[PATCH] D144272: [clang][Interp] Ignore StaticAssertDecls

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 17 08:12:27 PST 2023


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, tahonermann, erichkeane, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  They have already been handled before, but we can't just return false
  when we encounter one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144272

Files:
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/test/AST/Interp/functions.cpp


Index: clang/test/AST/Interp/functions.cpp
===================================================================
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -9,11 +9,28 @@
 static_assert(gimme5() == 5, "");
 
 
-template<typename T> constexpr T identity(T t) { return t; }
+template<typename T> constexpr T identity(T t) {
+  static_assert(true);
+  return t;
+}
 static_assert(identity(true), "");
 static_assert(identity(true), ""); /// Compiled bytecode should be cached
 static_assert(!identity(false), "");
 
+template<typename A, typename B>
+constexpr bool sameSize() {
+  static_assert(sizeof(A) == sizeof(B), ""); // expected-error {{static assertion failed}} \
+                                             // ref-error {{static assertion failed}} \
+                                             // expected-note {{evaluates to}} \
+                                             // ref-note {{evaluates to}}
+  return true;
+}
+static_assert(sameSize<int, int>(), "");
+static_assert(sameSize<unsigned int, int>(), "");
+static_assert(sameSize<char, long>(), ""); // expected-note {{in instantiation of function template specialization}} \
+                                           // ref-note {{in instantiation of function template specialization}}
+
+
 constexpr auto add(int a, int b) -> int {
   return identity(a) + identity(b);
 }
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -210,6 +210,9 @@
 template <class Emitter>
 bool ByteCodeStmtGen<Emitter>::visitDeclStmt(const DeclStmt *DS) {
   for (auto *D : DS->decls()) {
+    if (isa<StaticAssertDecl>(D))
+      continue;
+
     const auto *VD = dyn_cast<VarDecl>(D);
     if (!VD)
       return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144272.498384.patch
Type: text/x-patch
Size: 1872 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230217/566e1bdc/attachment.bin>


More information about the cfe-commits mailing list