Skip to content

Commit 2ff635e

Browse files
authored
merge main into amd-staging (llvm#4315)
2 parents dab5469 + f47c2d8 commit 2ff635e

File tree

138 files changed

+6965
-932
lines changed

Some content is hidden

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

138 files changed

+6965
-932
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
BasedOnStyle: LLVM
2+
LineEnding: LF

clang/.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
BasedOnStyle: LLVM
2+
LineEnding: LF

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ Bug Fixes to AST Handling
694694
legal representation. This is fixed because ElaboratedTypes don't exist anymore. (#GH43179) (#GH68670) (#GH92757)
695695
- Fix unrecognized html tag causing undesirable comment lexing (#GH152944)
696696
- Fix comment lexing of special command names (#GH152943)
697+
- Use `extern` as a hint to continue parsing when recovering from a malformed declaration.
697698

698699
Miscellaneous Bug Fixes
699700
^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/CIR/CodeGen/CIRGenOpenACCRecipe.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,32 @@ void OpenACCRecipeBuilderBase::createRecipeDestroySection(
400400

401401
mlir::acc::YieldOp::create(builder, locEnd);
402402
}
403+
void OpenACCRecipeBuilderBase::makeBoundsInit(
404+
mlir::Value alloca, mlir::Location loc, mlir::Block *block,
405+
const VarDecl *allocaDecl, QualType origType, bool isInitSection) {
406+
mlir::OpBuilder::InsertionGuard guardCase(builder);
407+
builder.setInsertionPointToEnd(block);
408+
CIRGenFunction::LexicalScope ls(cgf, loc, block);
409+
410+
CIRGenFunction::AutoVarEmission tempDeclEmission{*allocaDecl};
411+
tempDeclEmission.EmittedAsOffload = true;
412+
413+
// The init section is the only one of the handful that only has a single
414+
// argument for the 'type', so we have to drop 1 for init, and future calls
415+
// to this will need to drop 2.
416+
llvm::MutableArrayRef<mlir::BlockArgument> boundsRange =
417+
block->getArguments().drop_front(isInitSection ? 1 : 2);
418+
419+
mlir::Value subscriptedValue = alloca;
420+
for (mlir::BlockArgument boundArg : llvm::reverse(boundsRange))
421+
subscriptedValue = createBoundsLoop(subscriptedValue, boundArg, loc,
422+
/*inverse=*/false);
423+
424+
tempDeclEmission.setAllocatedAddress(
425+
Address{subscriptedValue, cgf.convertType(origType),
426+
cgf.getContext().getDeclAlign(allocaDecl)});
427+
cgf.emitAutoVarInit(tempDeclEmission);
428+
}
403429

404430
// TODO: OpenACC: When we get this implemented for the reduction/firstprivate,
405431
// this might end up re-merging with createRecipeInitCopy. For now, keep it
@@ -442,11 +468,16 @@ void OpenACCRecipeBuilderBase::createPrivateInitRecipe(
442468
cgf.emitAutoVarAlloca(*allocaDecl, builder.saveInsertionPoint());
443469
cgf.emitAutoVarInit(tempDeclEmission);
444470
} else {
445-
makeBoundsAlloca(block, exprRange, loc, "openacc.private.init", numBounds,
446-
boundTypes);
447-
448-
if (initExpr)
449-
cgf.cgm.errorNYI(exprRange, "private-init with bounds initialization");
471+
mlir::Value alloca = makeBoundsAlloca(
472+
block, exprRange, loc, "openacc.private.init", numBounds, boundTypes);
473+
474+
// If the initializer is trivial, there is nothing to do here, so save
475+
// ourselves some effort.
476+
if (initExpr && (!cgf.isTrivialInitializer(initExpr) ||
477+
cgf.getContext().getLangOpts().getTrivialAutoVarInit() !=
478+
LangOptions::TrivialAutoVarInitKind::Uninitialized))
479+
makeBoundsInit(alloca, loc, block, allocaDecl, origType,
480+
/*isInitSection=*/true);
450481
}
451482

452483
mlir::acc::YieldOp::create(builder, locEnd);

clang/lib/CIR/CodeGen/CIRGenOpenACCRecipe.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class OpenACCRecipeBuilderBase {
3535
size_t numBounds,
3636
llvm::ArrayRef<QualType> boundTypes);
3737

38+
void makeBoundsInit(mlir::Value alloca, mlir::Location loc,
39+
mlir::Block *block, const VarDecl *allocaDecl,
40+
QualType origType, bool isInitSection);
41+
3842
protected:
3943
CIRGen::CIRGenFunction &cgf;
4044
CIRGen::CIRGenBuilderTy &builder;

clang/lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,9 @@ void Parser::SkipMalformedDecl() {
20832083
return;
20842084
break;
20852085

2086+
case tok::kw_extern:
2087+
// 'extern' at the start of a line is almost certainly a good
2088+
// place to pick back up parsing
20862089
case tok::kw_namespace:
20872090
// 'namespace' at the start of a line is almost certainly a good
20882091
// place to pick back up parsing, except in an Objective-C

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13660,7 +13660,7 @@ bool Sema::CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename,
1366013660

1366113661
if (Cxx20Enumerator) {
1366213662
Diag(NameLoc, diag::warn_cxx17_compat_using_decl_non_member_enumerator)
13663-
<< SS.getRange();
13663+
<< SS.getScopeRep() << SS.getRange();
1366413664
return false;
1366513665
}
1366613666

clang/lib/Sema/SemaExpr.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20177,9 +20177,10 @@ static void DoMarkVarDeclReferenced(
2017720177
bool NeededForConstantEvaluation =
2017820178
isPotentiallyConstantEvaluatedContext(SemaRef) && UsableInConstantExpr;
2017920179

20180-
bool NeedDefinition = OdrUse == OdrUseContext::Used ||
20181-
NeededForConstantEvaluation ||
20182-
Var->getType()->isUndeducedType();
20180+
bool NeedDefinition =
20181+
OdrUse == OdrUseContext::Used || NeededForConstantEvaluation ||
20182+
(TSK != clang::TSK_Undeclared && !UsableInConstantExpr &&
20183+
Var->getType()->isUndeducedType());
2018320184

2018420185
assert(!isa<VarTemplatePartialSpecializationDecl>(Var) &&
2018520186
"Can't instantiate a partial template specialization.");

clang/lib/StaticAnalyzer/Core/RegionStore.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,14 +2658,20 @@ RegionStoreManager::bindArray(LimitedRegionBindingsConstRef B,
26582658
return bindAggregate(B, R, V);
26592659
}
26602660

2661-
// Handle lazy compound values.
2661+
// FIXME Single value constant should have been handled before this call to
2662+
// bindArray. This is only a hotfix to not crash.
2663+
if (Init.isConstant())
2664+
return bindAggregate(B, R, Init);
2665+
26622666
if (std::optional LCV = Init.getAs<nonloc::LazyCompoundVal>()) {
26632667
if (std::optional NewB = tryBindSmallArray(B, R, AT, *LCV))
26642668
return *NewB;
2665-
26662669
return bindAggregate(B, R, Init);
26672670
}
26682671

2672+
if (isa<nonloc::SymbolVal>(Init))
2673+
return bindAggregate(B, R, Init);
2674+
26692675
if (Init.isUnknown())
26702676
return bindAggregate(B, R, UnknownVal());
26712677

clang/test/Analysis/initializer.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,3 +610,51 @@ void top() {
610610
consume(parseMatchComponent());
611611
}
612612
} // namespace elementwise_copy_small_array_from_post_initializer_of_cctor
613+
614+
namespace gh147686 {
615+
// The problem reported in https://github.com/llvm/llvm-project/issues/147686
616+
// is sensitive to the initializer form: using parenthesis to initialize m_ptr
617+
// resulted in crashes when analyzing *m_ptr = '\0'; but using braces is fine.
618+
619+
struct A {
620+
A() : m_ptr(m_buf) { *m_ptr = '\0'; } // no-crash
621+
A(int overload) : m_ptr{m_buf} { *m_ptr = '\0'; }
622+
A(char src) : m_ptr(m_buf) { *m_ptr = src; } // no-crash
623+
A(char src, int overload) : m_ptr{m_buf} { *m_ptr = src; }
624+
char m_buf[64] = {0};
625+
char * m_ptr;
626+
};
627+
628+
void test1() {
629+
A a;
630+
clang_analyzer_eval(a.m_buf[0] == 0); // expected-warning{{TRUE}}
631+
// FIXME The next eval should result in TRUE.
632+
clang_analyzer_eval(*a.m_ptr == 0); // expected-warning{{UNKNOWN}}
633+
}
634+
635+
void test2() {
636+
A a(314);
637+
clang_analyzer_eval(a.m_buf[0] == 0); // expected-warning{{TRUE}}
638+
clang_analyzer_eval(*a.m_ptr == 0); // expected-warning{{TRUE}}
639+
}
640+
641+
void test3() {
642+
A a(0);
643+
clang_analyzer_eval(a.m_buf[0] == 0); // expected-warning{{TRUE}}
644+
clang_analyzer_eval(*a.m_ptr == 0); // expected-warning{{TRUE}}
645+
}
646+
647+
void test3Bis(char arg) {
648+
A a(arg);
649+
// FIXME This test should behave like test3.
650+
clang_analyzer_eval(a.m_buf[0] == arg); // expected-warning{{FALSE}} // expected-warning{{TRUE}}
651+
clang_analyzer_eval(*a.m_ptr == arg); // expected-warning{{UNKNOWN}}
652+
}
653+
654+
void test4(char arg) {
655+
A a(arg, 314);
656+
clang_analyzer_eval(a.m_buf[0] == arg); // expected-warning{{TRUE}}
657+
clang_analyzer_eval(*a.m_ptr == arg); // expected-warning{{TRUE}}
658+
}
659+
660+
} // namespace gh147686

0 commit comments

Comments
 (0)