diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp index 371240065179e..de3d72169432f 100644 --- a/clang/lib/AST/Interp/InterpBuiltin.cpp +++ b/clang/lib/AST/Interp/InterpBuiltin.cpp @@ -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()); diff --git a/clang/test/AST/Interp/builtin-functions.cpp b/clang/test/AST/Interp/builtin-functions.cpp index 3701106e02f05..ab8abac4b36e3 100644 --- a/clang/test/AST/Interp/builtin-functions.cpp +++ b/clang/test/AST/Interp/builtin-functions.cpp @@ -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