Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: I05d9aa4950fdaae931ccda281de93a565b85a6c1
  • Loading branch information
Jenkins committed Oct 5, 2024
2 parents f102fb0 + 68210c7 commit 24cddcc
Show file tree
Hide file tree
Showing 30 changed files with 511 additions and 105 deletions.
7 changes: 7 additions & 0 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,13 @@ bool Compiler<Emitter>::VisitUnaryExprOrTypeTraitExpr(
return this->emitConst(1, E);
}

if (Kind == UETT_OpenMPRequiredSimdAlign) {
assert(E->isArgumentType());
unsigned Bits = ASTCtx.getOpenMPDefaultSimdAlign(E->getArgumentType());

return this->emitConst(ASTCtx.toCharUnitsFromBits(Bits).getQuantity(), E);
}

return false;
}

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/ByteCode/InterpBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ bool Block::hasPointer(const Pointer *P) const {
#endif

DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
: Root(Root),
B(~0u, Blk->Desc, Blk->IsStatic, Blk->IsExtern, /*isDead=*/true) {
: Root(Root), B(~0u, Blk->Desc, Blk->IsStatic, Blk->IsExtern, Blk->IsWeak,
/*isDead=*/true) {
// Add the block to the chain of dead blocks.
if (Root)
Root->Prev = this;
Expand Down
15 changes: 9 additions & 6 deletions clang/lib/AST/ByteCode/InterpBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ class Block final {
public:
/// Creates a new block.
Block(unsigned EvalID, const std::optional<unsigned> &DeclID,
const Descriptor *Desc, bool IsStatic = false, bool IsExtern = false)
const Descriptor *Desc, bool IsStatic = false, bool IsExtern = false,
bool IsWeak = false)
: EvalID(EvalID), DeclID(DeclID), IsStatic(IsStatic), IsExtern(IsExtern),
IsDynamic(false), Desc(Desc) {
IsDynamic(false), IsWeak(IsWeak), Desc(Desc) {
assert(Desc);
}

Block(unsigned EvalID, const Descriptor *Desc, bool IsStatic = false,
bool IsExtern = false)
bool IsExtern = false, bool IsWeak = false)
: EvalID(EvalID), DeclID((unsigned)-1), IsStatic(IsStatic),
IsExtern(IsExtern), IsDynamic(false), Desc(Desc) {
IsExtern(IsExtern), IsDynamic(false), IsWeak(IsWeak), Desc(Desc) {
assert(Desc);
}

Expand All @@ -73,6 +74,7 @@ class Block final {
bool isStatic() const { return IsStatic; }
/// Checks if the block is temporary.
bool isTemporary() const { return Desc->IsTemporary; }
bool isWeak() const { return IsWeak; }
bool isDynamic() const { return IsDynamic; }
/// Returns the size of the block.
unsigned getSize() const { return Desc->getAllocSize(); }
Expand Down Expand Up @@ -135,9 +137,9 @@ class Block final {
friend class DynamicAllocator;

Block(unsigned EvalID, const Descriptor *Desc, bool IsExtern, bool IsStatic,
bool IsDead)
bool IsWeak, bool IsDead)
: EvalID(EvalID), IsStatic(IsStatic), IsExtern(IsExtern), IsDead(true),
IsDynamic(false), Desc(Desc) {
IsDynamic(false), IsWeak(IsWeak), Desc(Desc) {
assert(Desc);
}

Expand Down Expand Up @@ -170,6 +172,7 @@ class Block final {
/// Flag indicating if this block has been allocated via dynamic
/// memory allocation (e.g. malloc).
bool IsDynamic = false;
bool IsWeak = false;
/// Pointer to the stack slot descriptor.
const Descriptor *Desc;
};
Expand Down
4 changes: 1 addition & 3 deletions clang/lib/AST/ByteCode/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,7 @@ class Pointer {
return false;

assert(isBlockPointer());
if (const ValueDecl *VD = getDeclDesc()->asValueDecl())
return VD->isWeak();
return false;
return asBlockPointer().Pointee->isWeak();
}
/// Checks if an object was initialized.
bool isInitialized() const;
Expand Down
16 changes: 10 additions & 6 deletions clang/lib/AST/ByteCode/Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ std::optional<unsigned> Program::getOrCreateDummy(const DeclTy &D) {
return It->second;

QualType QT;
bool IsWeak = false;
if (const auto *E = D.dyn_cast<const Expr *>()) {
QT = E->getType();
} else {
const ValueDecl *VD = cast<ValueDecl>(D.get<const Decl *>());
IsWeak = VD->isWeak();
QT = VD->getType();
if (const auto *RT = QT->getAs<ReferenceType>())
QT = RT->getPointeeType();
Expand All @@ -182,7 +184,7 @@ std::optional<unsigned> Program::getOrCreateDummy(const DeclTy &D) {

auto *G = new (Allocator, Desc->getAllocSize())
Global(Ctx.getEvalID(), getCurrentDecl(), Desc, /*IsStatic=*/true,
/*IsExtern=*/false);
/*IsExtern=*/false, IsWeak);
G->block()->invokeCtor();

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

// Register all previous declarations as well. For extern blocks, just replace
// the index with the new variable.
if (auto Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern, Init)) {
if (auto Idx =
createGlobal(VD, VD->getType(), IsStatic, IsExtern, IsWeak, Init)) {
for (const Decl *P = VD; P; P = P->getPreviousDecl()) {
if (P != VD) {
unsigned PIdx = GlobalIndices[P];
Expand All @@ -225,7 +229,7 @@ std::optional<unsigned> Program::createGlobal(const Expr *E) {
if (auto Idx = getGlobal(E))
return Idx;
if (auto Idx = createGlobal(E, E->getType(), /*isStatic=*/true,
/*isExtern=*/false)) {
/*isExtern=*/false, /*IsWeak=*/false)) {
GlobalIndices[E] = *Idx;
return *Idx;
}
Expand All @@ -234,7 +238,7 @@ std::optional<unsigned> Program::createGlobal(const Expr *E) {

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

auto *G = new (Allocator, Desc->getAllocSize())
Global(Ctx.getEvalID(), getCurrentDecl(), Desc, IsStatic, IsExtern);
auto *G = new (Allocator, Desc->getAllocSize()) Global(
Ctx.getEvalID(), getCurrentDecl(), Desc, IsStatic, IsExtern, IsWeak);
G->block()->invokeCtor();

// Initialize InlineDescriptor fields.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Program.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Program final {

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

/// Reference to the VM context.
Context &Ctx;
Expand Down
17 changes: 9 additions & 8 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,9 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
} else
TC = &getToolChain(C.getInputArgs(), TT);
C.addOffloadDeviceToolChain(TC, Action::OFK_OpenMP);
if (DerivedArchs.contains(TT.getTriple()))
KnownArchs[TC] = DerivedArchs[TT.getTriple()];
auto It = DerivedArchs.find(TT.getTriple());
if (It != DerivedArchs.end())
KnownArchs[TC] = It->second;
}
}
} else if (C.getInputArgs().hasArg(options::OPT_fopenmp_targets_EQ)) {
Expand Down Expand Up @@ -3992,11 +3993,10 @@ class OffloadingActionBuilder final {
void recordHostAction(Action *HostAction, const Arg *InputArg) {
assert(HostAction && "Invalid host action");
assert(InputArg && "Invalid input argument");
auto Loc = HostActionToInputArgMap.find(HostAction);
if (Loc == HostActionToInputArgMap.end())
HostActionToInputArgMap[HostAction] = InputArg;
assert(HostActionToInputArgMap[HostAction] == InputArg &&
auto Loc = HostActionToInputArgMap.try_emplace(HostAction, InputArg).first;
assert(Loc->second == InputArg &&
"host action mapped to multiple input arguments");
(void)Loc;
}

/// Generate an action that adds device dependences (if any) to a host action.
Expand Down Expand Up @@ -5848,8 +5848,9 @@ InputInfoList Driver::BuildJobsForActionNoCache(
std::pair<const Action *, std::string> ActionTC = {
OA->getHostDependence(),
GetTriplePlusArchString(TC, BoundArch, TargetDeviceOffloadKind)};
if (CachedResults.find(ActionTC) != CachedResults.end()) {
InputInfoList Inputs = CachedResults[ActionTC];
auto It = CachedResults.find(ActionTC);
if (It != CachedResults.end()) {
InputInfoList Inputs = It->second;
Inputs.append(OffloadDependencesInputInfo);
return Inputs;
}
Expand Down
18 changes: 6 additions & 12 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,10 +1405,9 @@ const Expr *DSAStackTy::addUniqueAligned(const ValueDecl *D,
assert(!isStackEmpty() && "Data sharing attributes stack is empty");
D = getCanonicalDecl(D);
SharingMapTy &StackElem = getTopOfStack();
auto It = StackElem.AlignedMap.find(D);
if (It == StackElem.AlignedMap.end()) {
auto [It, Inserted] = StackElem.AlignedMap.try_emplace(D, NewDE);
if (Inserted) {
assert(NewDE && "Unexpected nullptr expr to be added into aligned map");
StackElem.AlignedMap[D] = NewDE;
return nullptr;
}
assert(It->second && "Unexpected nullptr expr in the aligned map");
Expand All @@ -1420,10 +1419,9 @@ const Expr *DSAStackTy::addUniqueNontemporal(const ValueDecl *D,
assert(!isStackEmpty() && "Data sharing attributes stack is empty");
D = getCanonicalDecl(D);
SharingMapTy &StackElem = getTopOfStack();
auto It = StackElem.NontemporalMap.find(D);
if (It == StackElem.NontemporalMap.end()) {
auto [It, Inserted] = StackElem.NontemporalMap.try_emplace(D, NewDE);
if (Inserted) {
assert(NewDE && "Unexpected nullptr expr to be added into aligned map");
StackElem.NontemporalMap[D] = NewDE;
return nullptr;
}
assert(It->second && "Unexpected nullptr expr in the aligned map");
Expand Down Expand Up @@ -22083,9 +22081,7 @@ SemaOpenMP::ActOnOpenMPDeclareReductionDirectiveStart(
while (Filter.hasNext()) {
auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next());
if (InCompoundScope) {
auto I = UsedAsPrevious.find(PrevDecl);
if (I == UsedAsPrevious.end())
UsedAsPrevious[PrevDecl] = false;
UsedAsPrevious.try_emplace(PrevDecl, false);
if (OMPDeclareReductionDecl *D = PrevDecl->getPrevDeclInScope())
UsedAsPrevious[D] = true;
}
Expand Down Expand Up @@ -22339,9 +22335,7 @@ SemaOpenMP::DeclGroupPtrTy SemaOpenMP::ActOnOpenMPDeclareMapperDirective(
while (Filter.hasNext()) {
auto *PrevDecl = cast<OMPDeclareMapperDecl>(Filter.next());
if (InCompoundScope) {
auto I = UsedAsPrevious.find(PrevDecl);
if (I == UsedAsPrevious.end())
UsedAsPrevious[PrevDecl] = false;
UsedAsPrevious.try_emplace(PrevDecl, false);
if (OMPDeclareMapperDecl *D = PrevDecl->getPrevDeclInScope())
UsedAsPrevious[D] = true;
}
Expand Down
11 changes: 6 additions & 5 deletions clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void BuiltinFunctionChecker::handleOverflowBuiltin(const CallEvent &Call,
ProgramStateRef State = C.getState();
SValBuilder &SVB = C.getSValBuilder();
const Expr *CE = Call.getOriginExpr();
auto BoolTy = C.getASTContext().BoolTy;

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

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

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

if (Overflow) {
C.addTransition(
State->BindExpr(CE, C.getLocationContext(), SVB.makeTruthVal(true)),
createBuiltinOverflowNoteTag(C));
C.addTransition(State->BindExpr(CE, C.getLocationContext(),
SVB.makeTruthVal(true, BoolTy)),
createBuiltinOverflowNoteTag(C));
}
}

Expand Down
11 changes: 10 additions & 1 deletion clang/test/Analysis/builtin_overflow.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -verify %s \
// RUN: -analyzer-checker=core,debug.ExprInspection
// RUN: -analyzer-checker=core,debug.ExprInspection,alpha.core.BoolAssignment

#define __UINT_MAX__ (__INT_MAX__ * 2U + 1U)
#define __INT_MIN__ (-__INT_MAX__ - 1)
Expand Down Expand Up @@ -155,3 +155,12 @@ void test_uadd_overflow_contraints(unsigned a, unsigned b)
return;
}
}

void test_bool_assign(void)
{
int res;

// Reproduce issue from GH#111147. __builtin_*_overflow funcions
// should return _Bool, but not int.
_Bool ret = __builtin_mul_overflow(10, 20, &res); // no crash
}
4 changes: 3 additions & 1 deletion lld/ELF/AArch64ErrataFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
#include <vector>

namespace lld::elf {

struct Ctx;
class Defined;
class InputSection;
class InputSectionDescription;
class Patch843419Section;

class AArch64Err843419Patcher {
public:
AArch64Err843419Patcher(Ctx &ctx) : ctx(ctx) {}
// return true if Patches have been added to the OutputSections.
bool createFixes();

Expand All @@ -34,6 +35,7 @@ class AArch64Err843419Patcher {

void init();

Ctx &ctx;
// A cache of the mapping symbols defined by the InputSection sorted in order
// of ascending value with redundant symbols removed. These describe
// the ranges of code and data in an executable InputSection.
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/InputSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
// SHF_INFO_LINK and SHF_GROUP are normally resolved and not copied to the
// output section. However, for relocatable linking without
// --force-group-allocation, the SHF_GROUP flag and section groups are retained.
static uint64_t getFlags(uint64_t flags) {
static uint64_t getFlags(Ctx &ctx, uint64_t flags) {
flags &= ~(uint64_t)SHF_INFO_LINK;
if (ctx.arg.resolveGroups)
flags &= ~(uint64_t)SHF_GROUP;
Expand All @@ -88,7 +88,7 @@ template <class ELFT>
InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
const typename ELFT::Shdr &hdr,
StringRef name, Kind sectionKind)
: InputSectionBase(&file, getFlags(hdr.sh_flags), hdr.sh_type,
: InputSectionBase(&file, getFlags(ctx, hdr.sh_flags), hdr.sh_type,
hdr.sh_entsize, hdr.sh_link, hdr.sh_info,
hdr.sh_addralign, getSectionContents(file, hdr), name,
sectionKind) {
Expand Down
Loading

0 comments on commit 24cddcc

Please sign in to comment.