Skip to content

Commit 3aeced7

Browse files
authored
[clang] Fix assertion failure in constexpr union deserialization (#140179)
This commit fixes #140130
1 parent 9c3ab1c commit 3aeced7

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

clang/docs/ReleaseNotes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ Bug Fixes in This Version
622622
- Fixed an assertion failure in constant compound literal statements. (#GH139160)
623623
- Fix crash due to unknown references and pointer implementation and handling of
624624
base classes. (GH139452)
625+
- Fixed an assertion failure in serialization of constexpr structs containing unions. (#GH140130)
625626

626627
Bug Fixes to Compiler Builtins
627628
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/PropertiesBase.td

+2-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ let Class = PropertyTypeCase<APValue, "Union"> in {
414414
let Read = [{ node.getUnionValue() }];
415415
}
416416
def : Creator<[{
417-
return APValue(cast<clang::FieldDecl>(fieldDecl), std::move(value));
417+
// node.getUnionField() / fieldDecl can be null, thus, using `cast_if_present`
418+
return APValue(cast_if_present<clang::FieldDecl>(fieldDecl), std::move(value));
418419
}]>;
419420
}
420421
let Class = PropertyTypeCase<APValue, "AddrLabelDiff"> in {

clang/test/Modules/pr140130.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
// RUN: cd %t
5+
// RUN: %clang_cc1 -iquote . -fmodules -fno-cxx-modules -emit-module \
6+
// RUN: -std=c++20 -fmodule-name=c -xc++ c.cppmap -o c.pcm
7+
// RUN: %clang_cc1 -iquote . -fmodules -fno-cxx-modules -emit-module \
8+
// RUN: -std=c++20 -fmodule-name=a -fmodule-map-file=a.cppmap \
9+
// RUN: -fmodule-file=c.pcm -xc++ a.cppmap -o a.pcm
10+
11+
//--- a.cppmap
12+
module "a" {
13+
header "a.h"
14+
}
15+
//--- a.h
16+
#include "b.h"
17+
//--- b.h
18+
#ifndef _B_H_
19+
#define _B_H_
20+
struct B {
21+
consteval B() {}
22+
union {
23+
int a;
24+
};
25+
};
26+
constexpr B b;
27+
#endif
28+
//--- c.cppmap
29+
module "c" {
30+
header "c.h"
31+
}
32+
//--- c.h
33+
#include "b.h"

0 commit comments

Comments
 (0)