Skip to content

Commit 443c757

Browse files
Fix placement of _Assume_bounds_cast on c-style cast (#447)
The if statement that tries to replace an existing cast with a new cast assumed that the new cast was a c-style cast and not a CheckedC bounds cast. If the branch was taken when inserting a bounds cast, the leading '_' was cut off, resulting in invalid code. This commit adds a condition that ensures this does not happen.
1 parent 84a263d commit 443c757

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

clang/lib/3C/CastPlacement.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ void CastPlacementVisitor::surroundByCast(ConstraintVariable *Dst,
196196

197197
// If E is already a cast expression, we will try to rewrite the cast instead
198198
// of adding a new expression.
199-
if (auto *CE = dyn_cast<CStyleCastExpr>(E->IgnoreParens())) {
199+
if (isa<CStyleCastExpr>(E->IgnoreParens()) && CastKind == CAST_TO_WILD) {
200+
auto *CE = cast<CStyleCastExpr>(E->IgnoreParens());
200201
SourceRange CastTypeRange(CE->getLParenLoc(), CE->getRParenLoc());
201202
assert("Cast expected to start with '('" && !CastStrs.first.empty() &&
202203
CastStrs.first[0] == '(');

0 commit comments

Comments
 (0)