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?= <[email protected]>
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}}
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to