[clang] 192c2c5 - [clang][Interp] Ignore StaticAssertDecls
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 3 07:57:12 PDT 2023
Author: Timm Bäder
Date: 2023-04-03T16:56:58+02:00
New Revision: 192c2c5c89477e28d0129f37a7d262112585b353
URL: https://github.com/llvm/llvm-project/commit/192c2c5c89477e28d0129f37a7d262112585b353
DIFF: https://github.com/llvm/llvm-project/commit/192c2c5c89477e28d0129f37a7d262112585b353.diff
LOG: [clang][Interp] Ignore StaticAssertDecls
They have already been handled before, but we can't just return false
when we encounter one.
Differential Revision: https://reviews.llvm.org/D144272
Added:
Modified:
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/test/AST/Interp/functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 1735b9b0272b..6faa3f9a47a9 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -224,6 +224,9 @@ bool ByteCodeStmtGen<Emitter>::visitCompoundStmt(
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;
diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp
index 2b44f42486d3..4b81e7d6be3b 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -9,11 +9,28 @@ constexpr int gimme5() {
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);
}
More information about the cfe-commits
mailing list