Skip to content

Commit 9537656

Browse files
committed
Merge branch 'main' into riscv_remove_zext_from_bool_for_atomic_load
2 parents 9c794c5 + a9d93ec commit 9537656

File tree

227 files changed

+5431
-2130
lines changed

Some content is hidden

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

227 files changed

+5431
-2130
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ class RootSignatureParser {
7171
// expected, or, there is a lexing error
7272

7373
/// Root Element parse methods:
74-
bool parseDescriptorTable();
75-
bool parseDescriptorTableClause();
74+
std::optional<llvm::hlsl::rootsig::DescriptorTable> parseDescriptorTable();
75+
std::optional<llvm::hlsl::rootsig::DescriptorTableClause>
76+
parseDescriptorTableClause();
7677

7778
/// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
7879
/// order and only exactly once. `ParsedClauseParams` denotes the current

clang/lib/AST/ByteCode/Interp.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,19 @@ inline bool CmpHelper<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
10071007
return false;
10081008
}
10091009

1010+
// Diagnose comparisons between fields with different access specifiers.
1011+
if (std::optional<std::pair<Pointer, Pointer>> Split =
1012+
Pointer::computeSplitPoint(LHS, RHS)) {
1013+
const FieldDecl *LF = Split->first.getField();
1014+
const FieldDecl *RF = Split->second.getField();
1015+
if (LF && RF && !LF->getParent()->isUnion() &&
1016+
LF->getAccess() != RF->getAccess()) {
1017+
S.CCEDiag(S.Current->getSource(OpPC),
1018+
diag::note_constexpr_pointer_comparison_differing_access)
1019+
<< LF << LF->getAccess() << RF << RF->getAccess() << LF->getParent();
1020+
}
1021+
}
1022+
10101023
unsigned VL = LHS.getByteOffset();
10111024
unsigned VR = RHS.getByteOffset();
10121025
S.Stk.push<BoolT>(BoolT::from(Fn(Compare(VL, VR))));

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,48 @@ bool Pointer::pointsToLiteral() const {
571571
return E && !isa<MaterializeTemporaryExpr, StringLiteral>(E);
572572
}
573573

574+
std::optional<std::pair<Pointer, Pointer>>
575+
Pointer::computeSplitPoint(const Pointer &A, const Pointer &B) {
576+
if (!A.isBlockPointer() || !B.isBlockPointer())
577+
return std::nullopt;
578+
579+
if (A.asBlockPointer().Pointee != B.asBlockPointer().Pointee)
580+
return std::nullopt;
581+
if (A.isRoot() && B.isRoot())
582+
return std::nullopt;
583+
584+
if (A == B)
585+
return std::make_pair(A, B);
586+
587+
auto getBase = [](const Pointer &P) -> Pointer {
588+
if (P.isArrayElement())
589+
return P.expand().getArray();
590+
return P.getBase();
591+
};
592+
593+
Pointer IterA = A;
594+
Pointer IterB = B;
595+
Pointer CurA = IterA;
596+
Pointer CurB = IterB;
597+
for (;;) {
598+
if (IterA.asBlockPointer().Base > IterB.asBlockPointer().Base) {
599+
CurA = IterA;
600+
IterA = getBase(IterA);
601+
} else {
602+
CurB = IterB;
603+
IterB = getBase(IterB);
604+
}
605+
606+
if (IterA == IterB)
607+
return std::make_pair(CurA, CurB);
608+
609+
if (IterA.isRoot() && IterB.isRoot())
610+
return std::nullopt;
611+
}
612+
613+
llvm_unreachable("The loop above should've returned.");
614+
}
615+
574616
std::optional<APValue> Pointer::toRValue(const Context &Ctx,
575617
QualType ResultType) const {
576618
const ASTContext &ASTCtx = Ctx.getASTContext();

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,11 @@ class Pointer {
492492
return ElemDesc ? ElemDesc->ElemRecord : nullptr;
493493
}
494494
/// Returns the field information.
495-
const FieldDecl *getField() const { return getFieldDesc()->asFieldDecl(); }
495+
const FieldDecl *getField() const {
496+
if (const Descriptor *FD = getFieldDesc())
497+
return FD->asFieldDecl();
498+
return nullptr;
499+
}
496500

497501
/// Checks if the storage is extern.
498502
bool isExtern() const {
@@ -724,6 +728,9 @@ class Pointer {
724728
/// Checks if both given pointers point to the same block.
725729
static bool pointToSameBlock(const Pointer &A, const Pointer &B);
726730

731+
static std::optional<std::pair<Pointer, Pointer>>
732+
computeSplitPoint(const Pointer &A, const Pointer &B);
733+
727734
/// Whether this points to a block that's been created for a "literal lvalue",
728735
/// i.e. a non-MaterializeTemporaryExpr Expr.
729736
bool pointsToLiteral() const;

clang/lib/AST/ExprConstant.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9202,7 +9202,10 @@ bool LValueExprEvaluator::VisitExtVectorElementExpr(
92029202

92039203
if (Success) {
92049204
Result.setFrom(Info.Ctx, Val);
9205-
const auto *VT = E->getBase()->getType()->castAs<VectorType>();
9205+
QualType BaseType = E->getBase()->getType();
9206+
if (E->isArrow())
9207+
BaseType = BaseType->getPointeeType();
9208+
const auto *VT = BaseType->castAs<VectorType>();
92069209
HandleLValueVectorElement(Info, E, Result, VT->getElementType(),
92079210
VT->getNumElements(), Indices[0]);
92089211
}

clang/lib/Basic/Targets/SPIR.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ static const unsigned SPIRDefIsPrivMap[] = {
5858
// Used by both the SPIR and SPIR-V targets.
5959
static const unsigned SPIRDefIsGenMap[] = {
6060
4, // Default
61-
// OpenCL address space values for this map are dummy and they can't be used
62-
0, // opencl_global
61+
// Some OpenCL address space values for this map are dummy and they can't be
62+
// used
63+
1, // opencl_global
6364
0, // opencl_local
6465
0, // opencl_constant
6566
0, // opencl_private

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,22 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
961961
Debugify.setOrigDIVerifyBugsReportFilePath(
962962
CodeGenOpts.DIBugsReportFilePath);
963963
Debugify.registerCallbacks(PIC, MAM);
964+
965+
#if ENABLE_DEBUGLOC_COVERAGE_TRACKING
966+
// If we're using debug location coverage tracking, mark all the
967+
// instructions coming out of the frontend without a DebugLoc as being
968+
// compiler-generated, to prevent both those instructions and new
969+
// instructions that inherit their location from being treated as
970+
// incorrectly empty locations.
971+
for (Function &F : *TheModule) {
972+
if (!F.getSubprogram())
973+
continue;
974+
for (BasicBlock &BB : F)
975+
for (Instruction &I : BB)
976+
if (!I.getDebugLoc())
977+
I.setDebugLoc(DebugLoc::getCompilerGenerated());
978+
}
979+
#endif
964980
}
965981
// Attempt to load pass plugins and register their callbacks with PB.
966982
for (auto &PluginFN : CodeGenOpts.PassPlugins) {

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,11 +1240,15 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
12401240
Instance.createSourceManager(Instance.getFileManager());
12411241
SourceManager &SourceMgr = Instance.getSourceManager();
12421242

1243-
// Note that this module is part of the module build stack, so that we
1244-
// can detect cycles in the module graph.
1245-
SourceMgr.setModuleBuildStack(getSourceManager().getModuleBuildStack());
1246-
SourceMgr.pushModuleBuildStack(ModuleName,
1247-
FullSourceLoc(ImportLoc, getSourceManager()));
1243+
if (ThreadSafeConfig) {
1244+
// Detecting cycles in the module graph is responsibility of the client.
1245+
} else {
1246+
// Note that this module is part of the module build stack, so that we
1247+
// can detect cycles in the module graph.
1248+
SourceMgr.setModuleBuildStack(getSourceManager().getModuleBuildStack());
1249+
SourceMgr.pushModuleBuildStack(
1250+
ModuleName, FullSourceLoc(ImportLoc, getSourceManager()));
1251+
}
12481252

12491253
// Make a copy for the new instance.
12501254
Instance.FailedModules = FailedModules;

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,14 @@ RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements,
2626

2727
bool RootSignatureParser::parse() {
2828
// Iterate as many RootElements as possible
29-
while (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
30-
// Dispatch onto parser method.
31-
// We guard against the unreachable here as we just ensured that CurToken
32-
// will be one of the kinds in the while condition
33-
switch (CurToken.TokKind) {
34-
case TokenKind::kw_DescriptorTable:
35-
if (parseDescriptorTable())
29+
do {
30+
if (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
31+
auto Table = parseDescriptorTable();
32+
if (!Table.has_value())
3633
return true;
37-
break;
38-
default:
39-
llvm_unreachable("Switch for consumed token was not provided");
34+
Elements.push_back(*Table);
4035
}
41-
42-
if (!tryConsumeExpectedToken(TokenKind::pu_comma))
43-
break;
44-
}
36+
} while (tryConsumeExpectedToken(TokenKind::pu_comma));
4537

4638
if (consumeExpectedToken(TokenKind::end_of_stream,
4739
diag::err_hlsl_unexpected_end_of_params,
@@ -51,38 +43,38 @@ bool RootSignatureParser::parse() {
5143
return false;
5244
}
5345

54-
bool RootSignatureParser::parseDescriptorTable() {
46+
std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
5547
assert(CurToken.TokKind == TokenKind::kw_DescriptorTable &&
5648
"Expects to only be invoked starting at given keyword");
5749

58-
DescriptorTable Table;
59-
6050
if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
6151
CurToken.TokKind))
62-
return true;
63-
64-
// Iterate as many Clauses as possible
65-
while (tryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
66-
TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
67-
if (parseDescriptorTableClause())
68-
return true;
52+
return std::nullopt;
6953

70-
Table.NumClauses++;
54+
DescriptorTable Table;
7155

72-
if (!tryConsumeExpectedToken(TokenKind::pu_comma))
73-
break;
74-
}
56+
// Iterate as many Clauses as possible
57+
do {
58+
if (tryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
59+
TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
60+
auto Clause = parseDescriptorTableClause();
61+
if (!Clause.has_value())
62+
return std::nullopt;
63+
Elements.push_back(*Clause);
64+
Table.NumClauses++;
65+
}
66+
} while (tryConsumeExpectedToken(TokenKind::pu_comma));
7567

7668
if (consumeExpectedToken(TokenKind::pu_r_paren,
7769
diag::err_hlsl_unexpected_end_of_params,
7870
/*param of=*/TokenKind::kw_DescriptorTable))
79-
return true;
71+
return std::nullopt;
8072

81-
Elements.push_back(Table);
82-
return false;
73+
return Table;
8374
}
8475

85-
bool RootSignatureParser::parseDescriptorTableClause() {
76+
std::optional<DescriptorTableClause>
77+
RootSignatureParser::parseDescriptorTableClause() {
8678
assert((CurToken.TokKind == TokenKind::kw_CBV ||
8779
CurToken.TokKind == TokenKind::kw_SRV ||
8880
CurToken.TokKind == TokenKind::kw_UAV ||
@@ -93,7 +85,7 @@ bool RootSignatureParser::parseDescriptorTableClause() {
9385

9486
if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
9587
CurToken.TokKind))
96-
return true;
88+
return std::nullopt;
9789

9890
DescriptorTableClause Clause;
9991
TokenKind ExpectedReg;
@@ -120,13 +112,13 @@ bool RootSignatureParser::parseDescriptorTableClause() {
120112

121113
auto Params = parseDescriptorTableClauseParams(ExpectedReg);
122114
if (!Params.has_value())
123-
return true;
115+
return std::nullopt;
124116

125117
// Check mandatory parameters were provided
126118
if (!Params->Reg.has_value()) {
127119
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param)
128120
<< ExpectedReg;
129-
return true;
121+
return std::nullopt;
130122
}
131123

132124
Clause.Reg = Params->Reg.value();
@@ -138,10 +130,9 @@ bool RootSignatureParser::parseDescriptorTableClause() {
138130
if (consumeExpectedToken(TokenKind::pu_r_paren,
139131
diag::err_hlsl_unexpected_end_of_params,
140132
/*param of=*/ParamKind))
141-
return true;
133+
return std::nullopt;
142134

143-
Elements.push_back(Clause);
144-
return false;
135+
return Clause;
145136
}
146137

147138
std::optional<RootSignatureParser::ParsedClauseParams>

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,32 +2085,31 @@ bool SemaOpenACC::CheckDeclareClause(SemaOpenACC::OpenACCParsedClause &Clause,
20852085
}
20862086
} else {
20872087
const auto *DRE = cast<DeclRefExpr>(VarExpr);
2088-
const VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl());
2089-
if (Var)
2088+
if (const auto *Var = dyn_cast<VarDecl>(DRE->getDecl())) {
20902089
CurDecl = Var->getCanonicalDecl();
20912090

2092-
// OpenACC3.3 2.13:
2093-
// A 'declare' directive must be in the same scope as the declaration of
2094-
// any var that appears in the clauses of the directive or any scope
2095-
// within a C/C++ function.
2096-
// We can't really check 'scope' here, so we check declaration context,
2097-
// which is a reasonable approximation, but misses scopes inside of
2098-
// functions.
2099-
if (removeLinkageSpecDC(Var->getCanonicalDecl()
2100-
->getLexicalDeclContext()
2101-
->getPrimaryContext()) != DC) {
2102-
Diag(VarExpr->getBeginLoc(), diag::err_acc_declare_same_scope)
2103-
<< Clause.getClauseKind();
2104-
continue;
2105-
}
2106-
// OpenACC3.3 2.13:
2107-
// C and C++ extern variables may only appear in 'create',
2108-
// 'copyin', 'deviceptr', 'device_resident', or 'link' clauses on a
2109-
// 'declare' directive.
2110-
if (!IsSpecialClause && Var && Var->hasExternalStorage()) {
2111-
Diag(VarExpr->getBeginLoc(), diag::err_acc_declare_extern)
2112-
<< Clause.getClauseKind();
2113-
continue;
2091+
// OpenACC3.3 2.13:
2092+
// A 'declare' directive must be in the same scope as the declaration of
2093+
// any var that appears in the clauses of the directive or any scope
2094+
// within a C/C++ function.
2095+
// We can't really check 'scope' here, so we check declaration context,
2096+
// which is a reasonable approximation, but misses scopes inside of
2097+
// functions.
2098+
if (removeLinkageSpecDC(
2099+
Var->getLexicalDeclContext()->getPrimaryContext()) != DC) {
2100+
Diag(VarExpr->getBeginLoc(), diag::err_acc_declare_same_scope)
2101+
<< Clause.getClauseKind();
2102+
continue;
2103+
}
2104+
// OpenACC3.3 2.13:
2105+
// C and C++ extern variables may only appear in 'create',
2106+
// 'copyin', 'deviceptr', 'device_resident', or 'link' clauses on a
2107+
// 'declare' directive.
2108+
if (!IsSpecialClause && Var->hasExternalStorage()) {
2109+
Diag(VarExpr->getBeginLoc(), diag::err_acc_declare_extern)
2110+
<< Clause.getClauseKind();
2111+
continue;
2112+
}
21142113
}
21152114

21162115
// OpenACC3.3 2.13:

0 commit comments

Comments
 (0)