[clang] 2147a2a - [clang][Interp] Not all TypeTraitExprs are of bool type

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 1 23:16:44 PST 2024


Author: Timm Bäder
Date: 2024-02-02T07:40:05+01:00
New Revision: 2147a2a4f3ef344a561677b55444ce4d028ec59f

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

LOG: [clang][Interp] Not all TypeTraitExprs are of bool type

In C, they return an integer, so emit their value as such.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c
    clang/test/Sema/auto-type.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a93635a9f6888..ca7e529041188 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1668,7 +1668,9 @@ template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitTypeTraitExpr(const TypeTraitExpr *E) {
   if (DiscardResult)
     return true;
-  return this->emitConstBool(E->getValue(), E);
+  if (E->getType()->isBooleanType())
+    return this->emitConstBool(E->getValue(), E);
+  return this->emitConst(E->getValue(), E);
 }
 
 template <class Emitter>

diff  --git a/clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c b/clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c
index 9c1335786a500..2ead63c8e43e1 100644
--- a/clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c
+++ b/clang/test/Sema/PR2919-builtin-types-compat-strips-crv.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only %s
+// RUN: %clang_cc1 -fsyntax-only %s -fexperimental-new-constant-interpreter
 
 typedef struct foo T0;
 typedef const struct foo T1;

diff  --git a/clang/test/Sema/auto-type.c b/clang/test/Sema/auto-type.c
index 1170c687c96aa..b66f58b923287 100644
--- a/clang/test/Sema/auto-type.c
+++ b/clang/test/Sema/auto-type.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wno-strict-prototypes -verify -pedantic -std=c11
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-strict-prototypes -verify -pedantic -std=c11 -fexperimental-new-constant-interpreter
 
 __auto_type a = 5; // expected-warning {{'__auto_type' is a GNU extension}}
 __extension__ __auto_type a1 = 5;


        


More information about the cfe-commits mailing list