Skip to content

Commit c94dc53

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:09cd5a86733a362f12542a11ffd834cac885eb32 into amd-gfx:a6a072505de2
Local branch amd-gfx a6a0725 Merged main:e069434afcd21911ad36c55971bb8f754854c09f into amd-gfx:2c74854f7595 Remote branch main 09cd5a8 [clang][bytecode] Refuse to contruct objects with virtual bases (llvm#110142)
2 parents a6a0725 + 09cd5a8 commit c94dc53

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,25 @@ bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T) {
10431043
return false;
10441044
}
10451045

1046+
static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func,
1047+
const Pointer &ThisPtr) {
1048+
assert(Func->isConstructor());
1049+
1050+
const Descriptor *D = ThisPtr.getFieldDesc();
1051+
1052+
// FIXME: I think this case is not 100% correct. E.g. a pointer into a
1053+
// subobject of a composite array.
1054+
if (!D->ElemRecord)
1055+
return true;
1056+
1057+
if (D->ElemRecord->getNumVirtualBases() == 0)
1058+
return true;
1059+
1060+
S.FFDiag(S.Current->getLocation(OpPC), diag::note_constexpr_virtual_base)
1061+
<< Func->getParentDecl();
1062+
return false;
1063+
}
1064+
10461065
bool CallVar(InterpState &S, CodePtr OpPC, const Function *Func,
10471066
uint32_t VarArgSize) {
10481067
if (Func->hasThisPointer()) {
@@ -1117,6 +1136,9 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
11171136
if (!CheckInvoke(S, OpPC, ThisPtr))
11181137
return cleanup();
11191138
}
1139+
1140+
if (Func->isConstructor() && !checkConstructor(S, OpPC, Func, ThisPtr))
1141+
return false;
11201142
}
11211143

11221144
if (!CheckCallable(S, OpPC, Func))

clang/test/AST/ByteCode/cxx23.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ namespace VirtualBases {
158158
/// Calls the constructor of D.
159159
D d;
160160
}
161+
162+
#if __cplusplus >= 202302L
163+
struct VBase {};
164+
struct HasVBase : virtual VBase {}; // all23-note 1{{virtual base class declared here}}
165+
struct Derived : HasVBase {
166+
constexpr Derived() {} // all23-error {{constexpr constructor not allowed in struct with virtual base class}}
167+
};
168+
template<typename T> struct DerivedFromVBase : T {
169+
constexpr DerivedFromVBase();
170+
};
171+
constexpr int f(DerivedFromVBase<HasVBase>) {}
172+
template<typename T> constexpr DerivedFromVBase<T>::DerivedFromVBase() : T() {}
173+
constexpr int nVBase = (DerivedFromVBase<HasVBase>(), 0); // all23-error {{constant expression}} \
174+
// all23-note {{cannot construct object of type 'DerivedFromVBase<VirtualBases::HasVBase>' with virtual base class in a constant expression}}
175+
#endif
161176
}
162177

163178
namespace LabelGoto {

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 513232
19+
#define LLVM_MAIN_REVISION 513234
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
12161216
}
12171217

12181218
bool DwarfCompileUnit::useGNUAnalogForDwarf5Feature() const {
1219-
return DD->getDwarfVersion() == 4 && !DD->tuneForLLDB();
1219+
return DD->getDwarfVersion() <= 4 && !DD->tuneForLLDB();
12201220
}
12211221

12221222
dwarf::Tag DwarfCompileUnit::getDwarf5OrGNUTag(dwarf::Tag Tag) const {

llvm/test/DebugInfo/MIR/X86/call-site-gnu-vs-dwarf5-attrs.mir

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@
3030
# RUN: -debug-entry-values -mtriple=x86_64-unknown-unknown \
3131
# RUN: -start-after=machineverifier -o - %s | llvm-dwarfdump - | FileCheck %s -check-prefixes=CHECK-DWARF5
3232

33+
## === DWARF3, tune for gdb ===
34+
# RUN: llc -emit-call-site-info -dwarf-version 3 -debugger-tune=gdb -filetype=obj \
35+
# RUN: -mtriple=x86_64-unknown-unknown -start-after=machineverifier -o - %s \
36+
# RUN: | llvm-dwarfdump - | FileCheck %s -implicit-check-not=DW_AT_call
37+
38+
## === DWARF3, tune for lldb ===
39+
# RUN: llc -dwarf-version 3 -debugger-tune=lldb -emit-call-site-info -filetype=obj \
40+
# RUN: -mtriple=x86_64-unknown-unknown -start-after=machineverifier -o - %s \
41+
# RUN: | llvm-dwarfdump - | FileCheck %s -implicit-check-not=DW_AT_GNU_call
42+
43+
## === DWARF3, tune for sce ===
44+
# RUN: llc -emit-call-site-info -dwarf-version 3 -filetype=obj -debugger-tune=sce \
45+
# RUN: -debug-entry-values -mtriple=x86_64-unknown-unknown \
46+
# RUN: -start-after=machineverifier -o - %s | llvm-dwarfdump - | FileCheck %s -implicit-check-not=DW_AT_call
47+
3348
## This is based on the following reproducer:
3449
##
3550
## extern void fn();

0 commit comments

Comments
 (0)