[clang] [clang][bytecode] Check for invalid record decls when returning a pointer from an evaluation (PR #230907)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 10 23:32:11 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/230907
We do allow creating such records for diagnostic purposes, but we shouldn't allow returning them from an evaluation.
>From 59e5bd27946a6dba9434d9b9109e24601b9b971f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sun, 11 Oct 2026 08:27:57 +0200
Subject: [PATCH] asdf
---
clang/lib/AST/ByteCode/EvaluationResult.cpp | 5 +++++
clang/test/AST/ByteCode/invalid.cpp | 11 +++++++++++
2 files changed, 16 insertions(+)
diff --git a/clang/lib/AST/ByteCode/EvaluationResult.cpp b/clang/lib/AST/ByteCode/EvaluationResult.cpp
index 30976fcf1d521..70f64568483fd 100644
--- a/clang/lib/AST/ByteCode/EvaluationResult.cpp
+++ b/clang/lib/AST/ByteCode/EvaluationResult.cpp
@@ -384,6 +384,11 @@ static bool lval(InterpState &S, const ASTContext &Ctx, const Pointer &Ptr,
}
if (const auto *VD = dyn_cast_if_present<VarDecl>(BaseVD)) {
+ // We might allow creating pointers into invalid records, but do not allow
+ // returning them from an evaluation.
+ if (const RecordDecl *TypeRD = VD->getType()->getAsRecordDecl();
+ TypeRD && TypeRD->isInvalidDecl())
+ return false;
// Check if this is a thread-local variable.
if (VD->getTLSKind()) {
// FIXME: Diagnostic!
diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp
index cf859eb75dd90..a160c29169bc5 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -327,3 +327,14 @@ namespace StringLiteralDtor {
static_assert(bar(), ""); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}
}
+
+namespace PointerIntoInvalidRecord {
+ template <auto V> auto foo = bar(V);
+ union U {
+ int baz;
+ union {
+ auto baz; // both-error {{'auto' not allowed in non-static union member}}
+ } internal;
+ } u;
+ template int *foo<&u.baz>; // both-error {{non-type template argument is not a constant expression}}
+}
More information about the cfe-commits
mailing list