Skip to content

Commit bc5391e

Browse files
committed
Merge remote-tracking branch 'upstream/main' into cmake-header-checks
2 parents 75759a6 + ab6e63a commit bc5391e

File tree

100 files changed

+2577
-784
lines changed

Some content is hidden

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

100 files changed

+2577
-784
lines changed

clang/include/clang/Driver/Driver.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@ enum ModuleHeaderMode {
7272
HeaderMode_System
7373
};
7474

75+
/// Options for specifying CUID used by CUDA/HIP for uniquely identifying
76+
/// compilation units.
77+
class CUIDOptions {
78+
public:
79+
enum class Kind { Hash, Random, Fixed, None, Invalid };
80+
81+
CUIDOptions() = default;
82+
CUIDOptions(llvm::opt::DerivedArgList &Args, const Driver &D);
83+
84+
// Get the CUID for an input string
85+
std::string getCUID(StringRef InputFile,
86+
llvm::opt::DerivedArgList &Args) const;
87+
88+
bool isEnabled() const {
89+
return UseCUID != Kind::None && UseCUID != Kind::Invalid;
90+
}
91+
92+
private:
93+
Kind UseCUID = Kind::None;
94+
StringRef FixedCUID;
95+
};
96+
7597
/// Driver - Encapsulate logic for constructing compilation processes
7698
/// from a set of gcc-driver-like command line arguments.
7799
class Driver {
@@ -119,6 +141,9 @@ class Driver {
119141
/// LTO mode selected via -f(no-offload-)?lto(=.*)? options.
120142
LTOKind OffloadLTOMode;
121143

144+
/// Options for CUID
145+
CUIDOptions CUIDOpts;
146+
122147
public:
123148
enum OpenMPRuntimeKind {
124149
/// An unknown OpenMP runtime. We can't generate effective OpenMP code
@@ -501,10 +526,11 @@ class Driver {
501526
/// \param C - The compilation that is being built.
502527
/// \param Args - The input arguments.
503528
/// \param Input - The input type and arguments
529+
/// \param CUID - The CUID for \p Input
504530
/// \param HostAction - The host action used in the offloading toolchain.
505531
Action *BuildOffloadingActions(Compilation &C,
506532
llvm::opt::DerivedArgList &Args,
507-
const InputTy &Input,
533+
const InputTy &Input, StringRef CUID,
508534
Action *HostAction) const;
509535

510536
/// Returns the set of bound architectures active for this offload kind.
@@ -728,6 +754,9 @@ class Driver {
728754
/// Get the specific kind of offload LTO being performed.
729755
LTOKind getOffloadLTOMode() const { return OffloadLTOMode; }
730756

757+
/// Get the CUID option.
758+
const CUIDOptions &getCUIDOpts() const { return CUIDOpts; }
759+
731760
private:
732761

733762
/// Tries to load options from configuration files.

clang/include/clang/Tooling/Tooling.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ buildASTFromCode(StringRef Code, StringRef FileName = "input.cc",
223223
/// \param PCHContainerOps The PCHContainerOperations for loading and creating
224224
/// clang modules.
225225
///
226-
/// \param Adjuster A function to filter the command line arguments as specified.
226+
/// \param Adjuster A function to filter the command line arguments as
227+
/// specified.
228+
///
229+
/// \param BaseFS FileSystem for managing and looking up files.
230+
/// VirtualMappedFiles takes precedence.
227231
///
228232
/// \return The resulting AST or null if an error occurred.
229233
std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
@@ -233,7 +237,9 @@ std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
233237
std::make_shared<PCHContainerOperations>(),
234238
ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(),
235239
const FileContentMappings &VirtualMappedFiles = FileContentMappings(),
236-
DiagnosticConsumer *DiagConsumer = nullptr);
240+
DiagnosticConsumer *DiagConsumer = nullptr,
241+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS =
242+
llvm::vfs::getRealFileSystem());
237243

238244
/// Utility to run a FrontendAction in a single clang invocation.
239245
class ToolInvocation {

clang/lib/AST/ASTImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6376,7 +6376,7 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
63766376
D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind());
63776377

63786378
if (auto P = D->getInstantiatedFrom()) {
6379-
if (auto *CTD = P.dyn_cast<ClassTemplateDecl *>()) {
6379+
if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
63806380
if (auto CTDorErr = import(CTD))
63816381
D2->setInstantiationOf(*CTDorErr);
63826382
} else {

clang/lib/Basic/TargetInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
425425
// HLSL explicitly defines the sizes and formats of some data types, and we
426426
// need to conform to those regardless of what architecture you are targeting.
427427
if (Opts.HLSL) {
428+
BoolWidth = BoolAlign = 32;
428429
LongWidth = LongAlign = 64;
429430
if (!Opts.NativeHalfType) {
430431
HalfFormat = &llvm::APFloat::IEEEsingle();

clang/lib/Basic/Targets/ARM.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@ bool ARMTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
617617
case 6:
618618
if (ArchProfile == llvm::ARM::ProfileKind::M)
619619
LDREX = 0;
620-
else if (ArchKind == llvm::ARM::ArchKind::ARMV6K)
620+
else if (ArchKind == llvm::ARM::ArchKind::ARMV6K ||
621+
ArchKind == llvm::ARM::ArchKind::ARMV6KZ)
621622
LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B;
622623
else
623624
LDREX = LDREX_W;

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7768,7 +7768,7 @@ class MappableExprsHandler {
77687768
&Data : RecordLayout) {
77697769
if (Data.isNull())
77707770
continue;
7771-
if (const auto *Base = Data.dyn_cast<const CXXRecordDecl *>())
7771+
if (const auto *Base = dyn_cast<const CXXRecordDecl *>(Data))
77727772
getPlainLayout(Base, Layout, /*AsBase=*/true);
77737773
else
77747774
Layout.push_back(cast<const FieldDecl *>(Data));

clang/lib/Driver/Driver.cpp

Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,50 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath) {
197197
return std::string(P);
198198
}
199199

200+
CUIDOptions::CUIDOptions(llvm::opt::DerivedArgList &Args, const Driver &D)
201+
: UseCUID(Kind::Hash) {
202+
if (Arg *A = Args.getLastArg(options::OPT_fuse_cuid_EQ)) {
203+
StringRef UseCUIDStr = A->getValue();
204+
UseCUID = llvm::StringSwitch<Kind>(UseCUIDStr)
205+
.Case("hash", Kind::Hash)
206+
.Case("random", Kind::Random)
207+
.Case("none", Kind::None)
208+
.Default(Kind::Invalid);
209+
if (UseCUID == Kind::Invalid)
210+
D.Diag(clang::diag::err_drv_invalid_value)
211+
<< A->getAsString(Args) << UseCUIDStr;
212+
}
213+
214+
FixedCUID = Args.getLastArgValue(options::OPT_cuid_EQ);
215+
if (!FixedCUID.empty())
216+
UseCUID = Kind::Fixed;
217+
}
218+
219+
std::string CUIDOptions::getCUID(StringRef InputFile,
220+
llvm::opt::DerivedArgList &Args) const {
221+
std::string CUID = FixedCUID.str();
222+
if (CUID.empty()) {
223+
if (UseCUID == Kind::Random)
224+
CUID = llvm::utohexstr(llvm::sys::Process::GetRandomNumber(),
225+
/*LowerCase=*/true);
226+
else if (UseCUID == Kind::Hash) {
227+
llvm::MD5 Hasher;
228+
llvm::MD5::MD5Result Hash;
229+
SmallString<256> RealPath;
230+
llvm::sys::fs::real_path(InputFile, RealPath,
231+
/*expand_tilde=*/true);
232+
Hasher.update(RealPath);
233+
for (auto *A : Args) {
234+
if (A->getOption().matches(options::OPT_INPUT))
235+
continue;
236+
Hasher.update(A->getAsString(Args));
237+
}
238+
Hasher.final(Hash);
239+
CUID = llvm::utohexstr(Hash.low(), /*LowerCase=*/true);
240+
}
241+
}
242+
return CUID;
243+
}
200244
Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
201245
DiagnosticsEngine &Diags, std::string Title,
202246
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
@@ -875,6 +919,9 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
875919
C.addOffloadDeviceToolChain(HIPTC, OFK);
876920
}
877921

922+
if (IsCuda || IsHIP)
923+
CUIDOpts = CUIDOptions(C.getArgs(), *this);
924+
878925
//
879926
// OpenMP
880927
//
@@ -3161,19 +3208,15 @@ class OffloadingActionBuilder final {
31613208
/// Default GPU architecture if there's no one specified.
31623209
OffloadArch DefaultOffloadArch = OffloadArch::UNKNOWN;
31633210

3164-
/// Method to generate compilation unit ID specified by option
3165-
/// '-fuse-cuid='.
3166-
enum UseCUIDKind { CUID_Hash, CUID_Random, CUID_None, CUID_Invalid };
3167-
UseCUIDKind UseCUID = CUID_Hash;
3168-
3169-
/// Compilation unit ID specified by option '-cuid='.
3170-
StringRef FixedCUID;
3211+
/// Compilation unit ID specified by option '-fuse-cuid=' or'-cuid='.
3212+
const CUIDOptions &CUIDOpts;
31713213

31723214
public:
31733215
CudaActionBuilderBase(Compilation &C, DerivedArgList &Args,
31743216
const Driver::InputList &Inputs,
31753217
Action::OffloadKind OFKind)
3176-
: DeviceActionBuilder(C, Args, Inputs, OFKind) {
3218+
: DeviceActionBuilder(C, Args, Inputs, OFKind),
3219+
CUIDOpts(C.getDriver().getCUIDOpts()) {
31773220

31783221
CompileDeviceOnly = C.getDriver().offloadDeviceOnly();
31793222
Relocatable = Args.hasFlag(options::OPT_fgpu_rdc,
@@ -3204,28 +3247,8 @@ class OffloadingActionBuilder final {
32043247
// Set the flag to true, so that the builder acts on the current input.
32053248
IsActive = true;
32063249

3207-
std::string CUID = FixedCUID.str();
3208-
if (CUID.empty()) {
3209-
if (UseCUID == CUID_Random)
3210-
CUID = llvm::utohexstr(llvm::sys::Process::GetRandomNumber(),
3211-
/*LowerCase=*/true);
3212-
else if (UseCUID == CUID_Hash) {
3213-
llvm::MD5 Hasher;
3214-
llvm::MD5::MD5Result Hash;
3215-
SmallString<256> RealPath;
3216-
llvm::sys::fs::real_path(IA->getInputArg().getValue(), RealPath,
3217-
/*expand_tilde=*/true);
3218-
Hasher.update(RealPath);
3219-
for (auto *A : Args) {
3220-
if (A->getOption().matches(options::OPT_INPUT))
3221-
continue;
3222-
Hasher.update(A->getAsString(Args));
3223-
}
3224-
Hasher.final(Hash);
3225-
CUID = llvm::utohexstr(Hash.low(), /*LowerCase=*/true);
3226-
}
3227-
}
3228-
IA->setId(CUID);
3250+
if (CUIDOpts.isEnabled())
3251+
IA->setId(CUIDOpts.getCUID(IA->getInputArg().getValue(), Args));
32293252

32303253
if (CompileHostOnly)
32313254
return ABRT_Success;
@@ -3351,21 +3374,6 @@ class OffloadingActionBuilder final {
33513374
CompileHostOnly = C.getDriver().offloadHostOnly();
33523375
EmitLLVM = Args.getLastArg(options::OPT_emit_llvm);
33533376
EmitAsm = Args.getLastArg(options::OPT_S);
3354-
FixedCUID = Args.getLastArgValue(options::OPT_cuid_EQ);
3355-
if (Arg *A = Args.getLastArg(options::OPT_fuse_cuid_EQ)) {
3356-
StringRef UseCUIDStr = A->getValue();
3357-
UseCUID = llvm::StringSwitch<UseCUIDKind>(UseCUIDStr)
3358-
.Case("hash", CUID_Hash)
3359-
.Case("random", CUID_Random)
3360-
.Case("none", CUID_None)
3361-
.Default(CUID_Invalid);
3362-
if (UseCUID == CUID_Invalid) {
3363-
C.getDriver().Diag(diag::err_drv_invalid_value)
3364-
<< A->getAsString(Args) << UseCUIDStr;
3365-
C.setContainsError();
3366-
return true;
3367-
}
3368-
}
33693377

33703378
// --offload and --offload-arch options are mutually exclusive.
33713379
if (Args.hasArgNoClaim(options::OPT_offload_EQ) &&
@@ -4366,6 +4374,12 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43664374
// Build the pipeline for this file.
43674375
Action *Current = C.MakeAction<InputAction>(*InputArg, InputType);
43684376

4377+
std::string CUID;
4378+
if (CUIDOpts.isEnabled() && types::isSrcFile(InputType)) {
4379+
CUID = CUIDOpts.getCUID(InputArg->getValue(), Args);
4380+
cast<InputAction>(Current)->setId(CUID);
4381+
}
4382+
43694383
// Use the current host action in any of the offloading actions, if
43704384
// required.
43714385
if (!UseNewOffloadingDriver)
@@ -4429,7 +4443,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
44294443
// Try to build the offloading actions and add the result as a dependency
44304444
// to the host.
44314445
if (UseNewOffloadingDriver)
4432-
Current = BuildOffloadingActions(C, Args, I, Current);
4446+
Current = BuildOffloadingActions(C, Args, I, CUID, Current);
44334447
// Use the current host action in any of the offloading actions, if
44344448
// required.
44354449
else if (OffloadBuilder->addHostDependenceToDeviceActions(Current,
@@ -4766,7 +4780,7 @@ Driver::getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
47664780

47674781
Action *Driver::BuildOffloadingActions(Compilation &C,
47684782
llvm::opt::DerivedArgList &Args,
4769-
const InputTy &Input,
4783+
const InputTy &Input, StringRef CUID,
47704784
Action *HostAction) const {
47714785
// Don't build offloading actions if explicitly disabled or we do not have a
47724786
// valid source input and compile action to embed it in. If preprocessing only
@@ -4807,13 +4821,13 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
48074821
llvm::DenseSet<StringRef> Arches = getOffloadArchs(C, Args, Kind, TC);
48084822
SmallVector<StringRef, 0> Sorted(Arches.begin(), Arches.end());
48094823
llvm::sort(Sorted);
4810-
for (StringRef Arch : Sorted)
4824+
for (StringRef Arch : Sorted) {
48114825
TCAndArchs.push_back(std::make_pair(TC, Arch));
4826+
DeviceActions.push_back(
4827+
C.MakeAction<InputAction>(*InputArg, InputType, CUID));
4828+
}
48124829
}
48134830

4814-
for (unsigned I = 0, E = TCAndArchs.size(); I != E; ++I)
4815-
DeviceActions.push_back(C.MakeAction<InputAction>(*InputArg, InputType));
4816-
48174831
if (DeviceActions.empty())
48184832
return HostAction;
48194833

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17310,7 +17310,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1731017310
return nullptr;
1731117311
if (EnumUnderlying) {
1731217312
EnumDecl *ED = cast<EnumDecl>(New);
17313-
if (TypeSourceInfo *TI = EnumUnderlying.dyn_cast<TypeSourceInfo *>())
17313+
if (TypeSourceInfo *TI = dyn_cast<TypeSourceInfo *>(EnumUnderlying))
1731417314
ED->setIntegerTypeSourceInfo(TI);
1731517315
else
1731617316
ED->setIntegerType(QualType(cast<const Type *>(EnumUnderlying), 0));
@@ -17943,7 +17943,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1794317943

1794417944
if (EnumUnderlying) {
1794517945
EnumDecl *ED = cast<EnumDecl>(New);
17946-
if (TypeSourceInfo *TI = EnumUnderlying.dyn_cast<TypeSourceInfo*>())
17946+
if (TypeSourceInfo *TI = dyn_cast<TypeSourceInfo *>(EnumUnderlying))
1794717947
ED->setIntegerTypeSourceInfo(TI);
1794817948
else
1794917949
ED->setIntegerType(QualType(cast<const Type *>(EnumUnderlying), 0));

clang/lib/Tooling/Tooling.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,12 @@ std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
692692
StringRef Code, const std::vector<std::string> &Args, StringRef FileName,
693693
StringRef ToolName, std::shared_ptr<PCHContainerOperations> PCHContainerOps,
694694
ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles,
695-
DiagnosticConsumer *DiagConsumer) {
695+
DiagnosticConsumer *DiagConsumer,
696+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS) {
696697
std::vector<std::unique_ptr<ASTUnit>> ASTs;
697698
ASTBuilderAction Action(ASTs);
698699
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem(
699-
new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
700+
new llvm::vfs::OverlayFileSystem(std::move(BaseFS)));
700701
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
701702
new llvm::vfs::InMemoryFileSystem);
702703
OverlayFileSystem->pushOverlay(InMemoryFileSystem);

clang/test/CodeGenHLSL/Bool.hlsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
2+
3+
// CHECK-LABEL: define noundef i1 {{.*}}fn{{.*}}(i1 noundef %x)
4+
// CHECK: [[X:%.*]] = alloca i32, align 4
5+
// CHECK-NEXT: [[Y:%.*]] = zext i1 {{%.*}} to i32
6+
// CHECK-NEXT: store i32 [[Y]], ptr [[X]], align 4
7+
// CHECK-NEXT: [[Z:%.*]] = load i32, ptr [[X]], align 4
8+
// CHECK-NEXT: [[L:%.*]] = trunc i32 [[Z]] to i1
9+
// CHECK-NEXT: ret i1 [[L]]
10+
bool fn(bool x) {
11+
return x;
12+
}

0 commit comments

Comments
 (0)