Skip to content

Commit b56415c

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:4effda09d897 into amd-gfx:3d7ab622862d
Local branch amd-gfx 3d7ab62 Merged main:9555736ac6d0 into amd-gfx:7c675722cfee Remote branch main 4effda0 [ASan] return 0 for current allocated bytes if malloc/free are never happend (llvm#67394)
2 parents 3d7ab62 + 4effda0 commit b56415c

File tree

50 files changed

+750
-395
lines changed

Some content is hidden

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

50 files changed

+750
-395
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ Attribute Changes in Clang
171171
automatic diagnostic to use parameters of types that the format style
172172
supports but that are never the result of default argument promotion, such as
173173
``float``. (`#59824: <https://github.com/llvm/llvm-project/issues/59824>`_)
174+
- The ``constructor`` and ``destructor`` attributes now diagnose when:
175+
- the priority is not between 101 and 65535, inclusive,
176+
- the function it is applied to accepts arguments or has a non-void return
177+
type, or
178+
- the function it is applied to is a non-static member function (C++).
174179

175180
Improvements to Clang's diagnostics
176181
-----------------------------------

clang/include/clang/Basic/AttrDocs.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7251,8 +7251,10 @@ after returning from ``main()`` or when the ``exit()`` function has been
72517251
called. Note, ``quick_exit()``, ``_Exit()``, and ``abort()`` prevent a function
72527252
marked ``destructor`` from being called.
72537253

7254-
The constructor or destructor function should not accept any arguments and its
7255-
return type should be ``void``.
7254+
The constructor or destructor function cannot accept any arguments and its
7255+
return type should be ``void``, ``int``, or ``unsigned int``. The latter two
7256+
types are supported for historical reasons. In C++ language modes, the function
7257+
cannot be marked ``consteval``, nor can it be a non-static member function.
72567258

72577259
The attributes accept an optional argument used to specify the priority order
72587260
in which to execute constructor and destructor functions. The priority is

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
174174
/// The code model to use (-mcmodel).
175175
std::string CodeModel;
176176

177+
/// The code model-specific large data threshold to use
178+
/// (-mlarge-data-threshold).
179+
uint64_t LargeDataThreshold;
180+
177181
/// The filename with path we use for coverage data files. The runtime
178182
/// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
179183
/// environment variables.

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ def warn_unsupported_branch_protection: Warning <
456456
"invalid branch protection option '%0' in '%1'">, InGroup<BranchProtection>;
457457
def err_sls_hardening_arm_not_supported : Error<
458458
"-mharden-sls is only supported on armv7-a or later">;
459+
def warn_drv_large_data_threshold_invalid_code_model: Warning<
460+
"'%0' only applies to medium code model">,
461+
InGroup<UnusedCommandLineArgument>;
459462

460463
def note_drv_command_failed_diag_msg : Note<
461464
"diagnostic msg: %0">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,6 +2864,8 @@ def warn_cxx11_compat_constexpr_body_multiple_return : Warning<
28642864
InGroup<CXXPre14Compat>, DefaultIgnore;
28652865
def note_constexpr_body_previous_return : Note<
28662866
"previous return statement is here">;
2867+
def err_ctordtor_attr_consteval : Error<
2868+
"%0 attribute cannot be applied to a 'consteval' function">;
28672869

28682870
// C++20 function try blocks in constexpr
28692871
def ext_constexpr_function_try_block_cxx20 : ExtWarn<
@@ -3176,6 +3178,11 @@ def err_alignas_underaligned : Error<
31763178
"requested alignment is less than minimum alignment of %1 for type %0">;
31773179
def warn_aligned_attr_underaligned : Warning<err_alignas_underaligned.Summary>,
31783180
InGroup<IgnoredAttributes>;
3181+
def err_ctor_dtor_attr_on_non_void_func : Error<
3182+
"%0 attribute can only be applied to a function which accepts no arguments "
3183+
"and has a 'void' or 'int' return type">;
3184+
def err_ctor_dtor_member_func : Error<
3185+
"%0 attribute cannot be applied to a member function">;
31793186
def err_attribute_sizeless_type : Error<
31803187
"%0 attribute cannot be applied to sizeless type %1">;
31813188
def err_attribute_argument_n_type : Error<

clang/include/clang/Basic/TargetOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ class TargetOptions {
109109
// code model.
110110
std::string CodeModel;
111111

112+
// The large data threshold used for certain code models on certain
113+
// architectures.
114+
uint64_t LargeDataThreshold;
115+
112116
/// The version of the SDK which was used during the compilation.
113117
/// The option is used for two different purposes:
114118
/// * on darwin the version is propagated to LLVM where it's used

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4248,6 +4248,9 @@ def inline_asm_EQ : Joined<["-"], "inline-asm=">, Group<m_Group>,
42484248
def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group<m_Group>,
42494249
Visibility<[ClangOption, CC1Option]>,
42504250
MarshallingInfoString<TargetOpts<"CodeModel">, [{"default"}]>;
4251+
def mlarge_data_threshold_EQ : Joined<["-"], "mlarge-data-threshold=">, Group<m_Group>,
4252+
Visibility<[ClangOption, CC1Option]>,
4253+
MarshallingInfoInt<TargetOpts<"LargeDataThreshold">>;
42514254
def mtls_size_EQ : Joined<["-"], "mtls-size=">, Group<m_Group>,
42524255
Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
42534256
HelpText<"Specify bit size of immediate TLS offsets (AArch64 ELF only): "

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
572572
return;
573573
TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
574574
Options, RM, CM, OptLevel));
575+
TM->setLargeDataThreshold(CodeGenOpts.LargeDataThreshold);
575576
}
576577

577578
bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,12 @@ void CodeGenModule::Release() {
11461146
if (CM != ~0u) {
11471147
llvm::CodeModel::Model codeModel = static_cast<llvm::CodeModel::Model>(CM);
11481148
getModule().setCodeModel(codeModel);
1149+
1150+
if (CM == llvm::CodeModel::Medium &&
1151+
Context.getTargetInfo().getTriple().getArch() ==
1152+
llvm::Triple::x86_64) {
1153+
getModule().setLargeDataThreshold(getCodeGenOpts().LargeDataThreshold);
1154+
}
11491155
}
11501156
}
11511157

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5714,6 +5714,23 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
57145714
}
57155715
}
57165716

5717+
if (Arg *A = Args.getLastArg(options::OPT_mlarge_data_threshold_EQ)) {
5718+
if (!Triple.isX86()) {
5719+
D.Diag(diag::err_drv_unsupported_opt_for_target)
5720+
<< A->getOption().getName() << TripleStr;
5721+
} else {
5722+
bool IsMediumCM = false;
5723+
if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ))
5724+
IsMediumCM = StringRef(A->getValue()) == "medium";
5725+
if (!IsMediumCM) {
5726+
D.Diag(diag::warn_drv_large_data_threshold_invalid_code_model)
5727+
<< A->getOption().getRenderName();
5728+
} else {
5729+
A->render(Args, CmdArgs);
5730+
}
5731+
}
5732+
}
5733+
57175734
if (Arg *A = Args.getLastArg(options::OPT_mtls_size_EQ)) {
57185735
StringRef Value = A->getValue();
57195736
unsigned TLSSize = 0;

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,8 +2023,7 @@ void tools::addX86AlignBranchArgs(const Driver &D, const ArgList &Args,
20232023
bool tools::SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs,
20242024
llvm::opt::ArgStringList &CC1Args,
20252025
SmallVector<std::string, 8> LibraryPaths, std::string Lib,
2026-
StringRef Arch, StringRef Target, bool isBitCodeSDL,
2027-
bool postClangLink) {
2026+
StringRef Arch, StringRef Target, bool isBitCodeSDL) {
20282027
SmallVector<std::string, 12> SDLs;
20292028

20302029
std::string LibDeviceLoc = "/libdevice";
@@ -2083,8 +2082,6 @@ bool tools::SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs,
20832082
for (auto SDL : SDLs) {
20842083
auto FullName = Twine(LPath + SDL).str();
20852084
if (llvm::sys::fs::exists(FullName)) {
2086-
if (postClangLink)
2087-
CC1Args.push_back("-mlink-builtin-bitcode");
20882085
CC1Args.push_back(DriverArgs.MakeArgString(FullName));
20892086
FoundSDL = true;
20902087
break;
@@ -2104,8 +2101,7 @@ bool tools::GetSDLFromOffloadArchive(
21042101
Compilation &C, const Driver &D, const Tool &T, const JobAction &JA,
21052102
const InputInfoList &Inputs, const llvm::opt::ArgList &DriverArgs,
21062103
llvm::opt::ArgStringList &CC1Args, SmallVector<std::string, 8> LibraryPaths,
2107-
StringRef Lib, StringRef Arch, StringRef Target, bool isBitCodeSDL,
2108-
bool postClangLink) {
2104+
StringRef Lib, StringRef Arch, StringRef Target, bool isBitCodeSDL) {
21092105

21102106
// We don't support bitcode archive bundles for nvptx
21112107
if (isBitCodeSDL && Arch.contains("nvptx"))
@@ -2203,8 +2199,6 @@ bool tools::GetSDLFromOffloadArchive(
22032199
C.addCommand(std::make_unique<Command>(
22042200
JA, T, ResponseFileSupport::AtFileCurCP(), UBProgram, UBArgs, Inputs,
22052201
InputInfo(&JA, C.getArgs().MakeArgString(OutputLib))));
2206-
if (postClangLink)
2207-
CC1Args.push_back("-mlink-builtin-bitcode");
22082202

22092203
CC1Args.push_back(DriverArgs.MakeArgString(OutputLib));
22102204

@@ -2213,14 +2207,14 @@ bool tools::GetSDLFromOffloadArchive(
22132207

22142208
// Wrapper function used by driver for adding SDLs during link phase.
22152209
void tools::AddStaticDeviceLibsLinking(Compilation &C, const Tool &T,
2216-
const JobAction &JA,
2217-
const InputInfoList &Inputs,
2218-
const llvm::opt::ArgList &DriverArgs,
2219-
llvm::opt::ArgStringList &CC1Args,
2220-
StringRef Arch, StringRef Target,
2221-
bool isBitCodeSDL, bool postClangLink) {
2210+
const JobAction &JA,
2211+
const InputInfoList &Inputs,
2212+
const llvm::opt::ArgList &DriverArgs,
2213+
llvm::opt::ArgStringList &CC1Args,
2214+
StringRef Arch, StringRef Target,
2215+
bool isBitCodeSDL) {
22222216
AddStaticDeviceLibs(&C, &T, &JA, &Inputs, C.getDriver(), DriverArgs, CC1Args,
2223-
Arch, Target, isBitCodeSDL, postClangLink);
2217+
Arch, Target, isBitCodeSDL);
22242218
}
22252219

22262220
// User defined Static Device Libraries(SDLs) can be passed to clang for
@@ -2252,7 +2246,7 @@ void tools::AddStaticDeviceLibs(Compilation *C, const Tool *T,
22522246
const llvm::opt::ArgList &DriverArgs,
22532247
llvm::opt::ArgStringList &CC1Args,
22542248
StringRef Arch, StringRef Target,
2255-
bool isBitCodeSDL, bool postClangLink) {
2249+
bool isBitCodeSDL) {
22562250

22572251
SmallVector<std::string, 8> LibraryPaths;
22582252
// Add search directories from LIBRARY_PATH env variable
@@ -2308,10 +2302,10 @@ void tools::AddStaticDeviceLibs(Compilation *C, const Tool *T,
23082302
for (auto SDLName : SDLNames) {
23092303
// This is the only call to SDLSearch
23102304
if (!SDLSearch(D, DriverArgs, CC1Args, LibraryPaths, SDLName, Arch, Target,
2311-
isBitCodeSDL, postClangLink)) {
2305+
isBitCodeSDL)) {
23122306
GetSDLFromOffloadArchive(*C, D, *T, *JA, *Inputs, DriverArgs, CC1Args,
23132307
LibraryPaths, SDLName, Arch, Target,
2314-
isBitCodeSDL, postClangLink);
2308+
isBitCodeSDL);
23152309
}
23162310
}
23172311
}

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,25 @@ void AddStaticDeviceLibsLinking(Compilation &C, const Tool &T,
5959
const llvm::opt::ArgList &DriverArgs,
6060
llvm::opt::ArgStringList &CmdArgs,
6161
StringRef Arch, StringRef Target,
62-
bool isBitCodeSDL, bool postClangLink);
62+
bool isBitCodeSDL);
6363
void AddStaticDeviceLibs(Compilation *C, const Tool *T, const JobAction *JA,
6464
const InputInfoList *Inputs, const Driver &D,
6565
const llvm::opt::ArgList &DriverArgs,
6666
llvm::opt::ArgStringList &CmdArgs, StringRef Arch,
67-
StringRef Target, bool isBitCodeSDL,
68-
bool postClangLink);
67+
StringRef Target, bool isBitCodeSDL);
6968

7069
bool SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs,
7170
llvm::opt::ArgStringList &CmdArgs,
7271
SmallVector<std::string, 8> LibraryPaths, std::string Lib,
73-
StringRef Arch, StringRef Target, bool isBitCodeSDL,
74-
bool postClangLink);
72+
StringRef Arch, StringRef Target, bool isBitCodeSDL);
7573

7674
bool GetSDLFromOffloadArchive(Compilation &C, const Driver &D, const Tool &T,
7775
const JobAction &JA, const InputInfoList &Inputs,
7876
const llvm::opt::ArgList &DriverArgs,
7977
llvm::opt::ArgStringList &CC1Args,
8078
SmallVector<std::string, 8> LibraryPaths,
8179
StringRef Lib, StringRef Arch, StringRef Target,
82-
bool isBitCodeSDL, bool postClangLink);
80+
bool isBitCodeSDL);
8381

8482
const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
8583
const InputInfo &Input, const InputInfo &Output);

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ void AMDGCN::Linker::constructLlvmLinkCommand(Compilation &C,
9191
// for the extracted archive of bitcode to inputs.
9292
auto TargetID = Args.getLastArgValue(options::OPT_mcpu_EQ);
9393
AddStaticDeviceLibsLinking(C, *this, JA, Inputs, Args, LlvmLinkArgs, "amdgcn",
94-
TargetID,
95-
/*IsBitCodeSDL=*/true,
96-
/*PostClangLink=*/false);
94+
TargetID, /*IsBitCodeSDL=*/true);
9795

9896
const char *LlvmLink =
9997
Args.MakeArgString(getToolChain().GetProgramPath("llvm-link"));
@@ -179,9 +177,7 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
179177
// for the extracted archive of bitcode to inputs.
180178
auto TargetID = Args.getLastArgValue(options::OPT_mcpu_EQ);
181179
AddStaticDeviceLibsLinking(C, *this, JA, Inputs, Args, LldArgs, "amdgcn",
182-
TargetID,
183-
/*IsBitCodeSDL=*/true,
184-
/*PostClangLink=*/false);
180+
TargetID, /*IsBitCodeSDL=*/true);
185181

186182
LldArgs.push_back("--no-whole-archive");
187183

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
574574
llvm::Triple::ArchType Arch = T.getArch();
575575

576576
CodeGenOpts.CodeModel = TargetOpts.CodeModel;
577+
CodeGenOpts.LargeDataThreshold = TargetOpts.LargeDataThreshold;
577578

578579
if (LangOpts.getExceptionHandling() !=
579580
LangOptions::ExceptionHandlingKind::None &&

0 commit comments

Comments
 (0)