Skip to content

Commit

Permalink
[clang][Interp] Reject dummy pointers from __builtin_strcmp()
Browse files Browse the repository at this point in the history
We can't load anything from them, so reject them here.
  • Loading branch information
tbaederr committed Mar 2, 2024
1 parent a30ba2c commit b901b0d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/AST/Interp/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
if (!CheckLive(S, OpPC, A, AK_Read) || !CheckLive(S, OpPC, B, AK_Read))
return false;

if (A.isDummy() || B.isDummy())
return false;

assert(A.getFieldDesc()->isPrimitiveArray());
assert(B.getFieldDesc()->isPrimitiveArray());

Expand Down
8 changes: 8 additions & 0 deletions clang/test/AST/Interp/builtin-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ namespace strcmp {
static_assert(__builtin_strcmp(kFoobar, kFoobazfoobar + 6) == 0, ""); // both-error {{not an integral constant}} \
// both-note {{dereferenced one-past-the-end}} \
// expected-note {{in call to}}

/// Used to assert because we're passing a dummy pointer to
/// __builtin_strcmp() when evaluating the return statement.
constexpr bool char_memchr_mutable() {
char buffer[] = "mutable";
return __builtin_strcmp(buffer, "mutable") == 0;
}
static_assert(char_memchr_mutable(), "");
}

/// Copied from constant-expression-cxx11.cpp
Expand Down

0 comments on commit b901b0d

Please sign in to comment.