[clang] [clang] Fix assertion failure in constexpr union deserialization (PR #140179)
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 19:57:26 PDT 2025
https://github.com/alexfh created https://github.com/llvm/llvm-project/pull/140179
This commit fixes https://github.com/llvm/llvm-project/issues/140130
>From 1b484ea9910fa1277481b27c58351c1e8b5001e3 Mon Sep 17 00:00:00 2001
From: Alexander Kornienko <alexfh at google.com>
Date: Fri, 16 May 2025 02:52:58 +0000
Subject: [PATCH] [clang] Fix assertion failure in constexpr union
deserialization
This commit fixes https://github.com/llvm/llvm-project/issues/140130
---
clang/include/clang/AST/PropertiesBase.td | 2 +-
clang/test/Modules/pr140130.cpp | 33 +++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Modules/pr140130.cpp
diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td
index 33336d57b6298..f3f0039ffe33e 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -414,7 +414,7 @@ let Class = PropertyTypeCase<APValue, "Union"> in {
let Read = [{ node.getUnionValue() }];
}
def : Creator<[{
- return APValue(cast<clang::FieldDecl>(fieldDecl), std::move(value));
+ return APValue(cast_if_present<clang::FieldDecl>(fieldDecl), std::move(value));
}]>;
}
let Class = PropertyTypeCase<APValue, "AddrLabelDiff"> in {
diff --git a/clang/test/Modules/pr140130.cpp b/clang/test/Modules/pr140130.cpp
new file mode 100644
index 0000000000000..da26a005b04f8
--- /dev/null
+++ b/clang/test/Modules/pr140130.cpp
@@ -0,0 +1,33 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -iquote . -fmodules -fno-cxx-modules -emit-module \
+// RUN: -std=c++20 -fmodule-name=c -xc++ c.cppmap -o c.pcm
+// RUN: %clang_cc1 -iquote . -fmodules -fno-cxx-modules -emit-module \
+// RUN: -std=c++20 -fmodule-name=a -fmodule-map-file=a.cppmap \
+// RUN: -fmodule-file=c.pcm -xc++ a.cppmap -o a.pcm
+
+//--- a.cppmap
+module "a" {
+ header "a.h"
+}
+//--- a.h
+#include "b.h"
+//--- b.h
+#ifndef _B_H_
+#define _B_H_
+struct B {
+ consteval B() {}
+ union {
+ int a;
+ };
+};
+constexpr B b;
+#endif
+//--- c.cppmap
+module "c" {
+header "c.h"
+}
+//--- c.h
+#include "b.h"
More information about the cfe-commits
mailing list