[clang] 85e6e71 - [clang][Interp] Handle discarded PointerToIntegral casts

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 12 21:57:41 PST 2024


Author: Timm Bäder
Date: 2024-02-13T06:57:30+01:00
New Revision: 85e6e71eb09cb9e75bbd475e5f54f876653c3f16

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

LOG: [clang][Interp] Handle discarded PointerToIntegral casts

Resolve an old TODO comment.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/AST/Interp/c.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 8a2c1e54e10a50..ba6c1d5f5c9470 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -167,7 +167,9 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
     return this->emitNull(classifyPrim(CE->getType()), CE);
 
   case CK_PointerToIntegral: {
-    // TODO: Discard handling.
+    if (DiscardResult)
+      return this->discard(SubExpr);
+
     if (!this->visit(SubExpr))
       return false;
 

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 392b682afd602b..85c195d33a96d7 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -24,6 +24,7 @@ _Static_assert(!!1, "");
 int a = (1 == 1 ? 5 : 3);
 _Static_assert(a == 5, ""); // all-error {{not an integral constant expression}}
 
+const int DiscardedPtrToIntCast = ((intptr_t)((void*)0), 0); // all-warning {{left operand of comma operator has no effect}}
 
 const int b = 3;
 _Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant expression}} \


        


More information about the cfe-commits mailing list