[clang] b901b0d - [clang][Interp] Reject dummy pointers from __builtin_strcmp()

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 2 09:56:31 PST 2024


Author: Timm Bäder
Date: 2024-03-02T18:28:51+01:00
New Revision: b901b0d3edeaa30e363af4cb9dc76d6a7072e6cf

URL: https://github.com/llvm/llvm-project/commit/b901b0d3edeaa30e363af4cb9dc76d6a7072e6cf
DIFF: https://github.com/llvm/llvm-project/commit/b901b0d3edeaa30e363af4cb9dc76d6a7072e6cf.diff

LOG: [clang][Interp] Reject dummy pointers from __builtin_strcmp()

We can't load anything from them, so reject them here.

Added: 
    

Modified: 
    clang/lib/AST/Interp/InterpBuiltin.cpp
    clang/test/AST/Interp/builtin-functions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 371240065179e3..de3d72169432fd 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 3701106e02f05b..ab8abac4b36e34 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


        


More information about the cfe-commits mailing list