Skip to content

Commit 24cddcc

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: I05d9aa4950fdaae931ccda281de93a565b85a6c1
2 parents f102fb0 + 68210c7 commit 24cddcc

File tree

30 files changed

+511
-105
lines changed

30 files changed

+511
-105
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,13 @@ bool Compiler<Emitter>::VisitUnaryExprOrTypeTraitExpr(
21282128
return this->emitConst(1, E);
21292129
}
21302130

2131+
if (Kind == UETT_OpenMPRequiredSimdAlign) {
2132+
assert(E->isArgumentType());
2133+
unsigned Bits = ASTCtx.getOpenMPDefaultSimdAlign(E->getArgumentType());
2134+
2135+
return this->emitConst(ASTCtx.toCharUnitsFromBits(Bits).getQuantity(), E);
2136+
}
2137+
21312138
return false;
21322139
}
21332140

clang/lib/AST/ByteCode/InterpBlock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ bool Block::hasPointer(const Pointer *P) const {
100100
#endif
101101

102102
DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
103-
: Root(Root),
104-
B(~0u, Blk->Desc, Blk->IsStatic, Blk->IsExtern, /*isDead=*/true) {
103+
: Root(Root), B(~0u, Blk->Desc, Blk->IsStatic, Blk->IsExtern, Blk->IsWeak,
104+
/*isDead=*/true) {
105105
// Add the block to the chain of dead blocks.
106106
if (Root)
107107
Root->Prev = this;

clang/lib/AST/ByteCode/InterpBlock.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@ class Block final {
5050
public:
5151
/// Creates a new block.
5252
Block(unsigned EvalID, const std::optional<unsigned> &DeclID,
53-
const Descriptor *Desc, bool IsStatic = false, bool IsExtern = false)
53+
const Descriptor *Desc, bool IsStatic = false, bool IsExtern = false,
54+
bool IsWeak = false)
5455
: EvalID(EvalID), DeclID(DeclID), IsStatic(IsStatic), IsExtern(IsExtern),
55-
IsDynamic(false), Desc(Desc) {
56+
IsDynamic(false), IsWeak(IsWeak), Desc(Desc) {
5657
assert(Desc);
5758
}
5859

5960
Block(unsigned EvalID, const Descriptor *Desc, bool IsStatic = false,
60-
bool IsExtern = false)
61+
bool IsExtern = false, bool IsWeak = false)
6162
: EvalID(EvalID), DeclID((unsigned)-1), IsStatic(IsStatic),
62-
IsExtern(IsExtern), IsDynamic(false), Desc(Desc) {
63+
IsExtern(IsExtern), IsDynamic(false), IsWeak(IsWeak), Desc(Desc) {
6364
assert(Desc);
6465
}
6566

@@ -73,6 +74,7 @@ class Block final {
7374
bool isStatic() const { return IsStatic; }
7475
/// Checks if the block is temporary.
7576
bool isTemporary() const { return Desc->IsTemporary; }
77+
bool isWeak() const { return IsWeak; }
7678
bool isDynamic() const { return IsDynamic; }
7779
/// Returns the size of the block.
7880
unsigned getSize() const { return Desc->getAllocSize(); }
@@ -135,9 +137,9 @@ class Block final {
135137
friend class DynamicAllocator;
136138

137139
Block(unsigned EvalID, const Descriptor *Desc, bool IsExtern, bool IsStatic,
138-
bool IsDead)
140+
bool IsWeak, bool IsDead)
139141
: EvalID(EvalID), IsStatic(IsStatic), IsExtern(IsExtern), IsDead(true),
140-
IsDynamic(false), Desc(Desc) {
142+
IsDynamic(false), IsWeak(IsWeak), Desc(Desc) {
141143
assert(Desc);
142144
}
143145

@@ -170,6 +172,7 @@ class Block final {
170172
/// Flag indicating if this block has been allocated via dynamic
171173
/// memory allocation (e.g. malloc).
172174
bool IsDynamic = false;
175+
bool IsWeak = false;
173176
/// Pointer to the stack slot descriptor.
174177
const Descriptor *Desc;
175178
};

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,7 @@ class Pointer {
524524
return false;
525525

526526
assert(isBlockPointer());
527-
if (const ValueDecl *VD = getDeclDesc()->asValueDecl())
528-
return VD->isWeak();
529-
return false;
527+
return asBlockPointer().Pointee->isWeak();
530528
}
531529
/// Checks if an object was initialized.
532530
bool isInitialized() const;

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@ std::optional<unsigned> Program::getOrCreateDummy(const DeclTy &D) {
152152
return It->second;
153153

154154
QualType QT;
155+
bool IsWeak = false;
155156
if (const auto *E = D.dyn_cast<const Expr *>()) {
156157
QT = E->getType();
157158
} else {
158159
const ValueDecl *VD = cast<ValueDecl>(D.get<const Decl *>());
160+
IsWeak = VD->isWeak();
159161
QT = VD->getType();
160162
if (const auto *RT = QT->getAs<ReferenceType>())
161163
QT = RT->getPointeeType();
@@ -182,7 +184,7 @@ std::optional<unsigned> Program::getOrCreateDummy(const DeclTy &D) {
182184

183185
auto *G = new (Allocator, Desc->getAllocSize())
184186
Global(Ctx.getEvalID(), getCurrentDecl(), Desc, /*IsStatic=*/true,
185-
/*IsExtern=*/false);
187+
/*IsExtern=*/false, IsWeak);
186188
G->block()->invokeCtor();
187189

188190
Globals.push_back(G);
@@ -193,6 +195,7 @@ std::optional<unsigned> Program::getOrCreateDummy(const DeclTy &D) {
193195
std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
194196
const Expr *Init) {
195197
bool IsStatic, IsExtern;
198+
bool IsWeak = VD->isWeak();
196199
if (const auto *Var = dyn_cast<VarDecl>(VD)) {
197200
IsStatic = Context::shouldBeGloballyIndexed(VD);
198201
IsExtern = Var->hasExternalStorage();
@@ -207,7 +210,8 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
207210

208211
// Register all previous declarations as well. For extern blocks, just replace
209212
// the index with the new variable.
210-
if (auto Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern, Init)) {
213+
if (auto Idx =
214+
createGlobal(VD, VD->getType(), IsStatic, IsExtern, IsWeak, Init)) {
211215
for (const Decl *P = VD; P; P = P->getPreviousDecl()) {
212216
if (P != VD) {
213217
unsigned PIdx = GlobalIndices[P];
@@ -225,7 +229,7 @@ std::optional<unsigned> Program::createGlobal(const Expr *E) {
225229
if (auto Idx = getGlobal(E))
226230
return Idx;
227231
if (auto Idx = createGlobal(E, E->getType(), /*isStatic=*/true,
228-
/*isExtern=*/false)) {
232+
/*isExtern=*/false, /*IsWeak=*/false)) {
229233
GlobalIndices[E] = *Idx;
230234
return *Idx;
231235
}
@@ -234,7 +238,7 @@ std::optional<unsigned> Program::createGlobal(const Expr *E) {
234238

235239
std::optional<unsigned> Program::createGlobal(const DeclTy &D, QualType Ty,
236240
bool IsStatic, bool IsExtern,
237-
const Expr *Init) {
241+
bool IsWeak, const Expr *Init) {
238242
// Create a descriptor for the global.
239243
Descriptor *Desc;
240244
const bool IsConst = Ty.isConstQualified();
@@ -251,8 +255,8 @@ std::optional<unsigned> Program::createGlobal(const DeclTy &D, QualType Ty,
251255
// Allocate a block for storage.
252256
unsigned I = Globals.size();
253257

254-
auto *G = new (Allocator, Desc->getAllocSize())
255-
Global(Ctx.getEvalID(), getCurrentDecl(), Desc, IsStatic, IsExtern);
258+
auto *G = new (Allocator, Desc->getAllocSize()) Global(
259+
Ctx.getEvalID(), getCurrentDecl(), Desc, IsStatic, IsExtern, IsWeak);
256260
G->block()->invokeCtor();
257261

258262
// Initialize InlineDescriptor fields.

clang/lib/AST/ByteCode/Program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class Program final {
152152

153153
std::optional<unsigned> createGlobal(const DeclTy &D, QualType Ty,
154154
bool IsStatic, bool IsExtern,
155-
const Expr *Init = nullptr);
155+
bool IsWeak, const Expr *Init = nullptr);
156156

157157
/// Reference to the VM context.
158158
Context &Ctx;

clang/lib/Driver/Driver.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,9 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
987987
} else
988988
TC = &getToolChain(C.getInputArgs(), TT);
989989
C.addOffloadDeviceToolChain(TC, Action::OFK_OpenMP);
990-
if (DerivedArchs.contains(TT.getTriple()))
991-
KnownArchs[TC] = DerivedArchs[TT.getTriple()];
990+
auto It = DerivedArchs.find(TT.getTriple());
991+
if (It != DerivedArchs.end())
992+
KnownArchs[TC] = It->second;
992993
}
993994
}
994995
} else if (C.getInputArgs().hasArg(options::OPT_fopenmp_targets_EQ)) {
@@ -3992,11 +3993,10 @@ class OffloadingActionBuilder final {
39923993
void recordHostAction(Action *HostAction, const Arg *InputArg) {
39933994
assert(HostAction && "Invalid host action");
39943995
assert(InputArg && "Invalid input argument");
3995-
auto Loc = HostActionToInputArgMap.find(HostAction);
3996-
if (Loc == HostActionToInputArgMap.end())
3997-
HostActionToInputArgMap[HostAction] = InputArg;
3998-
assert(HostActionToInputArgMap[HostAction] == InputArg &&
3996+
auto Loc = HostActionToInputArgMap.try_emplace(HostAction, InputArg).first;
3997+
assert(Loc->second == InputArg &&
39993998
"host action mapped to multiple input arguments");
3999+
(void)Loc;
40004000
}
40014001

40024002
/// Generate an action that adds device dependences (if any) to a host action.
@@ -5848,8 +5848,9 @@ InputInfoList Driver::BuildJobsForActionNoCache(
58485848
std::pair<const Action *, std::string> ActionTC = {
58495849
OA->getHostDependence(),
58505850
GetTriplePlusArchString(TC, BoundArch, TargetDeviceOffloadKind)};
5851-
if (CachedResults.find(ActionTC) != CachedResults.end()) {
5852-
InputInfoList Inputs = CachedResults[ActionTC];
5851+
auto It = CachedResults.find(ActionTC);
5852+
if (It != CachedResults.end()) {
5853+
InputInfoList Inputs = It->second;
58535854
Inputs.append(OffloadDependencesInputInfo);
58545855
return Inputs;
58555856
}

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,10 +1405,9 @@ const Expr *DSAStackTy::addUniqueAligned(const ValueDecl *D,
14051405
assert(!isStackEmpty() && "Data sharing attributes stack is empty");
14061406
D = getCanonicalDecl(D);
14071407
SharingMapTy &StackElem = getTopOfStack();
1408-
auto It = StackElem.AlignedMap.find(D);
1409-
if (It == StackElem.AlignedMap.end()) {
1408+
auto [It, Inserted] = StackElem.AlignedMap.try_emplace(D, NewDE);
1409+
if (Inserted) {
14101410
assert(NewDE && "Unexpected nullptr expr to be added into aligned map");
1411-
StackElem.AlignedMap[D] = NewDE;
14121411
return nullptr;
14131412
}
14141413
assert(It->second && "Unexpected nullptr expr in the aligned map");
@@ -1420,10 +1419,9 @@ const Expr *DSAStackTy::addUniqueNontemporal(const ValueDecl *D,
14201419
assert(!isStackEmpty() && "Data sharing attributes stack is empty");
14211420
D = getCanonicalDecl(D);
14221421
SharingMapTy &StackElem = getTopOfStack();
1423-
auto It = StackElem.NontemporalMap.find(D);
1424-
if (It == StackElem.NontemporalMap.end()) {
1422+
auto [It, Inserted] = StackElem.NontemporalMap.try_emplace(D, NewDE);
1423+
if (Inserted) {
14251424
assert(NewDE && "Unexpected nullptr expr to be added into aligned map");
1426-
StackElem.NontemporalMap[D] = NewDE;
14271425
return nullptr;
14281426
}
14291427
assert(It->second && "Unexpected nullptr expr in the aligned map");
@@ -22083,9 +22081,7 @@ SemaOpenMP::ActOnOpenMPDeclareReductionDirectiveStart(
2208322081
while (Filter.hasNext()) {
2208422082
auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next());
2208522083
if (InCompoundScope) {
22086-
auto I = UsedAsPrevious.find(PrevDecl);
22087-
if (I == UsedAsPrevious.end())
22088-
UsedAsPrevious[PrevDecl] = false;
22084+
UsedAsPrevious.try_emplace(PrevDecl, false);
2208922085
if (OMPDeclareReductionDecl *D = PrevDecl->getPrevDeclInScope())
2209022086
UsedAsPrevious[D] = true;
2209122087
}
@@ -22339,9 +22335,7 @@ SemaOpenMP::DeclGroupPtrTy SemaOpenMP::ActOnOpenMPDeclareMapperDirective(
2233922335
while (Filter.hasNext()) {
2234022336
auto *PrevDecl = cast<OMPDeclareMapperDecl>(Filter.next());
2234122337
if (InCompoundScope) {
22342-
auto I = UsedAsPrevious.find(PrevDecl);
22343-
if (I == UsedAsPrevious.end())
22344-
UsedAsPrevious[PrevDecl] = false;
22338+
UsedAsPrevious.try_emplace(PrevDecl, false);
2234522339
if (OMPDeclareMapperDecl *D = PrevDecl->getPrevDeclInScope())
2234622340
UsedAsPrevious[D] = true;
2234722341
}

clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ void BuiltinFunctionChecker::handleOverflowBuiltin(const CallEvent &Call,
183183
ProgramStateRef State = C.getState();
184184
SValBuilder &SVB = C.getSValBuilder();
185185
const Expr *CE = Call.getOriginExpr();
186+
auto BoolTy = C.getASTContext().BoolTy;
186187

187188
SVal Arg1 = Call.getArgSVal(0);
188189
SVal Arg2 = Call.getArgSVal(1);
@@ -193,8 +194,8 @@ void BuiltinFunctionChecker::handleOverflowBuiltin(const CallEvent &Call,
193194

194195
auto [Overflow, NotOverflow] = checkOverflow(C, RetValMax, ResultType);
195196
if (NotOverflow) {
196-
ProgramStateRef StateNoOverflow =
197-
State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(false));
197+
ProgramStateRef StateNoOverflow = State->BindExpr(
198+
CE, C.getLocationContext(), SVB.makeTruthVal(false, BoolTy));
198199

199200
if (auto L = Call.getArgSVal(2).getAs<Loc>()) {
200201
StateNoOverflow =
@@ -212,9 +213,9 @@ void BuiltinFunctionChecker::handleOverflowBuiltin(const CallEvent &Call,
212213
}
213214

214215
if (Overflow) {
215-
C.addTransition(
216-
State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(true)),
217-
createBuiltinOverflowNoteTag(C));
216+
C.addTransition(State->BindExpr(CE, C.getLocationContext(),
217+
SVB.makeTruthVal(true, BoolTy)),
218+
createBuiltinOverflowNoteTag(C));
218219
}
219220
}
220221

clang/test/Analysis/builtin_overflow.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -verify %s \
2-
// RUN: -analyzer-checker=core,debug.ExprInspection
2+
// RUN: -analyzer-checker=core,debug.ExprInspection,alpha.core.BoolAssignment
33

44
#define __UINT_MAX__ (__INT_MAX__ * 2U + 1U)
55
#define __INT_MIN__ (-__INT_MAX__ - 1)
@@ -155,3 +155,12 @@ void test_uadd_overflow_contraints(unsigned a, unsigned b)
155155
return;
156156
}
157157
}
158+
159+
void test_bool_assign(void)
160+
{
161+
int res;
162+
163+
// Reproduce issue from GH#111147. __builtin_*_overflow funcions
164+
// should return _Bool, but not int.
165+
_Bool ret = __builtin_mul_overflow(10, 20, &res); // no crash
166+
}

lld/ELF/AArch64ErrataFix.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
#include <vector>
1515

1616
namespace lld::elf {
17-
17+
struct Ctx;
1818
class Defined;
1919
class InputSection;
2020
class InputSectionDescription;
2121
class Patch843419Section;
2222

2323
class AArch64Err843419Patcher {
2424
public:
25+
AArch64Err843419Patcher(Ctx &ctx) : ctx(ctx) {}
2526
// return true if Patches have been added to the OutputSections.
2627
bool createFixes();
2728

@@ -34,6 +35,7 @@ class AArch64Err843419Patcher {
3435

3536
void init();
3637

38+
Ctx &ctx;
3739
// A cache of the mapping symbols defined by the InputSection sorted in order
3840
// of ascending value with redundant symbols removed. These describe
3941
// the ranges of code and data in an executable InputSection.

lld/ELF/InputSection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
7777
// SHF_INFO_LINK and SHF_GROUP are normally resolved and not copied to the
7878
// output section. However, for relocatable linking without
7979
// --force-group-allocation, the SHF_GROUP flag and section groups are retained.
80-
static uint64_t getFlags(uint64_t flags) {
80+
static uint64_t getFlags(Ctx &ctx, uint64_t flags) {
8181
flags &= ~(uint64_t)SHF_INFO_LINK;
8282
if (ctx.arg.resolveGroups)
8383
flags &= ~(uint64_t)SHF_GROUP;
@@ -88,7 +88,7 @@ template <class ELFT>
8888
InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
8989
const typename ELFT::Shdr &hdr,
9090
StringRef name, Kind sectionKind)
91-
: InputSectionBase(&file, getFlags(hdr.sh_flags), hdr.sh_type,
91+
: InputSectionBase(&file, getFlags(ctx, hdr.sh_flags), hdr.sh_type,
9292
hdr.sh_entsize, hdr.sh_link, hdr.sh_info,
9393
hdr.sh_addralign, getSectionContents(file, hdr), name,
9494
sectionKind) {

0 commit comments

Comments
 (0)