Skip to content

Commit 86625b6

Browse files
committed
Merged main:b7730a23efb222944b732bbdb3a7b965b7bffd98 into amd-gfx:0616aed9b07e
Local branch amd-gfx 0616aed Merged main:1fb1a5d8e2c5a0cbaeb39ead68352e5e55752a6d into amd-gfx:df815516a962 Remote branch main b7730a2 [test] Avoid writing to a potentially write-protected dir (llvm#102073) Change-Id: Iee4703aeb9072dc5b9cb667b574ad855b38a05b0
2 parents 0616aed + b7730a2 commit 86625b6

File tree

232 files changed

+4792
-1579
lines changed

Some content is hidden

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

232 files changed

+4792
-1579
lines changed

clang-tools-extra/clang-tidy/tool/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ clang_target_link_libraries(clangTidyMain
3333
# Support plugins.
3434
if(CLANG_PLUGIN_SUPPORT)
3535
set(support_plugins SUPPORT_PLUGINS)
36+
set(export_symbols EXPORT_SYMBOLS_FOR_PLUGINS)
3637
endif()
3738

3839
add_clang_tool(clang-tidy
@@ -41,6 +42,7 @@ add_clang_tool(clang-tidy
4142
DEPENDS
4243
clang-resource-headers
4344
${support_plugins}
45+
${export_symbols}
4446
)
4547
clang_target_link_libraries(clang-tidy
4648
PRIVATE
@@ -57,10 +59,6 @@ target_link_libraries(clang-tidy
5759
${ALL_CLANG_TIDY_CHECKS}
5860
)
5961

60-
if(CLANG_PLUGIN_SUPPORT)
61-
export_executable_symbols_for_plugins(clang-tidy)
62-
endif()
63-
6462
install(PROGRAMS clang-tidy-diff.py
6563
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
6664
COMPONENT clang-tidy)

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ Bug Fixes to C++ Support
186186
substitutions in concepts, so it doesn't incorrectly complain of missing
187187
module imports in those situations. (#GH60336)
188188
- Fix init-capture packs having a size of one before being instantiated. (#GH63677)
189+
- Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667),
190+
(#GH99877).
189191

190192
Bug Fixes to AST Handling
191193
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang-c/Index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2981,7 +2981,7 @@ enum CXTypeKind {
29812981
CXType_BTFTagAttributed = 178,
29822982

29832983
// HLSL Intangible Types
2984-
CXType_HLSLResource = 179,
2984+
CXType_HLSLResource = 179
29852985
};
29862986

29872987
/**

clang/include/clang/Basic/Features.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ FEATURE(ptrauth_vtable_pointer_address_discrimination, LangOpts.PointerAuthVTPtr
110110
FEATURE(ptrauth_vtable_pointer_type_discrimination, LangOpts.PointerAuthVTPtrTypeDiscrimination)
111111
FEATURE(ptrauth_type_info_vtable_pointer_discrimination, LangOpts.PointerAuthTypeInfoVTPtrDiscrimination)
112112
FEATURE(ptrauth_member_function_pointer_type_discrimination, LangOpts.PointerAuthCalls)
113-
FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
114113
FEATURE(ptrauth_function_pointer_type_discrimination, LangOpts.PointerAuthFunctionTypeDiscrimination)
115114
FEATURE(ptrauth_indirect_gotos, LangOpts.PointerAuthIndirectGotos)
115+
FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
116+
FEATURE(ptrauth_init_fini_address_discrimination, LangOpts.PointerAuthInitFiniAddressDiscrimination)
116117
EXTENSION(swiftcc,
117118
PP.getTargetInfo().checkCallingConvention(CC_Swift) ==
118119
clang::TargetInfo::CCCR_OK)

clang/include/clang/Basic/LangOptions.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ LANGOPT(PointerAuthAuthTraps, 1, 0, "pointer authentication failure traps")
170170
LANGOPT(PointerAuthVTPtrAddressDiscrimination, 1, 0, "incorporate address discrimination in authenticated vtable pointers")
171171
LANGOPT(PointerAuthVTPtrTypeDiscrimination, 1, 0, "incorporate type discrimination in authenticated vtable pointers")
172172
LANGOPT(PointerAuthTypeInfoVTPtrDiscrimination, 1, 0, "incorporate type and address discrimination in authenticated vtable pointers for std::type_info")
173-
LANGOPT(PointerAuthInitFini, 1, 0, "sign function pointers in init/fini arrays")
174173
BENIGN_LANGOPT(PointerAuthFunctionTypeDiscrimination, 1, 0,
175174
"Use type discrimination when signing function pointers")
175+
LANGOPT(PointerAuthInitFini, 1, 0, "sign function pointers in init/fini arrays")
176+
LANGOPT(PointerAuthInitFiniAddressDiscrimination, 1, 0,
177+
"incorporate address discrimination in authenticated function pointers in init/fini arrays")
176178

177179
LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for all language standard modes")
178180
LANGOPT(ExperimentalLateParseAttributes, 1, 0, "experimental late parsing of attributes")

clang/include/clang/Basic/PointerAuthOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
namespace clang {
2525

26+
/// Constant discriminator to be used with function pointers in .init_array and
27+
/// .fini_array. The value is ptrauth_string_discriminator("init_fini")
28+
constexpr uint16_t InitFiniPointerConstantDiscriminator = 0xD9D4;
29+
2630
constexpr unsigned PointerAuthKeyNone = -1;
2731

2832
/// Constant discriminator for std::type_info vtable pointers: 0xB1EA/45546
@@ -186,6 +190,9 @@ struct PointerAuthOptions {
186190

187191
/// The ABI for C++ member function pointers.
188192
PointerAuthSchema CXXMemberFunctionPointers;
193+
194+
/// The ABI for function addresses in .init_array and .fini_array
195+
PointerAuthSchema InitFiniPointers;
189196
};
190197

191198
} // end namespace clang

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4254,11 +4254,13 @@ defm ptrauth_vtable_pointer_type_discrimination :
42544254
OptInCC1FFlag<"ptrauth-vtable-pointer-type-discrimination", "Enable type discrimination of vtable pointers">;
42554255
defm ptrauth_type_info_vtable_pointer_discrimination :
42564256
OptInCC1FFlag<"ptrauth-type-info-vtable-pointer-discrimination", "Enable type and address discrimination of vtable pointer of std::type_info">;
4257-
defm ptrauth_init_fini : OptInCC1FFlag<"ptrauth-init-fini", "Enable signing of function pointers in init/fini arrays">;
42584257
defm ptrauth_function_pointer_type_discrimination : OptInCC1FFlag<"ptrauth-function-pointer-type-discrimination",
42594258
"Enable type discrimination on C function pointers">;
42604259
defm ptrauth_indirect_gotos : OptInCC1FFlag<"ptrauth-indirect-gotos",
42614260
"Enable signing and authentication of indirect goto targets">;
4261+
defm ptrauth_init_fini : OptInCC1FFlag<"ptrauth-init-fini", "Enable signing of function pointers in init/fini arrays">;
4262+
defm ptrauth_init_fini_address_discrimination : OptInCC1FFlag<"ptrauth-init-fini-address-discrimination",
4263+
"Enable address discrimination of function pointers in init/fini arrays">;
42624264
}
42634265

42644266
def fenable_matrix : Flag<["-"], "fenable-matrix">, Group<f_Group>,

clang/lib/AST/Interp/Interp.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,12 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
628628

629629
S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
630630
<< DiagDecl->isConstexpr() << (bool)CD << DiagDecl;
631-
S.Note(DiagDecl->getLocation(), diag::note_declared_at);
631+
632+
if (DiagDecl->getDefinition())
633+
S.Note(DiagDecl->getDefinition()->getLocation(),
634+
diag::note_declared_at);
635+
else
636+
S.Note(DiagDecl->getLocation(), diag::note_declared_at);
632637
}
633638
} else {
634639
S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,10 +1218,13 @@ void CodeGenModule::Release() {
12181218
(LangOpts.PointerAuthVTPtrTypeDiscrimination
12191219
<< AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_VPTRTYPEDISCR) |
12201220
(LangOpts.PointerAuthInitFini
1221-
<< AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI);
1222-
static_assert(AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI ==
1223-
AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_LAST,
1224-
"Update when new enum items are defined");
1221+
<< AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI) |
1222+
(LangOpts.PointerAuthInitFiniAddressDiscrimination
1223+
<< AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINIADDRDISC);
1224+
static_assert(
1225+
AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINIADDRDISC ==
1226+
AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_LAST,
1227+
"Update when new enum items are defined");
12251228
if (PAuthABIVersion != 0) {
12261229
getModule().addModuleFlag(llvm::Module::Error,
12271230
"aarch64-elf-pauthabi-platform",
@@ -2082,37 +2085,53 @@ void CodeGenModule::AddGlobalDtor(llvm::Function *Dtor, int Priority,
20822085
void CodeGenModule::EmitCtorList(CtorList &Fns, const char *GlobalName) {
20832086
if (Fns.empty()) return;
20842087

2085-
// Ctor function type is void()*.
2086-
llvm::FunctionType* CtorFTy = llvm::FunctionType::get(VoidTy, false);
2087-
llvm::Type *CtorPFTy = llvm::PointerType::get(CtorFTy,
2088-
TheModule.getDataLayout().getProgramAddressSpace());
2088+
const PointerAuthSchema &InitFiniAuthSchema =
2089+
getCodeGenOpts().PointerAuth.InitFiniPointers;
20892090

2090-
// Get the type of a ctor entry, { i32, void ()*, i8* }.
2091-
llvm::StructType *CtorStructTy = llvm::StructType::get(
2092-
Int32Ty, CtorPFTy, VoidPtrTy);
2091+
// Ctor function type is ptr.
2092+
llvm::PointerType *PtrTy = llvm::PointerType::get(
2093+
getLLVMContext(), TheModule.getDataLayout().getProgramAddressSpace());
2094+
2095+
// Get the type of a ctor entry, { i32, ptr, ptr }.
2096+
llvm::StructType *CtorStructTy = llvm::StructType::get(Int32Ty, PtrTy, PtrTy);
20932097

20942098
// Construct the constructor and destructor arrays.
2095-
ConstantInitBuilder builder(*this);
2096-
auto ctors = builder.beginArray(CtorStructTy);
2099+
ConstantInitBuilder Builder(*this);
2100+
auto Ctors = Builder.beginArray(CtorStructTy);
20972101
for (const auto &I : Fns) {
2098-
auto ctor = ctors.beginStruct(CtorStructTy);
2099-
ctor.addInt(Int32Ty, I.Priority);
2100-
ctor.add(I.Initializer);
2102+
auto Ctor = Ctors.beginStruct(CtorStructTy);
2103+
Ctor.addInt(Int32Ty, I.Priority);
2104+
if (InitFiniAuthSchema) {
2105+
llvm::Constant *StorageAddress =
2106+
(InitFiniAuthSchema.isAddressDiscriminated()
2107+
? llvm::ConstantExpr::getIntToPtr(
2108+
llvm::ConstantInt::get(
2109+
IntPtrTy,
2110+
llvm::ConstantPtrAuth::AddrDiscriminator_CtorsDtors),
2111+
PtrTy)
2112+
: nullptr);
2113+
llvm::Constant *SignedCtorPtr = getConstantSignedPointer(
2114+
I.Initializer, InitFiniAuthSchema.getKey(), StorageAddress,
2115+
llvm::ConstantInt::get(
2116+
SizeTy, InitFiniAuthSchema.getConstantDiscrimination()));
2117+
Ctor.add(SignedCtorPtr);
2118+
} else {
2119+
Ctor.add(I.Initializer);
2120+
}
21012121
if (I.AssociatedData)
2102-
ctor.add(I.AssociatedData);
2122+
Ctor.add(I.AssociatedData);
21032123
else
2104-
ctor.addNullPointer(VoidPtrTy);
2105-
ctor.finishAndAddTo(ctors);
2124+
Ctor.addNullPointer(PtrTy);
2125+
Ctor.finishAndAddTo(Ctors);
21062126
}
21072127

2108-
auto list =
2109-
ctors.finishAndCreateGlobal(GlobalName, getPointerAlign(),
2110-
/*constant*/ false,
2111-
llvm::GlobalValue::AppendingLinkage);
2128+
auto List = Ctors.finishAndCreateGlobal(GlobalName, getPointerAlign(),
2129+
/*constant*/ false,
2130+
llvm::GlobalValue::AppendingLinkage);
21122131

21132132
// The LTO linker doesn't seem to like it when we set an alignment
21142133
// on appending variables. Take it off as a workaround.
2115-
list->setAlignment(std::nullopt);
2134+
List->setAlignment(std::nullopt);
21162135

21172136
Fns.clear();
21182137
}

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,14 +1847,17 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
18471847
Args.addOptInFlag(
18481848
CmdArgs, options::OPT_fptrauth_type_info_vtable_pointer_discrimination,
18491849
options::OPT_fno_ptrauth_type_info_vtable_pointer_discrimination);
1850-
Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_init_fini,
1851-
options::OPT_fno_ptrauth_init_fini);
18521850
Args.addOptInFlag(
18531851
CmdArgs, options::OPT_fptrauth_function_pointer_type_discrimination,
18541852
options::OPT_fno_ptrauth_function_pointer_type_discrimination);
18551853

18561854
Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_indirect_gotos,
18571855
options::OPT_fno_ptrauth_indirect_gotos);
1856+
Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_init_fini,
1857+
options::OPT_fno_ptrauth_init_fini);
1858+
Args.addOptInFlag(CmdArgs,
1859+
options::OPT_fptrauth_init_fini_address_discrimination,
1860+
options::OPT_fno_ptrauth_init_fini_address_discrimination);
18581861
}
18591862

18601863
void Clang::AddLoongArchTargetArgs(const ArgList &Args,

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,12 @@ void CompilerInvocation::setDefaultPointerAuthOptions(
15031503
PointerAuthSchema(Key::ASIA, true, Discrimination::Decl);
15041504
Opts.CXXMemberFunctionPointers =
15051505
PointerAuthSchema(Key::ASIA, false, Discrimination::Type);
1506+
1507+
if (LangOpts.PointerAuthInitFini) {
1508+
Opts.InitFiniPointers = PointerAuthSchema(
1509+
Key::ASIA, LangOpts.PointerAuthInitFiniAddressDiscrimination,
1510+
Discrimination::Constant, InitFiniPointerConstantDiscriminator);
1511+
}
15061512
}
15071513
Opts.IndirectGotos = LangOpts.PointerAuthIndirectGotos;
15081514
}
@@ -3425,11 +3431,12 @@ static void GeneratePointerAuthArgs(const LangOptions &Opts,
34253431
GenerateArg(Consumer, OPT_fptrauth_vtable_pointer_type_discrimination);
34263432
if (Opts.PointerAuthTypeInfoVTPtrDiscrimination)
34273433
GenerateArg(Consumer, OPT_fptrauth_type_info_vtable_pointer_discrimination);
3428-
3429-
if (Opts.PointerAuthInitFini)
3430-
GenerateArg(Consumer, OPT_fptrauth_init_fini);
34313434
if (Opts.PointerAuthFunctionTypeDiscrimination)
34323435
GenerateArg(Consumer, OPT_fptrauth_function_pointer_type_discrimination);
3436+
if (Opts.PointerAuthInitFini)
3437+
GenerateArg(Consumer, OPT_fptrauth_init_fini);
3438+
if (Opts.PointerAuthInitFiniAddressDiscrimination)
3439+
GenerateArg(Consumer, OPT_fptrauth_init_fini_address_discrimination);
34333440
}
34343441

34353442
static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
@@ -3445,10 +3452,11 @@ static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
34453452
Args.hasArg(OPT_fptrauth_vtable_pointer_type_discrimination);
34463453
Opts.PointerAuthTypeInfoVTPtrDiscrimination =
34473454
Args.hasArg(OPT_fptrauth_type_info_vtable_pointer_discrimination);
3448-
3449-
Opts.PointerAuthInitFini = Args.hasArg(OPT_fptrauth_init_fini);
34503455
Opts.PointerAuthFunctionTypeDiscrimination =
34513456
Args.hasArg(OPT_fptrauth_function_pointer_type_discrimination);
3457+
Opts.PointerAuthInitFini = Args.hasArg(OPT_fptrauth_init_fini);
3458+
Opts.PointerAuthInitFiniAddressDiscrimination =
3459+
Args.hasArg(OPT_fptrauth_init_fini_address_discrimination);
34523460
}
34533461

34543462
/// Check if input file kind and language standard are compatible.

clang/lib/Headers/ptrauth.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ typedef enum {
3636
The extra data is always 0. */
3737
ptrauth_key_cxx_vtable_pointer = ptrauth_key_process_independent_data,
3838

39+
/* The key used to sign pointers in ELF .init_array/.fini_array. */
40+
ptrauth_key_init_fini_pointer = ptrauth_key_process_independent_code,
41+
3942
/* Other pointers signed under the ABI use private ABI rules. */
4043

4144
} ptrauth_key;
@@ -247,6 +250,9 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
247250
[[clang::ptrauth_vtable_pointer(key, address_discrimination, \
248251
extra_discrimination)]]
249252

253+
/* The value is ptrauth_string_discriminator("init_fini") */
254+
#define __ptrauth_init_fini_discriminator 0xd9d4
255+
250256
#else
251257

252258
#define ptrauth_strip(__value, __key) \

clang/lib/Sema/SemaLambda.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,8 @@ void Sema::CompleteLambdaCallOperator(
10211021
getGenericLambdaTemplateParameterList(LSI, *this);
10221022

10231023
DeclContext *DC = Method->getLexicalDeclContext();
1024+
// DeclContext::addDecl() assumes that the DeclContext we're adding to is the
1025+
// lexical context of the Method. Do so.
10241026
Method->setLexicalDeclContext(LSI->Lambda);
10251027
if (TemplateParams) {
10261028
FunctionTemplateDecl *TemplateMethod =
@@ -1105,6 +1107,8 @@ void Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
11051107

11061108
CXXMethodDecl *Method = CreateLambdaCallOperator(Intro.Range, Class);
11071109
LSI->CallOperator = Method;
1110+
// Temporarily set the lexical declaration context to the current
1111+
// context, so that the Scope stack matches the lexical nesting.
11081112
Method->setLexicalDeclContext(CurContext);
11091113

11101114
PushDeclContext(CurScope, Method);

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/ADT/STLForwardCompat.h"
4040
#include "llvm/ADT/StringExtras.h"
4141
#include "llvm/Support/ErrorHandling.h"
42+
#include "llvm/Support/SaveAndRestore.h"
4243
#include "llvm/Support/TimeProfiler.h"
4344
#include <optional>
4445

@@ -1657,11 +1658,12 @@ namespace {
16571658
LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
16581659
Sema::ConstraintEvalRAII<TemplateInstantiator> RAII(*this);
16591660

1660-
ExprResult Result = inherited::TransformLambdaExpr(E);
1661-
if (Result.isInvalid())
1662-
return Result;
1661+
return inherited::TransformLambdaExpr(E);
1662+
}
16631663

1664-
CXXMethodDecl *MD = Result.getAs<LambdaExpr>()->getCallOperator();
1664+
ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
1665+
LambdaScopeInfo *LSI) {
1666+
CXXMethodDecl *MD = LSI->CallOperator;
16651667
for (ParmVarDecl *PVD : MD->parameters()) {
16661668
assert(PVD && "null in a parameter list");
16671669
if (!PVD->hasDefaultArg())
@@ -1680,8 +1682,7 @@ namespace {
16801682
PVD->setDefaultArg(ErrorResult.get());
16811683
}
16821684
}
1683-
1684-
return Result;
1685+
return inherited::RebuildLambdaExpr(StartLoc, EndLoc, LSI);
16851686
}
16861687

16871688
StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body) {
@@ -1694,11 +1695,8 @@ namespace {
16941695
// `true` to temporarily fix this issue.
16951696
// FIXME: This temporary fix can be removed after fully implementing
16961697
// p0588r1.
1697-
bool Prev = EvaluateConstraints;
1698-
EvaluateConstraints = true;
1699-
StmtResult Stmt = inherited::TransformLambdaBody(E, Body);
1700-
EvaluateConstraints = Prev;
1701-
return Stmt;
1698+
llvm::SaveAndRestore _(EvaluateConstraints, true);
1699+
return inherited::TransformLambdaBody(E, Body);
17021700
}
17031701

17041702
ExprResult TransformRequiresExpr(RequiresExpr *E) {

0 commit comments

Comments
 (0)