[clang] [clang][bytecode] Check for invalid record decls when returning a pointer from an evaluation (PR #230907)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 10 23:32:48 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We do allow creating such records for diagnostic purposes, but we shouldn't allow returning them from an evaluation.
---
Full diff: https://github.com/llvm/llvm-project/pull/230907.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/EvaluationResult.cpp (+5)
- (modified) clang/test/AST/ByteCode/invalid.cpp (+11)
``````````diff
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}}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/230907
More information about the cfe-commits
mailing list