Skip to content

Commit bc89c96

Browse files
authored
Merge branch 'main' into pr/mutablearrayref
2 parents 3f9289a + 7a77127 commit bc89c96

File tree

214 files changed

+8513
-1926
lines changed

Some content is hidden

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

214 files changed

+8513
-1926
lines changed

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,8 @@ It should be used via an editor plugin rather than invoked directly. For more in
775775
clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment variable.
776776
)";
777777
llvm::cl::HideUnrelatedOptions(ClangdCategories);
778-
llvm::cl::ParseCommandLineOptions(argc, argv, Overview,
779-
/*Errs=*/nullptr, FlagsEnvVar);
778+
llvm::cl::ParseCommandLineOptions(argc, argv, Overview, /*Errs=*/nullptr,
779+
/*VFS=*/nullptr, FlagsEnvVar);
780780
if (Test) {
781781
if (!Sync.getNumOccurrences())
782782
Sync = true;

clang/include/clang/AST/Decl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4521,6 +4521,23 @@ class RecordDecl : public TagDecl {
45214521
return field_begin() == field_end();
45224522
}
45234523

4524+
/// noload_fields - Iterate over the fields stored in this record
4525+
/// that are currently loaded; don't attempt to retrieve anything
4526+
/// from an external source.
4527+
field_range noload_fields() const {
4528+
return field_range(noload_field_begin(), noload_field_end());
4529+
}
4530+
4531+
field_iterator noload_field_begin() const;
4532+
field_iterator noload_field_end() const {
4533+
return field_iterator(decl_iterator());
4534+
}
4535+
4536+
// Whether there are any fields (non-static data members) in this record.
4537+
bool noload_field_empty() const {
4538+
return noload_field_begin() == noload_field_end();
4539+
}
4540+
45244541
/// Note that the definition of this type is now complete.
45254542
virtual void completeDefinition();
45264543

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13223,6 +13223,8 @@ def note_hlsl_resource_range_here: Note<"overlapping resource range here">;
1322313223

1322413224
def err_hlsl_incomplete_resource_array_in_function_param: Error<
1322513225
"incomplete resource array in a function parameter">;
13226+
def err_hlsl_assign_to_global_resource: Error<
13227+
"assignment to global resource variable %0 is not allowed">;
1322613228

1322713229
// Layout randomization diagnostics.
1322813230
def err_non_designated_init_used : Error<

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class SemaHLSL : public SemaBase {
133133
bool isSemanticValid(FunctionDecl *FD, DeclaratorDecl *D);
134134
void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param,
135135
const HLSLAnnotationAttr *AnnotationAttr);
136+
bool CheckResourceBinOp(BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr,
137+
SourceLocation Loc);
136138
void DiagnoseAttrStageMismatch(
137139
const Attr *A, llvm::Triple::EnvironmentType Stage,
138140
std::initializer_list<llvm::Triple::EnvironmentType> AllowedStages);

clang/lib/AST/Decl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5161,6 +5161,10 @@ RecordDecl::field_iterator RecordDecl::field_begin() const {
51615161
return field_iterator(decl_iterator(FirstDecl));
51625162
}
51635163

5164+
RecordDecl::field_iterator RecordDecl::noload_field_begin() const {
5165+
return field_iterator(decl_iterator(getDefinitionOrSelf()->FirstDecl));
5166+
}
5167+
51645168
/// completeDefinition - Notes that the definition of this type is now
51655169
/// complete.
51665170
void RecordDecl::completeDefinition() {

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ getInstrProfOptions(const CodeGenOptions &CodeGenOpts,
562562
return Options;
563563
}
564564

565-
static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
565+
static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts,
566+
vfs::FileSystem &VFS) {
566567
SmallVector<const char *, 16> BackendArgs;
567568
BackendArgs.push_back("clang"); // Fake program name.
568569
if (!CodeGenOpts.DebugPass.empty()) {
@@ -582,8 +583,9 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
582583
// FIXME: The command line parser below is not thread-safe and shares a global
583584
// state, so this call might crash or overwrite the options of another Clang
584585
// instance in the same process.
585-
llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
586-
BackendArgs.data());
586+
llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1, BackendArgs.data(),
587+
/*Overview=*/"", /*Errs=*/nullptr,
588+
/*VFS=*/&VFS);
587589
}
588590

589591
void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
@@ -1260,7 +1262,7 @@ void EmitAssemblyHelper::RunCodegenPipeline(
12601262
void EmitAssemblyHelper::emitAssembly(BackendAction Action,
12611263
std::unique_ptr<raw_pwrite_stream> OS,
12621264
BackendConsumer *BC) {
1263-
setCommandLineOpts(CodeGenOpts);
1265+
setCommandLineOpts(CodeGenOpts, CI.getVirtualFileSystem());
12641266

12651267
bool RequiresCodeGen = actionRequiresCodeGen(Action);
12661268
CreateTargetMachine(RequiresCodeGen);
@@ -1295,7 +1297,7 @@ runThinLTOBackend(CompilerInstance &CI, ModuleSummaryIndex *CombinedIndex,
12951297
ModuleToDefinedGVSummaries;
12961298
CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
12971299

1298-
setCommandLineOpts(CGOpts);
1300+
setCommandLineOpts(CGOpts, CI.getVirtualFileSystem());
12991301

13001302
// We can simply import the values mentioned in the combined index, since
13011303
// we should only invoke this using the individual indexes written out

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
188188
return createPPC32TargetCodeGenInfo(CGM, IsSoftFloat);
189189
}
190190
case llvm::Triple::ppcle: {
191-
bool IsSoftFloat = CodeGenOpts.FloatABI == "soft";
191+
bool IsSoftFloat =
192+
CodeGenOpts.FloatABI == "soft" || Target.hasFeature("spe");
192193
return createPPC32TargetCodeGenInfo(CGM, IsSoftFloat);
193194
}
194195
case llvm::Triple::ppc64:

clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
244244
for (unsigned i = 0; i != NumArgs; ++i)
245245
Args[i + 1] = Clang->getFrontendOpts().LLVMArgs[i].c_str();
246246
Args[NumArgs + 1] = nullptr;
247-
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
247+
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get(), /*Overview=*/"",
248+
/*Errs=*/nullptr,
249+
/*VFS=*/&Clang->getVirtualFileSystem());
248250
}
249251

250252
#if CLANG_ENABLE_STATIC_ANALYZER

clang/lib/Sema/SemaExpr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15711,6 +15711,12 @@ ExprResult Sema::BuildBinOp(Scope *S, SourceLocation OpLoc,
1571115711
RHSExpr = resolvedRHS.get();
1571215712
}
1571315713

15714+
if (getLangOpts().HLSL && (LHSExpr->getType()->isHLSLResourceRecord() ||
15715+
LHSExpr->getType()->isHLSLResourceRecordArray())) {
15716+
if (!HLSL().CheckResourceBinOp(Opc, LHSExpr, RHSExpr, OpLoc))
15717+
return ExprError();
15718+
}
15719+
1571415720
if (getLangOpts().CPlusPlus) {
1571515721
// Otherwise, build an overloaded op if either expression is type-dependent
1571615722
// or has an overloadable type.

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,6 +3956,34 @@ bool SemaHLSL::ActOnUninitializedVarDecl(VarDecl *VD) {
39563956
return false;
39573957
}
39583958

3959+
// Return true if everything is ok; returns false if there was an error.
3960+
bool SemaHLSL::CheckResourceBinOp(BinaryOperatorKind Opc, Expr *LHSExpr,
3961+
Expr *RHSExpr, SourceLocation Loc) {
3962+
assert((LHSExpr->getType()->isHLSLResourceRecord() ||
3963+
LHSExpr->getType()->isHLSLResourceRecordArray()) &&
3964+
"expected LHS to be a resource record or array of resource records");
3965+
if (Opc != BO_Assign)
3966+
return true;
3967+
3968+
// If LHS is an array subscript, get the underlying declaration.
3969+
Expr *E = LHSExpr;
3970+
while (auto *ASE = dyn_cast<ArraySubscriptExpr>(E))
3971+
E = ASE->getBase()->IgnoreParenImpCasts();
3972+
3973+
// Report error if LHS is a resource declared at a global scope.
3974+
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParens())) {
3975+
if (VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
3976+
if (VD->hasGlobalStorage()) {
3977+
// assignment to global resource is not allowed
3978+
SemaRef.Diag(Loc, diag::err_hlsl_assign_to_global_resource) << VD;
3979+
SemaRef.Diag(VD->getLocation(), diag::note_var_declared_here) << VD;
3980+
return false;
3981+
}
3982+
}
3983+
}
3984+
return true;
3985+
}
3986+
39593987
// Walks though the global variable declaration, collects all resource binding
39603988
// requirements and adds them to Bindings
39613989
void SemaHLSL::collectResourceBindingsOnVarDecl(VarDecl *VD) {

0 commit comments

Comments
 (0)