Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: I58051c9847a5cdc48a2c9f178ddd70468fffb80a
  • Loading branch information
Jenkins committed Sep 24, 2024
2 parents 8c1a259 + a6bdf3f commit 780fd8a
Show file tree
Hide file tree
Showing 142 changed files with 4,750 additions and 2,515 deletions.
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ Python Binding Changes
OpenMP Support
--------------
- Added support for 'omp assume' directive.
- Added support for 'omp scope' directive.

Improvements
^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,14 @@ class ProgramState : public llvm::FoldingSetNode {
/// \param ITraits information about special handling for particular regions
/// or symbols.
[[nodiscard]] ProgramStateRef
invalidateRegions(ArrayRef<const MemRegion *> Regions, const Expr *E,
invalidateRegions(ArrayRef<const MemRegion *> Regions, const Stmt *S,
unsigned BlockCount, const LocationContext *LCtx,
bool CausesPointerEscape, InvalidatedSymbols *IS = nullptr,
const CallEvent *Call = nullptr,
RegionAndSymbolInvalidationTraits *ITraits = nullptr) const;

[[nodiscard]] ProgramStateRef
invalidateRegions(ArrayRef<SVal> Values, const Expr *E, unsigned BlockCount,
invalidateRegions(ArrayRef<SVal> Values, const Stmt *S, unsigned BlockCount,
const LocationContext *LCtx, bool CausesPointerEscape,
InvalidatedSymbols *IS = nullptr,
const CallEvent *Call = nullptr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,9 @@ class SValBuilder {
const Expr *expr,
const LocationContext *LCtx,
unsigned count);
DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag,
const Expr *expr,
DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, const Stmt *S,
const LocationContext *LCtx,
QualType type,
unsigned count);
QualType type, unsigned count);
DefinedOrUnknownSVal conjureSymbolVal(const Stmt *stmt,
const LocationContext *LCtx,
QualType type,
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class StoreManager {
///
/// \param[in] store The initial store.
/// \param[in] Values The values to invalidate.
/// \param[in] E The current statement being evaluated. Used to conjure
/// \param[in] S The current statement being evaluated. Used to conjure
/// symbols to mark the values of invalidated regions.
/// \param[in] Count The current block count. Used to conjure
/// symbols to mark the values of invalidated regions.
Expand All @@ -233,7 +233,7 @@ class StoreManager {
/// even if they do not currently have bindings. Pass \c NULL if this
/// information will not be used.
virtual StoreRef invalidateRegions(
Store store, ArrayRef<SVal> Values, const Expr *Ex, unsigned Count,
Store store, ArrayRef<SVal> Values, const Stmt *S, unsigned Count,
const LocationContext *LCtx, const CallEvent *Call,
InvalidatedSymbols &IS, RegionAndSymbolInvalidationTraits &ITraits,
InvalidatedRegions *TopLevelRegions, InvalidatedRegions *Invalidated) = 0;
Expand Down
13 changes: 6 additions & 7 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,9 +1282,8 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
? BinaryOperator::getOpForCompoundAssignment(E->getOpcode())
: E->getOpcode();

// The LHS and RHS of a comparison operator must have the same type. So we
// just use LHS vector element type here.
PrimType ElemT = this->classifyVectorElementType(LHS->getType());
PrimType RHSElemT = this->classifyVectorElementType(RHS->getType());
PrimType ResultElemT = this->classifyVectorElementType(E->getType());

// Evaluate LHS and save value to LHSOffset.
Expand Down Expand Up @@ -1312,7 +1311,7 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
PrimType PromotT = classifyPrim(PromotTy);
PrimType OpT = NeedIntPromot ? PromotT : ElemT;

auto getElem = [=](unsigned Offset, unsigned Index) {
auto getElem = [=](unsigned Offset, PrimType ElemT, unsigned Index) {
if (!this->emitGetLocal(PT_Ptr, Offset, E))
return false;
if (!this->emitArrayElemPop(ElemT, Index, E))
Expand Down Expand Up @@ -1342,9 +1341,9 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
}

for (unsigned I = 0; I != VecTy->getNumElements(); ++I) {
if (!getElem(LHSOffset, I))
if (!getElem(LHSOffset, ElemT, I))
return false;
if (!getElem(RHSOffset, I))
if (!getElem(RHSOffset, RHSElemT, I))
return false;
switch (Op) {
case BO_Add:
Expand Down Expand Up @@ -1372,11 +1371,11 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
return false;
break;
case BO_Shl:
if (!this->emitShl(OpT, ElemT, E))
if (!this->emitShl(OpT, RHSElemT, E))
return false;
break;
case BO_Shr:
if (!this->emitShr(OpT, ElemT, E))
if (!this->emitShr(OpT, RHSElemT, E))
return false;
break;
case BO_EQ:
Expand Down
50 changes: 14 additions & 36 deletions clang/lib/Frontend/Rewrite/RewriteObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ namespace {
SmallVector<DeclRefExpr *, 32> BlockDeclRefs;

// Block related declarations.
SmallVector<ValueDecl *, 8> BlockByCopyDecls;
llvm::SmallPtrSet<ValueDecl *, 8> BlockByCopyDeclsPtrSet;
SmallVector<ValueDecl *, 8> BlockByRefDecls;
llvm::SmallPtrSet<ValueDecl *, 8> BlockByRefDeclsPtrSet;
llvm::SmallSetVector<ValueDecl *, 8> BlockByCopyDecls;
llvm::SmallSetVector<ValueDecl *, 8> BlockByRefDecls;
llvm::DenseMap<ValueDecl *, unsigned> BlockByRefDeclNo;
llvm::SmallPtrSet<ValueDecl *, 8> ImportedBlockDecls;
llvm::SmallPtrSet<VarDecl *, 8> ImportedLocalExternalDecls;
Expand Down Expand Up @@ -3357,7 +3355,7 @@ std::string RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i,
S += VD->getNameAsString();
S += ", (void*)src->";
S += VD->getNameAsString();
if (BlockByRefDeclsPtrSet.count(VD))
if (BlockByRefDecls.contains(VD))
S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
else if (VD->getType()->isBlockPointerType())
S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
Expand All @@ -3374,7 +3372,7 @@ std::string RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i,
for (ValueDecl *VD : ImportedBlockDecls) {
S += "_Block_object_dispose((void*)src->";
S += VD->getNameAsString();
if (BlockByRefDeclsPtrSet.count(VD))
if (BlockByRefDecls.contains(VD))
S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
else if (VD->getType()->isBlockPointerType())
S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
Expand Down Expand Up @@ -3553,14 +3551,10 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
DeclRefExpr *Exp = InnerDeclRefs[count++];
ValueDecl *VD = Exp->getDecl();
BlockDeclRefs.push_back(Exp);
if (!VD->hasAttr<BlocksAttr>() && !BlockByCopyDeclsPtrSet.count(VD)) {
BlockByCopyDeclsPtrSet.insert(VD);
BlockByCopyDecls.push_back(VD);
}
if (VD->hasAttr<BlocksAttr>() && !BlockByRefDeclsPtrSet.count(VD)) {
BlockByRefDeclsPtrSet.insert(VD);
BlockByRefDecls.push_back(VD);
}
if (VD->hasAttr<BlocksAttr>())
BlockByRefDecls.insert(VD);
else
BlockByCopyDecls.insert(VD);
// imported objects in the inner blocks not used in the outer
// blocks must be copied/disposed in the outer block as well.
if (VD->hasAttr<BlocksAttr>() ||
Expand Down Expand Up @@ -3590,9 +3584,7 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,

BlockDeclRefs.clear();
BlockByRefDecls.clear();
BlockByRefDeclsPtrSet.clear();
BlockByCopyDecls.clear();
BlockByCopyDeclsPtrSet.clear();
ImportedBlockDecls.clear();
}
if (RewriteSC) {
Expand Down Expand Up @@ -4314,20 +4306,12 @@ void RewriteObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) {
if (BlockDeclRefs.size()) {
// Unique all "by copy" declarations.
for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
if (!BlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>()) {
if (!BlockByCopyDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) {
BlockByCopyDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl());
BlockByCopyDecls.push_back(BlockDeclRefs[i]->getDecl());
}
}
if (!BlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>())
BlockByCopyDecls.insert(BlockDeclRefs[i]->getDecl());
// Unique all "by ref" declarations.
for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
if (BlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>()) {
if (!BlockByRefDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) {
BlockByRefDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl());
BlockByRefDecls.push_back(BlockDeclRefs[i]->getDecl());
}
}
if (BlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>())
BlockByRefDecls.insert(BlockDeclRefs[i]->getDecl());
// Find any imported blocks...they will need special attention.
for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
if (BlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>() ||
Expand Down Expand Up @@ -4358,22 +4342,18 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) {
DeclRefExpr *Exp = InnerBlockDeclRefs[i];
ValueDecl *VD = Exp->getDecl();
if (!VD->hasAttr<BlocksAttr>() &&
BlockByCopyDeclsPtrSet.insert(VD).second) {
if (!VD->hasAttr<BlocksAttr>() && BlockByCopyDecls.insert(VD)) {
// We need to save the copied-in variables in nested
// blocks because it is needed at the end for some of the API
// generations. See SynthesizeBlockLiterals routine.
InnerDeclRefs.push_back(Exp);
countOfInnerDecls++;
BlockDeclRefs.push_back(Exp);
BlockByCopyDecls.push_back(VD);
}
if (VD->hasAttr<BlocksAttr>() &&
BlockByRefDeclsPtrSet.insert(VD).second) {
if (VD->hasAttr<BlocksAttr>() && BlockByRefDecls.insert(VD)) {
InnerDeclRefs.push_back(Exp);
countOfInnerDecls++;
BlockDeclRefs.push_back(Exp);
BlockByRefDecls.push_back(VD);
}
}
// Find any imported blocks...they will need special attention.
Expand Down Expand Up @@ -4534,9 +4514,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
NewRep);
BlockDeclRefs.clear();
BlockByRefDecls.clear();
BlockByRefDeclsPtrSet.clear();
BlockByCopyDecls.clear();
BlockByCopyDeclsPtrSet.clear();
ImportedBlockDecls.clear();
return NewRep;
}
Expand Down
30 changes: 12 additions & 18 deletions clang/lib/StaticAnalyzer/Core/ProgramState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,24 @@ ProgramState::bindDefaultZero(SVal loc, const LocationContext *LCtx) const {
typedef ArrayRef<const MemRegion *> RegionList;
typedef ArrayRef<SVal> ValueList;

ProgramStateRef
ProgramState::invalidateRegions(RegionList Regions,
const Expr *E, unsigned Count,
const LocationContext *LCtx,
bool CausedByPointerEscape,
InvalidatedSymbols *IS,
const CallEvent *Call,
RegionAndSymbolInvalidationTraits *ITraits) const {
ProgramStateRef ProgramState::invalidateRegions(
RegionList Regions, const Stmt *S, unsigned Count,
const LocationContext *LCtx, bool CausedByPointerEscape,
InvalidatedSymbols *IS, const CallEvent *Call,
RegionAndSymbolInvalidationTraits *ITraits) const {
SmallVector<SVal, 8> Values;
for (const MemRegion *Reg : Regions)
Values.push_back(loc::MemRegionVal(Reg));

return invalidateRegions(Values, E, Count, LCtx, CausedByPointerEscape, IS,
return invalidateRegions(Values, S, Count, LCtx, CausedByPointerEscape, IS,
Call, ITraits);
}

ProgramStateRef
ProgramState::invalidateRegions(ValueList Values,
const Expr *E, unsigned Count,
const LocationContext *LCtx,
bool CausedByPointerEscape,
InvalidatedSymbols *IS,
const CallEvent *Call,
RegionAndSymbolInvalidationTraits *ITraits) const {
ProgramStateRef ProgramState::invalidateRegions(
ValueList Values, const Stmt *S, unsigned Count,
const LocationContext *LCtx, bool CausedByPointerEscape,
InvalidatedSymbols *IS, const CallEvent *Call,
RegionAndSymbolInvalidationTraits *ITraits) const {

ProgramStateManager &Mgr = getStateManager();
ExprEngine &Eng = Mgr.getOwningEngine();
Expand All @@ -186,7 +180,7 @@ ProgramState::invalidateRegions(ValueList Values,
StoreManager::InvalidatedRegions TopLevelInvalidated;
StoreManager::InvalidatedRegions Invalidated;
const StoreRef &NewStore = Mgr.StoreMgr->invalidateRegions(
getStore(), Values, E, Count, LCtx, Call, *IS, *ITraits,
getStore(), Values, S, Count, LCtx, Call, *IS, *ITraits,
&TopLevelInvalidated, &Invalidated);

ProgramStateRef NewState = makeWithStore(NewStore);
Expand Down
Loading

0 comments on commit 780fd8a

Please sign in to comment.