[PATCH] D148690: [clang][Interp] Handle __extension__ unary operators

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


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG78e774e0c827: [clang][Interp] Handle __extension__ unary operators (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D148690?vs=514844&id=544207#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148690

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


Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -880,5 +880,16 @@
     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
 }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2004,6 +2004,9 @@
   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");
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148690.544207.patch
Type: text/x-patch
Size: 1316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230726/b15f51c8/attachment.bin>


More information about the cfe-commits mailing list