[PATCH] D157200: [clang][Interp] Visit Logical-not operand as bool

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 15 01:13:02 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd2f2c166203: [clang][Interp] Visit Logical-not operand as bool (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D157200?vs=547519&id=556833#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157200/new/

https://reviews.llvm.org/D157200

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


Index: clang/test/AST/Interp/c.c
===================================================================
--- clang/test/AST/Interp/c.c
+++ clang/test/AST/Interp/c.c
@@ -12,6 +12,9 @@
 _Static_assert(1 && 1.0, ""); // pedantic-ref-warning {{not an integer constant expression}} \
                               // pedantic-expected-warning {{not an integer constant expression}}
 _Static_assert( (5 > 4) + (3 > 2) == 2, "");
+_Static_assert(!!1.0, ""); // pedantic-ref-warning {{not an integer constant expression}} \
+                           // pedantic-expected-warning {{not an integer constant expression}}
+_Static_assert(!!1, "");
 
 /// FIXME: Should also be rejected in the new interpreter
 int a = (1 == 1 ? 5 : 3);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2378,10 +2378,18 @@
     return this->emitStore(*T, E);
   }
   case UO_LNot: // !x
-    if (!this->visit(SubExpr))
+    if (DiscardResult)
+      return this->discard(SubExpr);
+
+    if (!this->visitBool(SubExpr))
       return false;
-    // The Inv doesn't change anything, so skip it if we don't need the result.
-    return DiscardResult ? this->emitPop(*T, E) : this->emitInvBool(E);
+
+    if (!this->emitInvBool(E))
+      return false;
+
+    if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool)
+      return this->emitCast(PT_Bool, ET, E);
+    return true;
   case UO_Minus: // -x
     if (!this->visit(SubExpr))
       return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157200.556833.patch
Type: text/x-patch
Size: 1588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230915/c3b78939/attachment.bin>


More information about the cfe-commits mailing list