Skip to content

Commit 06165b2

Browse files
authored
merge amd-debug into amd-staging (llvm#3959)
2 parents 51fb1b1 + ae345b7 commit 06165b2

File tree

308 files changed

+13146
-12042
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

308 files changed

+13146
-12042
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,8 @@ Bug Fixes to C++ Support
596596
authentication enabled. (#GH152601)
597597
- Fix the check for narrowing int-to-float conversions, so that they are detected in
598598
cases where converting the float back to an integer is undefined behaviour (#GH157067).
599+
- Fix an assertion failure when a ``constexpr`` variable is only referenced through
600+
``__builtin_addressof``, and related issues with builtin arguments. (#GH154034)
599601

600602
Bug Fixes to AST Handling
601603
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/Mangle.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,37 @@ bool MangleContext::shouldMangleDeclName(const NamedDecl *D) {
152152
return shouldMangleCXXName(D);
153153
}
154154

155+
static llvm::StringRef g_lldb_func_call_label_prefix = "$__lldb_func:";
156+
157+
/// Given an LLDB function call label, this function prints the label
158+
/// into \c Out, together with the structor type of \c GD (if the
159+
/// decl is a constructor/destructor). LLDB knows how to handle mangled
160+
/// names with this encoding.
161+
///
162+
/// Example input label:
163+
/// $__lldb_func::123:456:~Foo
164+
///
165+
/// Example output:
166+
/// $__lldb_func:D1:123:456:~Foo
167+
///
168+
static void emitLLDBAsmLabel(llvm::StringRef label, GlobalDecl GD,
169+
llvm::raw_ostream &Out) {
170+
assert(label.starts_with(g_lldb_func_call_label_prefix));
171+
172+
Out << g_lldb_func_call_label_prefix;
173+
174+
if (auto *Ctor = llvm::dyn_cast<clang::CXXConstructorDecl>(GD.getDecl())) {
175+
Out << "C";
176+
if (Ctor->getInheritedConstructor().getConstructor())
177+
Out << "I";
178+
Out << GD.getCtorType();
179+
} else if (llvm::isa<clang::CXXDestructorDecl>(GD.getDecl())) {
180+
Out << "D" << GD.getDtorType();
181+
}
182+
183+
Out << label.substr(g_lldb_func_call_label_prefix.size());
184+
}
185+
155186
void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) {
156187
const ASTContext &ASTContext = getASTContext();
157188
const NamedDecl *D = cast<NamedDecl>(GD.getDecl());
@@ -185,7 +216,11 @@ void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) {
185216
if (!UserLabelPrefix.empty())
186217
Out << '\01'; // LLVM IR Marker for __asm("foo")
187218

188-
Out << ALA->getLabel();
219+
if (ALA->getLabel().starts_with(g_lldb_func_call_label_prefix))
220+
emitLLDBAsmLabel(ALA->getLabel(), GD, Out);
221+
else
222+
Out << ALA->getLabel();
223+
189224
return;
190225
}
191226

clang/lib/Driver/ToolChain.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,9 @@ ToolChain::getTargetAndModeFromProgramName(StringRef PN) {
516516
StringRef Prefix(ProgName);
517517
Prefix = Prefix.slice(0, LastComponent);
518518
std::string IgnoredError;
519-
bool IsRegistered = llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError);
519+
520+
llvm::Triple Triple(Prefix);
521+
bool IsRegistered = llvm::TargetRegistry::lookupTarget(Triple, IgnoredError);
520522
return ParsedClangName{std::string(Prefix), ModeSuffix, DS->ModeFlag,
521523
IsRegistered};
522524
}

clang/lib/Parse/ParseStmtAsm.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,12 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
509509

510510
// We need an actual supported target.
511511
const llvm::Triple &TheTriple = Actions.Context.getTargetInfo().getTriple();
512-
const std::string &TT = TheTriple.getTriple();
513512
const llvm::Target *TheTarget = nullptr;
514513
if (!TheTriple.isX86()) {
515514
Diag(AsmLoc, diag::err_msasm_unsupported_arch) << TheTriple.getArchName();
516515
} else {
517516
std::string Error;
518-
TheTarget = llvm::TargetRegistry::lookupTarget(TT, Error);
517+
TheTarget = llvm::TargetRegistry::lookupTarget(TheTriple, Error);
519518
if (!TheTarget)
520519
Diag(AsmLoc, diag::err_msasm_unable_to_create_target) << Error;
521520
}

clang/lib/Sema/SemaExpr.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6314,30 +6314,38 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext &Context,
63146314
unsigned i = 0;
63156315
SmallVector<QualType, 8> OverloadParams;
63166316

6317-
for (QualType ParamType : FT->param_types()) {
6317+
{
6318+
// The lvalue conversions in this loop are only for type resolution and
6319+
// don't actually occur.
6320+
EnterExpressionEvaluationContext Unevaluated(
6321+
*Sema, Sema::ExpressionEvaluationContext::Unevaluated);
6322+
Sema::SFINAETrap Trap(*Sema, /*ForValidityCheck=*/true);
63186323

6319-
// Convert array arguments to pointer to simplify type lookup.
6320-
ExprResult ArgRes =
6321-
Sema->DefaultFunctionArrayLvalueConversion(ArgExprs[i++]);
6322-
if (ArgRes.isInvalid())
6323-
return nullptr;
6324-
Expr *Arg = ArgRes.get();
6325-
QualType ArgType = Arg->getType();
6326-
if (!ParamType->isPointerType() ||
6327-
ParamType->getPointeeType().hasAddressSpace() ||
6328-
!ArgType->isPointerType() ||
6329-
!ArgType->getPointeeType().hasAddressSpace() ||
6330-
isPtrSizeAddressSpace(ArgType->getPointeeType().getAddressSpace())) {
6331-
OverloadParams.push_back(ParamType);
6332-
continue;
6333-
}
6324+
for (QualType ParamType : FT->param_types()) {
63346325

6335-
QualType PointeeType = ParamType->getPointeeType();
6336-
NeedsNewDecl = true;
6337-
LangAS AS = ArgType->getPointeeType().getAddressSpace();
6326+
// Convert array arguments to pointer to simplify type lookup.
6327+
ExprResult ArgRes =
6328+
Sema->DefaultFunctionArrayLvalueConversion(ArgExprs[i++]);
6329+
if (ArgRes.isInvalid())
6330+
return nullptr;
6331+
Expr *Arg = ArgRes.get();
6332+
QualType ArgType = Arg->getType();
6333+
if (!ParamType->isPointerType() ||
6334+
ParamType->getPointeeType().hasAddressSpace() ||
6335+
!ArgType->isPointerType() ||
6336+
!ArgType->getPointeeType().hasAddressSpace() ||
6337+
isPtrSizeAddressSpace(ArgType->getPointeeType().getAddressSpace())) {
6338+
OverloadParams.push_back(ParamType);
6339+
continue;
6340+
}
63386341

6339-
PointeeType = Context.getAddrSpaceQualType(PointeeType, AS);
6340-
OverloadParams.push_back(Context.getPointerType(PointeeType));
6342+
QualType PointeeType = ParamType->getPointeeType();
6343+
NeedsNewDecl = true;
6344+
LangAS AS = ArgType->getPointeeType().getAddressSpace();
6345+
6346+
PointeeType = Context.getAddrSpaceQualType(PointeeType, AS);
6347+
OverloadParams.push_back(Context.getPointerType(PointeeType));
6348+
}
63416349
}
63426350

63436351
if (!NeedsNewDecl)

clang/test/Driver/config-file3.c

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

231231
//--- Tilde expansion in user configuration file directory
232232
//
233-
// RUN: HOME=%S/Inputs/config %clang -### --config-user-dir=~ -v 2>&1 | FileCheck %s --check-prefix=CHECK-TILDE
233+
// RUN: env HOME=%S/Inputs/config %clang -### --config-user-dir=~ -v 2>&1 | FileCheck %s --check-prefix=CHECK-TILDE
234234
// CHECK-TILDE: User configuration file directory: {{.*}}/Inputs/config
235235

236236
//--- Fallback to stripping OS versions

clang/test/SemaCXX/builtin-get-vtable-pointer.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ struct PolymorphicTemplate {
6666
};
6767

6868
void test_function(int); // expected-note{{possible target for call}}
69-
// expected-note@-1{{possible target for call}}
7069
void test_function(double); // expected-note{{possible target for call}}
71-
// expected-note@-1{{possible target for call}}
7270

7371
void getVTablePointer() {
7472
ForwardDeclaration *fd = nullptr;
@@ -89,7 +87,6 @@ void getVTablePointer() {
8987
__builtin_get_vtable_pointer(np_array); // expected-error{{__builtin_get_vtable_pointer requires an argument of polymorphic class pointer type, but 'NonPolymorphic' has no virtual methods}}
9088
__builtin_get_vtable_pointer(&np_array); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'NonPolymorphic (*)[1]' was provided}}
9189
__builtin_get_vtable_pointer(test_function); // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}}
92-
// expected-error@-1{{reference to overloaded function could not be resolved; did you mean to call it?}}
9390
Foo<double> Food;
9491
Foo<int> Fooi;
9592
__builtin_get_vtable_pointer(Food); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'Foo<double>' was provided}}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cc1 -std=c++20 %s -emit-obj -o /dev/null
2+
3+
const int* test_odr_used() {
4+
// This previously crashed due to Value improperly being removed from
5+
// MaybeODRUseExprs.
6+
static constexpr int Value = 0;
7+
return __builtin_addressof(Value);
8+
}

clang/test/SemaObjC/non-trivial-c-union.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,10 @@ void testVolatileLValueToRValue(volatile U0 *a) {
8787
void unionInSystemHeader0(U0_SystemHeader);
8888

8989
void unionInSystemHeader1(U1_SystemHeader); // expected-error {{cannot use type 'U1_SystemHeader' for a function/method parameter since it is a union that is non-trivial to destruct}} expected-error {{cannot use type 'U1_SystemHeader' for a function/method parameter since it is a union that is non-trivial to copy}}
90+
91+
void testAddressof(void) {
92+
extern volatile U0 t0;
93+
// These don't dereference so they shouldn't cause an error.
94+
(void)&t0;
95+
(void)__builtin_addressof(t0);
96+
}

clang/unittests/AST/DeclTest.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212

1313
#include "clang/AST/Decl.h"
1414
#include "clang/AST/ASTContext.h"
15+
#include "clang/AST/DeclCXX.h"
1516
#include "clang/AST/DeclTemplate.h"
1617
#include "clang/AST/Mangle.h"
1718
#include "clang/ASTMatchers/ASTMatchFinder.h"
1819
#include "clang/ASTMatchers/ASTMatchers.h"
20+
#include "clang/Basic/ABI.h"
1921
#include "clang/Basic/Diagnostic.h"
2022
#include "clang/Basic/LLVM.h"
2123
#include "clang/Basic/TargetInfo.h"
@@ -102,6 +104,124 @@ TEST(Decl, AsmLabelAttr) {
102104
"foo");
103105
}
104106

107+
TEST(Decl, AsmLabelAttr_LLDB) {
108+
StringRef Code = R"(
109+
struct S {
110+
void f() {}
111+
S() = default;
112+
~S() = default;
113+
};
114+
)";
115+
auto AST =
116+
tooling::buildASTFromCodeWithArgs(Code, {"-target", "i386-apple-darwin"});
117+
ASTContext &Ctx = AST->getASTContext();
118+
assert(Ctx.getTargetInfo().getUserLabelPrefix() == StringRef("_") &&
119+
"Expected target to have a global prefix");
120+
DiagnosticsEngine &Diags = AST->getDiagnostics();
121+
122+
const auto *DeclS =
123+
selectFirst<CXXRecordDecl>("d", match(cxxRecordDecl().bind("d"), Ctx));
124+
125+
auto *DeclF = *DeclS->method_begin();
126+
auto *Ctor = *DeclS->ctor_begin();
127+
auto *Dtor = DeclS->getDestructor();
128+
129+
ASSERT_TRUE(DeclF);
130+
ASSERT_TRUE(Ctor);
131+
ASSERT_TRUE(Dtor);
132+
133+
DeclF->addAttr(AsmLabelAttr::Create(Ctx, "$__lldb_func::123:123:_Z1fv"));
134+
Ctor->addAttr(AsmLabelAttr::Create(Ctx, "$__lldb_func::123:123:S"));
135+
Dtor->addAttr(AsmLabelAttr::Create(Ctx, "$__lldb_func::123:123:~S"));
136+
137+
std::unique_ptr<ItaniumMangleContext> MC(
138+
ItaniumMangleContext::create(Ctx, Diags));
139+
140+
{
141+
std::string Mangled;
142+
llvm::raw_string_ostream OS_Mangled(Mangled);
143+
MC->mangleName(DeclF, OS_Mangled);
144+
145+
ASSERT_EQ(Mangled, "\x01$__lldb_func::123:123:_Z1fv");
146+
};
147+
148+
{
149+
std::string Mangled;
150+
llvm::raw_string_ostream OS_Mangled(Mangled);
151+
MC->mangleName(GlobalDecl(Ctor, CXXCtorType::Ctor_Complete), OS_Mangled);
152+
153+
ASSERT_EQ(Mangled, "\x01$__lldb_func:C0:123:123:S");
154+
};
155+
156+
{
157+
std::string Mangled;
158+
llvm::raw_string_ostream OS_Mangled(Mangled);
159+
MC->mangleName(GlobalDecl(Ctor, CXXCtorType::Ctor_Base), OS_Mangled);
160+
161+
ASSERT_EQ(Mangled, "\x01$__lldb_func:C1:123:123:S");
162+
};
163+
164+
{
165+
std::string Mangled;
166+
llvm::raw_string_ostream OS_Mangled(Mangled);
167+
MC->mangleName(GlobalDecl(Dtor, CXXDtorType::Dtor_Deleting), OS_Mangled);
168+
169+
ASSERT_EQ(Mangled, "\x01$__lldb_func:D0:123:123:~S");
170+
};
171+
172+
{
173+
std::string Mangled;
174+
llvm::raw_string_ostream OS_Mangled(Mangled);
175+
MC->mangleName(GlobalDecl(Dtor, CXXDtorType::Dtor_Base), OS_Mangled);
176+
177+
ASSERT_EQ(Mangled, "\x01$__lldb_func:D2:123:123:~S");
178+
};
179+
}
180+
181+
TEST(Decl, AsmLabelAttr_LLDB_Inherit) {
182+
StringRef Code = R"(
183+
struct Base {
184+
Base(int x) {}
185+
};
186+
187+
struct Derived : Base {
188+
using Base::Base;
189+
} d(5);
190+
)";
191+
auto AST =
192+
tooling::buildASTFromCodeWithArgs(Code, {"-target", "i386-apple-darwin"});
193+
ASTContext &Ctx = AST->getASTContext();
194+
assert(Ctx.getTargetInfo().getUserLabelPrefix() == StringRef("_") &&
195+
"Expected target to have a global prefix");
196+
DiagnosticsEngine &Diags = AST->getDiagnostics();
197+
198+
const auto *Ctor = selectFirst<CXXConstructorDecl>(
199+
"ctor",
200+
match(cxxConstructorDecl(isInheritingConstructor()).bind("ctor"), Ctx));
201+
202+
const_cast<CXXConstructorDecl *>(Ctor)->addAttr(
203+
AsmLabelAttr::Create(Ctx, "$__lldb_func::123:123:Derived"));
204+
205+
std::unique_ptr<ItaniumMangleContext> MC(
206+
ItaniumMangleContext::create(Ctx, Diags));
207+
208+
{
209+
std::string Mangled;
210+
llvm::raw_string_ostream OS_Mangled(Mangled);
211+
MC->mangleName(GlobalDecl(Ctor, CXXCtorType::Ctor_Complete), OS_Mangled);
212+
213+
ASSERT_EQ(Mangled, "\x01$__lldb_func:CI0:123:123:Derived");
214+
};
215+
216+
{
217+
std::string Mangled;
218+
llvm::raw_string_ostream OS_Mangled(Mangled);
219+
MC->mangleName(GlobalDecl(Ctor, CXXCtorType::Ctor_Base), OS_Mangled);
220+
221+
ASSERT_EQ(Mangled, "\x01$__lldb_func:CI1:123:123:Derived");
222+
};
223+
}
224+
105225
TEST(Decl, MangleDependentSizedArray) {
106226
StringRef Code = R"(
107227
template <int ...N>

0 commit comments

Comments
 (0)