Skip to content

Commit f7464e4

Browse files
committed
merge main into amd-staging
Change-Id: I86799a0abe3a5e218396a84865d99f667d5e9645
2 parents 34c3153 + a98a0dc commit f7464e4

File tree

296 files changed

+11149
-5753
lines changed

Some content is hidden

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

296 files changed

+11149
-5753
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
@@ -191,6 +191,8 @@ Bug Fixes to C++ Support
191191
substitutions in concepts, so it doesn't incorrectly complain of missing
192192
module imports in those situations. (#GH60336)
193193
- Fix init-capture packs having a size of one before being instantiated. (#GH63677)
194+
- Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667),
195+
(#GH99877).
194196

195197
Bug Fixes to AST Handling
196198
^^^^^^^^^^^^^^^^^^^^^^^^^

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/Basic/riscv_vector.td

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,9 @@ let HasMasked = false,
13781378
let RequiredFeatures = ["Zvfhmin"] in
13791379
defm vmv_v : RVVOutBuiltinSet<"vmv_v_v", "x",
13801380
[["v", "v", "vv"]]>;
1381+
let RequiredFeatures = ["Zvfbfmin"] in
1382+
defm vmv_v : RVVOutBuiltinSet<"vmv_v_v", "y",
1383+
[["v", "v", "vv"]]>;
13811384
let SupportOverloading = false in
13821385
defm vmv_v : RVVOutBuiltinSet<"vmv_v_x", "csil",
13831386
[["x", "v", "ve"],
@@ -1890,6 +1893,9 @@ let HasMasked = false,
18901893
let RequiredFeatures = ["Zvfhmin"] in
18911894
defm vmerge : RVVOutOp1BuiltinSet<"vmerge", "x",
18921895
[["vvm", "v", "vvvm"]]>;
1896+
let RequiredFeatures = ["Zvfbfmin"] in
1897+
defm vmerge : RVVOutOp1BuiltinSet<"vmerge", "y",
1898+
[["vvm", "v", "vvvm"]]>;
18931899
defm vfmerge : RVVOutOp1BuiltinSet<"vfmerge", "xfd",
18941900
[["vfm", "v", "vvem"]]>;
18951901
}
@@ -1912,8 +1918,18 @@ def vfcvt_rtz_x_f_v : RVVConvToSignedBuiltin<"vfcvt_rtz_x">;
19121918
let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
19131919
def vfwcvt_rtz_xu_f_v : RVVConvToWidenUnsignedBuiltin<"vfwcvt_rtz_xu">;
19141920
def vfwcvt_rtz_x_f_v : RVVConvToWidenSignedBuiltin<"vfwcvt_rtz_x">;
1915-
def vfwcvt_f_xu_v : RVVConvBuiltin<"Fw", "FwUv", "csi", "vfwcvt_f">;
1916-
def vfwcvt_f_x_v : RVVConvBuiltin<"Fw", "Fwv", "csi", "vfwcvt_f">;
1921+
def vfwcvt_f_xu_v : RVVConvBuiltin<"Fw", "FwUv", "si", "vfwcvt_f">;
1922+
def vfwcvt_f_x_v : RVVConvBuiltin<"Fw", "Fwv", "si", "vfwcvt_f">;
1923+
let RequiredFeatures = ["Zvfh"] in {
1924+
let Name = "vfwcvt_f_xu_v",
1925+
IRName = "vfwcvt_f_xu_v",
1926+
MaskedIRName = "vfwcvt_f_xu_v_mask" in
1927+
def : RVVConvBuiltin<"Fw", "FwUv", "c", "vfwcvt_f">;
1928+
let Name = "vfwcvt_f_x_v",
1929+
IRName = "vfwcvt_f_x_v",
1930+
MaskedIRName = "vfwcvt_f_x_v_mask" in
1931+
def : RVVConvBuiltin<"Fw", "Fwv", "c", "vfwcvt_f">;
1932+
}
19171933
def vfwcvt_f_f_v : RVVConvBuiltin<"w", "wv", "f", "vfwcvt_f">;
19181934
let RequiredFeatures = ["Zvfhmin"] in
19191935
def vfwcvt_f_f_v_fp16 : RVVConvBuiltin<"w", "wv", "x", "vfwcvt_f"> {
@@ -1927,6 +1943,16 @@ let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
19271943
let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
19281944
def vfncvt_rtz_xu_f_w : RVVConvToNarrowingUnsignedBuiltin<"vfncvt_rtz_xu">;
19291945
def vfncvt_rtz_x_f_w : RVVConvToNarrowingSignedBuiltin<"vfncvt_rtz_x">;
1946+
let RequiredFeatures = ["Zvfh"] in {
1947+
let Name = "vfncvt_rtz_xu_f_w",
1948+
IRName = "vfncvt_rtz_xu_f_w",
1949+
MaskedIRName = "vfncvt_rtz_xu_f_w_mask" in
1950+
def : RVVConvBuiltin<"Uv", "UvFw", "c", "vfncvt_rtz_xu">;
1951+
let Name = "vfncvt_rtz_x_f_w",
1952+
IRName = "vfncvt_rtz_x_f_w",
1953+
MaskedIRName = "vfncvt_rtz_x_f_w_mask" in
1954+
def : RVVConvBuiltin<"Iv", "IvFw", "c", "vfncvt_rtz_x">;
1955+
}
19301956
def vfncvt_rod_f_f_w : RVVConvBuiltin<"v", "vw", "xf", "vfncvt_rod_f">;
19311957
}
19321958

@@ -2005,10 +2031,18 @@ let ManualCodegen = [{
20052031
let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
20062032
let OverloadedName = "vfncvt_x" in
20072033
defm :
2008-
RVVConvBuiltinSet<"vfncvt_x_f_w", "csi", [["Iv", "IvFwu"]]>;
2034+
RVVConvBuiltinSet<"vfncvt_x_f_w", "si", [["Iv", "IvFwu"]]>;
20092035
let OverloadedName = "vfncvt_xu" in
20102036
defm :
2011-
RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFwu"]]>;
2037+
RVVConvBuiltinSet<"vfncvt_xu_f_w", "si", [["Uv", "UvFwu"]]>;
2038+
let RequiredFeatures = ["Zvfh"] in {
2039+
let OverloadedName = "vfncvt_x" in
2040+
defm :
2041+
RVVConvBuiltinSet<"vfncvt_x_f_w", "c", [["Iv", "IvFwu"]]>;
2042+
let OverloadedName = "vfncvt_xu" in
2043+
defm :
2044+
RVVConvBuiltinSet<"vfncvt_xu_f_w", "c", [["Uv", "UvFwu"]]>;
2045+
}
20122046
let OverloadedName = "vfncvt_f" in {
20132047
defm :
20142048
RVVConvBuiltinSet<"vfncvt_f_x_w", "xf", [["v", "vIwu"]]>;
@@ -2055,10 +2089,18 @@ let ManualCodegen = [{
20552089
let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
20562090
let OverloadedName = "vfncvt_x" in
20572091
defm :
2058-
RVVConvBuiltinSet<"vfncvt_x_f_w", "csi", [["Iv", "IvFw"]]>;
2092+
RVVConvBuiltinSet<"vfncvt_x_f_w", "si", [["Iv", "IvFw"]]>;
20592093
let OverloadedName = "vfncvt_xu" in
20602094
defm :
2061-
RVVConvBuiltinSet<"vfncvt_xu_f_w", "csi", [["Uv", "UvFw"]]>;
2095+
RVVConvBuiltinSet<"vfncvt_xu_f_w", "si", [["Uv", "UvFw"]]>;
2096+
let RequiredFeatures = ["Zvfh"] in {
2097+
let OverloadedName = "vfncvt_x" in
2098+
defm :
2099+
RVVConvBuiltinSet<"vfncvt_x_f_w", "c", [["Iv", "IvFw"]]>;
2100+
let OverloadedName = "vfncvt_xu" in
2101+
defm :
2102+
RVVConvBuiltinSet<"vfncvt_xu_f_w", "c", [["Uv", "UvFw"]]>;
2103+
}
20622104
let OverloadedName = "vfncvt_f" in {
20632105
defm :
20642106
RVVConvBuiltinSet<"vfncvt_f_x_w", "xf", [["v", "vIw"]]>;
@@ -2256,10 +2298,22 @@ defm vfslide1down : RVVFloatingBinVFBuiltinSet;
22562298

22572299
// 16.4. Vector Register Gather Instructions
22582300
// signed and floating type
2259-
defm vrgather : RVVOutBuiltinSet<"vrgather_vv", "csilxfd",
2301+
defm vrgather : RVVOutBuiltinSet<"vrgather_vv", "csilfd",
22602302
[["vv", "v", "vvUv"]]>;
2261-
defm vrgather : RVVOutBuiltinSet<"vrgather_vx", "csilxfd",
2303+
defm vrgather : RVVOutBuiltinSet<"vrgather_vx", "csilfd",
22622304
[["vx", "v", "vvz"]]>;
2305+
let RequiredFeatures = ["Zvfhmin"] in {
2306+
defm vrgather : RVVOutBuiltinSet<"vrgather_vv", "x",
2307+
[["vv", "v", "vvUv"]]>;
2308+
defm vrgather : RVVOutBuiltinSet<"vrgather_vx", "x",
2309+
[["vx", "v", "vvz"]]>;
2310+
}
2311+
let RequiredFeatures = ["Zvfbfmin"] in {
2312+
defm vrgather : RVVOutBuiltinSet<"vrgather_vv", "y",
2313+
[["vv", "v", "vvUv"]]>;
2314+
defm vrgather : RVVOutBuiltinSet<"vrgather_vx", "y",
2315+
[["vx", "v", "vvz"]]>;
2316+
}
22632317
defm vrgatherei16 : RVVOutBuiltinSet<"vrgatherei16_vv", "csilxfd",
22642318
[["vv", "v", "vv(Log2EEW:4)Uv"]]>;
22652319
// unsigned type
@@ -2282,8 +2336,14 @@ let HasMasked = false,
22822336
IntrinsicTypes = {ResultType, Ops.back()->getType()};
22832337
}] in {
22842338
// signed and floating type
2285-
defm vcompress : RVVOutBuiltinSet<"vcompress", "csilxfd",
2339+
defm vcompress : RVVOutBuiltinSet<"vcompress", "csilfd",
22862340
[["vm", "v", "vvm"]]>;
2341+
let RequiredFeatures = ["Zvfhmin"] in
2342+
defm vcompress : RVVOutBuiltinSet<"vcompress", "x",
2343+
[["vm", "v", "vvm"]]>;
2344+
let RequiredFeatures = ["Zvfbfmin"] in
2345+
defm vcompress : RVVOutBuiltinSet<"vcompress", "y",
2346+
[["vm", "v", "vvm"]]>;
22872347
// unsigned type
22882348
defm vcompress : RVVOutBuiltinSet<"vcompress", "csil",
22892349
[["vm", "Uv", "UvUvm"]]>;

clang/include/clang/Basic/riscv_vector_common.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,10 @@ class RVVConvToWidenUnsignedBuiltin<string overloaded_name>
604604
: RVVConvBuiltin<"Uw", "Uwv", "xf", overloaded_name>;
605605

606606
class RVVConvToNarrowingSignedBuiltin<string overloaded_name>
607-
: RVVConvBuiltin<"Iv", "IvFw", "csi", overloaded_name>;
607+
: RVVConvBuiltin<"Iv", "IvFw", "si", overloaded_name>;
608608

609609
class RVVConvToNarrowingUnsignedBuiltin<string overloaded_name>
610-
: RVVConvBuiltin<"Uv", "UvFw", "csi", overloaded_name>;
610+
: RVVConvBuiltin<"Uv", "UvFw", "si", overloaded_name>;
611611

612612
let HasMaskedOffOperand = true in {
613613
multiclass RVVSignedReductionBuiltin {

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4331,11 +4331,13 @@ defm ptrauth_vtable_pointer_type_discrimination :
43314331
OptInCC1FFlag<"ptrauth-vtable-pointer-type-discrimination", "Enable type discrimination of vtable pointers">;
43324332
defm ptrauth_type_info_vtable_pointer_discrimination :
43334333
OptInCC1FFlag<"ptrauth-type-info-vtable-pointer-discrimination", "Enable type and address discrimination of vtable pointer of std::type_info">;
4334-
defm ptrauth_init_fini : OptInCC1FFlag<"ptrauth-init-fini", "Enable signing of function pointers in init/fini arrays">;
43354334
defm ptrauth_function_pointer_type_discrimination : OptInCC1FFlag<"ptrauth-function-pointer-type-discrimination",
43364335
"Enable type discrimination on C function pointers">;
43374336
defm ptrauth_indirect_gotos : OptInCC1FFlag<"ptrauth-indirect-gotos",
43384337
"Enable signing and authentication of indirect goto targets">;
4338+
defm ptrauth_init_fini : OptInCC1FFlag<"ptrauth-init-fini", "Enable signing of function pointers in init/fini arrays">;
4339+
defm ptrauth_init_fini_address_discrimination : OptInCC1FFlag<"ptrauth-init-fini-address-discrimination",
4340+
"Enable address discrimination of function pointers in init/fini arrays">;
43394341
}
43404342

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

clang/include/clang/Support/RISCVVIntrinsicUtils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ enum RVVRequire : uint32_t {
502502
RVV_REQ_Zvksh = 1 << 15,
503503
RVV_REQ_Zvfbfwma = 1 << 16,
504504
RVV_REQ_Zvfbfmin = 1 << 17,
505-
RVV_REQ_Experimental = 1 << 18,
505+
RVV_REQ_Zvfh = 1 << 18,
506+
RVV_REQ_Experimental = 1 << 19,
506507

507508
LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Experimental)
508509
};

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
@@ -1228,10 +1228,13 @@ void CodeGenModule::Release() {
12281228
(LangOpts.PointerAuthVTPtrTypeDiscrimination
12291229
<< AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_VPTRTYPEDISCR) |
12301230
(LangOpts.PointerAuthInitFini
1231-
<< AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI);
1232-
static_assert(AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI ==
1233-
AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_LAST,
1234-
"Update when new enum items are defined");
1231+
<< AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINI) |
1232+
(LangOpts.PointerAuthInitFiniAddressDiscrimination
1233+
<< AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINIADDRDISC);
1234+
static_assert(
1235+
AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_INITFINIADDRDISC ==
1236+
AARCH64_PAUTH_PLATFORM_LLVM_LINUX_VERSION_LAST,
1237+
"Update when new enum items are defined");
12351238
if (PAuthABIVersion != 0) {
12361239
getModule().addModuleFlag(llvm::Module::Error,
12371240
"aarch64-elf-pauthabi-platform",
@@ -2092,37 +2095,53 @@ void CodeGenModule::AddGlobalDtor(llvm::Function *Dtor, int Priority,
20922095
void CodeGenModule::EmitCtorList(CtorList &Fns, const char *GlobalName) {
20932096
if (Fns.empty()) return;
20942097

2095-
// Ctor function type is void()*.
2096-
llvm::FunctionType* CtorFTy = llvm::FunctionType::get(VoidTy, false);
2097-
llvm::Type *CtorPFTy = llvm::PointerType::get(CtorFTy,
2098-
TheModule.getDataLayout().getProgramAddressSpace());
2098+
const PointerAuthSchema &InitFiniAuthSchema =
2099+
getCodeGenOpts().PointerAuth.InitFiniPointers;
20992100

2100-
// Get the type of a ctor entry, { i32, void ()*, i8* }.
2101-
llvm::StructType *CtorStructTy = llvm::StructType::get(
2102-
Int32Ty, CtorPFTy, VoidPtrTy);
2101+
// Ctor function type is ptr.
2102+
llvm::PointerType *PtrTy = llvm::PointerType::get(
2103+
getLLVMContext(), TheModule.getDataLayout().getProgramAddressSpace());
2104+
2105+
// Get the type of a ctor entry, { i32, ptr, ptr }.
2106+
llvm::StructType *CtorStructTy = llvm::StructType::get(Int32Ty, PtrTy, PtrTy);
21032107

21042108
// Construct the constructor and destructor arrays.
2105-
ConstantInitBuilder builder(*this);
2106-
auto ctors = builder.beginArray(CtorStructTy);
2109+
ConstantInitBuilder Builder(*this);
2110+
auto Ctors = Builder.beginArray(CtorStructTy);
21072111
for (const auto &I : Fns) {
2108-
auto ctor = ctors.beginStruct(CtorStructTy);
2109-
ctor.addInt(Int32Ty, I.Priority);
2110-
ctor.add(I.Initializer);
2112+
auto Ctor = Ctors.beginStruct(CtorStructTy);
2113+
Ctor.addInt(Int32Ty, I.Priority);
2114+
if (InitFiniAuthSchema) {
2115+
llvm::Constant *StorageAddress =
2116+
(InitFiniAuthSchema.isAddressDiscriminated()
2117+
? llvm::ConstantExpr::getIntToPtr(
2118+
llvm::ConstantInt::get(
2119+
IntPtrTy,
2120+
llvm::ConstantPtrAuth::AddrDiscriminator_CtorsDtors),
2121+
PtrTy)
2122+
: nullptr);
2123+
llvm::Constant *SignedCtorPtr = getConstantSignedPointer(
2124+
I.Initializer, InitFiniAuthSchema.getKey(), StorageAddress,
2125+
llvm::ConstantInt::get(
2126+
SizeTy, InitFiniAuthSchema.getConstantDiscrimination()));
2127+
Ctor.add(SignedCtorPtr);
2128+
} else {
2129+
Ctor.add(I.Initializer);
2130+
}
21112131
if (I.AssociatedData)
2112-
ctor.add(I.AssociatedData);
2132+
Ctor.add(I.AssociatedData);
21132133
else
2114-
ctor.addNullPointer(VoidPtrTy);
2115-
ctor.finishAndAddTo(ctors);
2134+
Ctor.addNullPointer(PtrTy);
2135+
Ctor.finishAndAddTo(Ctors);
21162136
}
21172137

2118-
auto list =
2119-
ctors.finishAndCreateGlobal(GlobalName, getPointerAlign(),
2120-
/*constant*/ false,
2121-
llvm::GlobalValue::AppendingLinkage);
2138+
auto List = Ctors.finishAndCreateGlobal(GlobalName, getPointerAlign(),
2139+
/*constant*/ false,
2140+
llvm::GlobalValue::AppendingLinkage);
21222141

21232142
// The LTO linker doesn't seem to like it when we set an alignment
21242143
// on appending variables. Take it off as a workaround.
2125-
list->setAlignment(std::nullopt);
2144+
List->setAlignment(std::nullopt);
21262145

21272146
Fns.clear();
21282147
}

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,14 +1900,17 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
19001900
Args.addOptInFlag(
19011901
CmdArgs, options::OPT_fptrauth_type_info_vtable_pointer_discrimination,
19021902
options::OPT_fno_ptrauth_type_info_vtable_pointer_discrimination);
1903-
Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_init_fini,
1904-
options::OPT_fno_ptrauth_init_fini);
19051903
Args.addOptInFlag(
19061904
CmdArgs, options::OPT_fptrauth_function_pointer_type_discrimination,
19071905
options::OPT_fno_ptrauth_function_pointer_type_discrimination);
19081906

19091907
Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_indirect_gotos,
19101908
options::OPT_fno_ptrauth_indirect_gotos);
1909+
Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_init_fini,
1910+
options::OPT_fno_ptrauth_init_fini);
1911+
Args.addOptInFlag(CmdArgs,
1912+
options::OPT_fptrauth_init_fini_address_discrimination,
1913+
options::OPT_fno_ptrauth_init_fini_address_discrimination);
19111914
}
19121915

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

0 commit comments

Comments
 (0)