Author: Timm Bäder
Date: 2024-03-12T07:48:56+01:00
New Revision: 1dd104db59d145d516a5e9cbb081ed01262961ef

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

LOG: [clang][Interp] Implement _Complex Not unary operators

This only happens in C as far as I can tell. The complex varialbe
will have undergone a conversion to bool in C++ before reaching
the unary operator.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 0dd645990d1d58..da4a8f88f1396a 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3182,6 +3182,17 @@ bool ByteCodeExprGen<Emitter>::VisitComplexUnaryOperator(
   case UO_AddrOf:
     return this->delegate(SubExpr);
 
+  case UO_LNot:
+    if (!this->visit(SubExpr))
+      return false;
+    if (!this->emitComplexBoolCast(SubExpr))
+      return false;
+    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_Real:
     return this->emitComplexReal(SubExpr);
 

diff  --git a/clang/test/AST/Interp/complex.c b/clang/test/AST/Interp/complex.c
index c9c2efb5974531..b5f30b87baa79a 100644
--- a/clang/test/AST/Interp/complex.c
+++ b/clang/test/AST/Interp/complex.c
@@ -14,3 +14,8 @@ void blah() {
 _Static_assert((0.0 + 0.0j) == (0.0 + 0.0j), "");
 _Static_assert((0.0 + 0.0j) != (0.0 + 0.0j), ""); // both-error {{static 
assertion}} \
                                                   // both-note {{evaluates to}}
+
+const _Complex float FC = {0.0f, 0.0f};
+_Static_assert(!FC, "");
+const _Complex float FI = {0, 0};
+_Static_assert(!FI, "");


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to