[clang] 02b3012 - [clang][bytecode] Always return false for invalid bcp results (#121467)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 2 04:44:48 PST 2025


Author: Timm Baeder
Date: 2025-01-02T13:44:45+01:00
New Revision: 02b30128e8e87795b9262035a48990648cbec586

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

LOG: [clang][bytecode] Always return false for invalid bcp results (#121467)

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/InterpBuiltin.cpp
    clang/test/AST/ByteCode/builtin-constant-p.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index b5849553d0bf53..731c9290993f12 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1544,9 +1544,10 @@ static bool interp__builtin_constant_p(InterpState &S, CodePtr OpPC,
     if (Res.isInvalid()) {
       C.cleanup();
       Stk.clear();
+      return returnInt(false);
     }
 
-    if (!Res.isInvalid() && !Res.empty()) {
+    if (!Res.empty()) {
       const APValue &LV = Res.toAPValue();
       if (LV.isLValue()) {
         APValue::LValueBase Base = LV.getLValueBase();

diff  --git a/clang/test/AST/ByteCode/builtin-constant-p.cpp b/clang/test/AST/ByteCode/builtin-constant-p.cpp
index 0d222d1c962778..62899b60064c28 100644
--- a/clang/test/AST/ByteCode/builtin-constant-p.cpp
+++ b/clang/test/AST/ByteCode/builtin-constant-p.cpp
@@ -12,3 +12,9 @@ static_assert(__builtin_constant_p(I + 10.0), "");
 static_assert(__builtin_constant_p(nullptr), "");
 static_assert(__builtin_constant_p(&I), ""); // both-error {{failed due to requirement}}
 static_assert(__builtin_constant_p((void)I), ""); // both-error {{failed due to requirement}}
+
+extern int z;
+constexpr int foo(int &a) {
+  return __builtin_constant_p(a);
+}
+static_assert(!foo(z));


        


More information about the cfe-commits mailing list