[clang] ee5fc90 - [clang][bytecode] Check for invalid record decls when returning a pointer from an evaluation (#230907)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 12 01:39:05 PDT 2026
Author: Timm Baeder
Date: 2026-10-12T10:39:00+02:00
New Revision: ee5fc909fbb3dd4eb5145235abf6559b5424a3c8
URL: https://github.com/llvm/llvm-project/commit/ee5fc909fbb3dd4eb5145235abf6559b5424a3c8
DIFF: https://github.com/llvm/llvm-project/commit/ee5fc909fbb3dd4eb5145235abf6559b5424a3c8.diff
LOG: [clang][bytecode] Check for invalid record decls when returning a pointer from an evaluation (#230907)
We do allow creating such records for diagnostic purposes, but we
shouldn't allow returning them from an evaluation.
Added:
Modified:
clang/lib/AST/ByteCode/EvaluationResult.cpp
clang/test/AST/ByteCode/invalid.cpp
Removed:
################################################################################
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