[clang] 78e774e - [clang][Interp] Handle __extension__ unary operators

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 25 22:17:03 PDT 2023


Author: Timm Bäder
Date: 2023-07-26T07:16:45+02:00
New Revision: 78e774e0c827803ce917da7f1cbdbb40892a1788

URL: https://github.com/llvm/llvm-project/commit/78e774e0c827803ce917da7f1cbdbb40892a1788
DIFF: https://github.com/llvm/llvm-project/commit/78e774e0c827803ce917da7f1cbdbb40892a1788.diff

LOG: [clang][Interp] Handle __extension__ unary operators

Differential Revision: https://reviews.llvm.org/D148690

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d2995fb57d8bef..c7c87d966cbe7f 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2004,6 +2004,9 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
   case UO_Real:   // __real x
   case UO_Imag:   // __imag x
   case UO_Extension:
+    if (DiscardResult)
+      return this->discard(SubExpr);
+    return this->visit(SubExpr);
   case UO_Coawait:
     assert(false && "Unhandled opcode");
   }

diff  --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index 5df7b7e5e6e8b0..f0513810eb4b7e 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -880,5 +880,16 @@ namespace PredefinedExprs {
     static_assert(strings_match(__func__, "foo"), "");
     static_assert(strings_match(__PRETTY_FUNCTION__, "void PredefinedExprs::foo()"), "");
   }
+
+  constexpr char heh(unsigned index) {
+    __FUNCTION__;               // ref-warning {{result unused}} \
+                                // expected-warning {{result unused}}
+    __extension__ __FUNCTION__; // ref-warning {{result unused}} \
+                                // expected-warning {{result unused}}
+    return __FUNCTION__[index];
+  }
+  static_assert(heh(0) == 'h', "");
+  static_assert(heh(1) == 'e', "");
+  static_assert(heh(2) == 'h', "");
 #endif
 }


        


More information about the cfe-commits mailing list