Skip to content

Commit 3ae0653

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:b10ecfa914dd1bc2013584917d0505ba5f15f75c into amd-gfx:8182b88afaa8
Local branch amd-gfx 8182b88 Manually merged main:e2f9c1853349a5dc86ccd0e85e09af245c418aa8 into amd-gfx:857e6d3ada20 Remote branch main b10ecfa [SLP]Represent externally used values as original scalars, if profitable.
2 parents 8182b88 + b10ecfa commit 3ae0653

File tree

350 files changed

+8192
-4676
lines changed

Some content is hidden

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

350 files changed

+8192
-4676
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,11 @@ alpha.core.PointerSub (C)
25012501
Check for pointer subtractions on two pointers pointing to different memory
25022502
chunks. According to the C standard §6.5.6 only subtraction of pointers that
25032503
point into (or one past the end) the same array object is valid (for this
2504-
purpose non-array variables are like arrays of size 1).
2504+
purpose non-array variables are like arrays of size 1). This checker only
2505+
searches for different memory objects at subtraction, but does not check if the
2506+
array index is correct. Furthermore, only cases are reported where
2507+
stack-allocated objects are involved (no warnings on pointers to memory
2508+
allocated by `malloc`).
25052509
25062510
.. code-block:: c
25072511
@@ -2511,11 +2515,6 @@ purpose non-array variables are like arrays of size 1).
25112515
x = &d[4] - &c[1]; // warn: 'c' and 'd' are different arrays
25122516
x = (&a + 1) - &a;
25132517
x = &b - &a; // warn: 'a' and 'b' are different variables
2514-
x = (&a + 2) - &a; // warn: for a variable it is only valid to have a pointer
2515-
// to one past the address of it
2516-
x = &c[10] - &c[0];
2517-
x = &c[11] - &c[0]; // warn: index larger than one past the end
2518-
x = &c[-1] - &c[0]; // warn: negative index
25192518
}
25202519
25212520
struct S {
@@ -2538,9 +2537,6 @@ offsets of members in a structure, using pointer subtractions. This is still
25382537
undefined behavior according to the standard and code like this can be replaced
25392538
with the `offsetof` macro.
25402539
2541-
The checker only reports cases where stack-allocated objects are involved (no
2542-
warnings on pointers to memory allocated by `malloc`).
2543-
25442540
.. _alpha-core-StackAddressAsyncEscape:
25452541
25462542
alpha.core.StackAddressAsyncEscape (C)

clang/include/clang/Basic/arm_sme.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ multiclass ZAAddSub<string n_suffix> {
325325
def NAME # _ZA16_VG1X4_F16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x4", "vm4", "h", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x4", [IsStreaming, IsInOutZA], []>;
326326
}
327327

328-
let SMETargetGuard = "sme2,b16b16" in {
328+
let SMETargetGuard = "sme-b16b16" in {
329329
def NAME # _ZA16_VG1X2_BF16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x2", "vm2", "b", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x2", [IsStreaming, IsInOutZA], []>;
330330
def NAME # _ZA16_VG1X4_BF16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x4", "vm4", "b", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x4", [IsStreaming, IsInOutZA], []>;
331331
}
@@ -506,7 +506,7 @@ let SMETargetGuard = "sme-f16f16" in {
506506
def SVMLS_LANE_VG1x4_F16 : Inst<"svmls_lane_za16[_f16]_vg1x4", "vm4di", "h", MergeNone, "aarch64_sme_fmls_lane_vg1x4", [IsStreaming, IsInOutZA], [ImmCheck<3, ImmCheck0_7>]>;
507507
}
508508

509-
let SMETargetGuard = "sme2,b16b16" in {
509+
let SMETargetGuard = "sme-b16b16" in {
510510
def SVMLA_MULTI_VG1x2_BF16 : Inst<"svmla_za16[_bf16]_vg1x2", "vm22", "b", MergeNone, "aarch64_sme_fmla_vg1x2", [IsStreaming, IsInOutZA], []>;
511511
def SVMLA_MULTI_VG1x4_BF16 : Inst<"svmla_za16[_bf16]_vg1x4", "vm44", "b", MergeNone, "aarch64_sme_fmla_vg1x4", [IsStreaming, IsInOutZA], []>;
512512
def SVMLS_MULTI_VG1x2_BF16 : Inst<"svmls_za16[_bf16]_vg1x2", "vm22", "b", MergeNone, "aarch64_sme_fmls_vg1x2", [IsStreaming, IsInOutZA], []>;
@@ -742,7 +742,7 @@ let SMETargetGuard = "sme2" in {
742742

743743
////////////////////////////////////////////////////////////////////////////////
744744
// SME2p1 - FMOPA, FMOPS (non-widening)
745-
let SMETargetGuard = "sme2,b16b16" in {
745+
let SMETargetGuard = "sme-b16b16" in {
746746
def SVMOPA_BF16_NW : SInst<"svmopa_za16[_bf16]_m", "viPPdd", "b",
747747
MergeNone, "aarch64_sme_mopa",
748748
[IsStreaming, IsInOutZA],

clang/include/clang/Frontend/MultiplexConsumer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class MultiplexASTDeserializationListener : public ASTDeserializationListener {
3636
void MacroRead(serialization::MacroID ID, MacroInfo *MI) override;
3737
void TypeRead(serialization::TypeIdx Idx, QualType T) override;
3838
void DeclRead(GlobalDeclID ID, const Decl *D) override;
39+
void PredefinedDeclBuilt(PredefinedDeclIDs ID, const Decl *D) override;
3940
void SelectorRead(serialization::SelectorID iD, Selector Sel) override;
4041
void MacroDefinitionRead(serialization::PreprocessedEntityID,
4142
MacroDefinitionRecord *MD) override;

clang/include/clang/Serialization/ASTDeserializationListener.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class ASTDeserializationListener {
4545
virtual void TypeRead(serialization::TypeIdx Idx, QualType T) { }
4646
/// A decl was deserialized from the AST file.
4747
virtual void DeclRead(GlobalDeclID ID, const Decl *D) {}
48+
/// A predefined decl was built during the serialization.
49+
virtual void PredefinedDeclBuilt(PredefinedDeclIDs ID, const Decl *D) {}
4850
/// A selector was read from the AST file.
4951
virtual void SelectorRead(serialization::SelectorID iD, Selector Sel) {}
5052
/// A macro definition was read from the AST file.

clang/include/clang/Serialization/ASTReader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,9 @@ class ASTReader
15591559
std::pair<ModuleFile *, unsigned>
15601560
translateTypeIDToIndex(serialization::TypeID ID) const;
15611561

1562+
/// Get a predefined Decl from ASTContext.
1563+
Decl *getPredefinedDecl(PredefinedDeclIDs ID);
1564+
15621565
public:
15631566
/// Load the AST file and validate its contents against the given
15641567
/// Preprocessor.

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ class ASTWriter : public ASTDeserializationListener,
869869
void IdentifierRead(serialization::IdentifierID ID, IdentifierInfo *II) override;
870870
void MacroRead(serialization::MacroID ID, MacroInfo *MI) override;
871871
void TypeRead(serialization::TypeIdx Idx, QualType T) override;
872+
void PredefinedDeclBuilt(PredefinedDeclIDs ID, const Decl *D) override;
872873
void SelectorRead(serialization::SelectorID ID, Selector Sel) override;
873874
void MacroDefinitionRead(serialization::PreprocessedEntityID ID,
874875
MacroDefinitionRecord *MD) override;

clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -304,24 +304,27 @@ class ProgramState : public llvm::FoldingSetNode {
304304

305305
[[nodiscard]] ProgramStateRef killBinding(Loc LV) const;
306306

307-
/// Returns the state with bindings for the given regions
308-
/// cleared from the store.
307+
/// Returns the state with bindings for the given regions cleared from the
308+
/// store. If \p Call is non-null, also invalidates global regions (but if
309+
/// \p Call is from a system header, then this is limited to globals declared
310+
/// in system headers).
309311
///
310-
/// Optionally invalidates global regions as well.
312+
/// This calls the lower-level method \c StoreManager::invalidateRegions to
313+
/// do the actual invalidation, then calls the checker callbacks which should
314+
/// be triggered by this event.
311315
///
312316
/// \param Regions the set of regions to be invalidated.
313317
/// \param E the expression that caused the invalidation.
314318
/// \param BlockCount The number of times the current basic block has been
315-
// visited.
316-
/// \param CausesPointerEscape the flag is set to true when
317-
/// the invalidation entails escape of a symbol (representing a
318-
/// pointer). For example, due to it being passed as an argument in a
319-
/// call.
319+
/// visited.
320+
/// \param CausesPointerEscape the flag is set to true when the invalidation
321+
/// entails escape of a symbol (representing a pointer). For example,
322+
/// due to it being passed as an argument in a call.
320323
/// \param IS the set of invalidated symbols.
321324
/// \param Call if non-null, the invalidated regions represent parameters to
322325
/// the call and should be considered directly invalidated.
323-
/// \param ITraits information about special handling for a particular
324-
/// region/symbol.
326+
/// \param ITraits information about special handling for particular regions
327+
/// or symbols.
325328
[[nodiscard]] ProgramStateRef
326329
invalidateRegions(ArrayRef<const MemRegion *> Regions, const Expr *E,
327330
unsigned BlockCount, const LocationContext *LCtx,
@@ -330,7 +333,7 @@ class ProgramState : public llvm::FoldingSetNode {
330333
RegionAndSymbolInvalidationTraits *ITraits = nullptr) const;
331334

332335
[[nodiscard]] ProgramStateRef
333-
invalidateRegions(ArrayRef<SVal> Regions, const Expr *E, unsigned BlockCount,
336+
invalidateRegions(ArrayRef<SVal> Values, const Expr *E, unsigned BlockCount,
334337
const LocationContext *LCtx, bool CausesPointerEscape,
335338
InvalidatedSymbols *IS = nullptr,
336339
const CallEvent *Call = nullptr,
@@ -484,17 +487,6 @@ class ProgramState : public llvm::FoldingSetNode {
484487
friend void ProgramStateRetain(const ProgramState *state);
485488
friend void ProgramStateRelease(const ProgramState *state);
486489

487-
/// \sa invalidateValues()
488-
/// \sa invalidateRegions()
489-
ProgramStateRef
490-
invalidateRegionsImpl(ArrayRef<SVal> Values,
491-
const Expr *E, unsigned BlockCount,
492-
const LocationContext *LCtx,
493-
bool ResultsInSymbolEscape,
494-
InvalidatedSymbols *IS,
495-
RegionAndSymbolInvalidationTraits *HTraits,
496-
const CallEvent *Call) const;
497-
498490
SVal wrapSymbolicRegion(SVal Base) const;
499491
};
500492

clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,15 @@ class StoreManager {
205205
/// invalidateRegions - Clears out the specified regions from the store,
206206
/// marking their values as unknown. Depending on the store, this may also
207207
/// invalidate additional regions that may have changed based on accessing
208-
/// the given regions. Optionally, invalidates non-static globals as well.
209-
/// \param[in] store The initial store
208+
/// the given regions. If \p Call is non-null, then this also invalidates
209+
/// non-static globals (but if \p Call is from a system header, then this is
210+
/// limited to globals declared in system headers).
211+
///
212+
/// Instead of calling this method directly, you should probably use
213+
/// \c ProgramState::invalidateRegions, which calls this and then ensures that
214+
/// the relevant checker callbacks are triggered.
215+
///
216+
/// \param[in] store The initial store.
210217
/// \param[in] Values The values to invalidate.
211218
/// \param[in] E The current statement being evaluated. Used to conjure
212219
/// symbols to mark the values of invalidated regions.

clang/lib/AST/Interp/Compiler.cpp

Lines changed: 87 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4733,9 +4733,8 @@ bool Compiler<Emitter>::checkLiteralType(const Expr *E) {
47334733
}
47344734

47354735
template <class Emitter>
4736-
bool Compiler<Emitter>::visitFunc(const FunctionDecl *F) {
4737-
// Classify the return type.
4738-
ReturnType = this->classify(F->getReturnType());
4736+
bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
4737+
assert(!ReturnType);
47394738

47404739
auto emitFieldInitializer = [&](const Record::Field *F, unsigned FieldOffset,
47414740
const Expr *InitExpr) -> bool {
@@ -4763,102 +4762,114 @@ bool Compiler<Emitter>::visitFunc(const FunctionDecl *F) {
47634762
return this->emitFinishInitPop(InitExpr);
47644763
};
47654764

4766-
// Emit custom code if this is a lambda static invoker.
4767-
if (const auto *MD = dyn_cast<CXXMethodDecl>(F);
4768-
MD && MD->isLambdaStaticInvoker())
4769-
return this->emitLambdaStaticInvokerBody(MD);
4765+
const RecordDecl *RD = Ctor->getParent();
4766+
const Record *R = this->getRecord(RD);
4767+
if (!R)
4768+
return false;
47704769

4771-
// Constructor. Set up field initializers.
4772-
if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(F)) {
4773-
const RecordDecl *RD = Ctor->getParent();
4774-
const Record *R = this->getRecord(RD);
4775-
if (!R)
4770+
if (R->isUnion() && Ctor->isCopyOrMoveConstructor()) {
4771+
// union copy and move ctors are special.
4772+
assert(cast<CompoundStmt>(Ctor->getBody())->body_empty());
4773+
if (!this->emitThis(Ctor))
47764774
return false;
47774775

4778-
if (R->isUnion() && Ctor->isCopyOrMoveConstructor()) {
4779-
// union copy and move ctors are special.
4780-
assert(cast<CompoundStmt>(Ctor->getBody())->body_empty());
4781-
if (!this->emitThis(Ctor))
4782-
return false;
4776+
auto PVD = Ctor->getParamDecl(0);
4777+
ParamOffset PO = this->Params[PVD]; // Must exist.
47834778

4784-
auto PVD = Ctor->getParamDecl(0);
4785-
ParamOffset PO = this->Params[PVD]; // Must exist.
4779+
if (!this->emitGetParam(PT_Ptr, PO.Offset, Ctor))
4780+
return false;
47864781

4787-
if (!this->emitGetParam(PT_Ptr, PO.Offset, Ctor))
4788-
return false;
4782+
return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
4783+
this->emitRetVoid(Ctor);
4784+
}
47894785

4790-
return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
4791-
this->emitRetVoid(Ctor);
4792-
}
4786+
InitLinkScope<Emitter> InitScope(this, InitLink::This());
4787+
for (const auto *Init : Ctor->inits()) {
4788+
// Scope needed for the initializers.
4789+
BlockScope<Emitter> Scope(this);
47934790

4794-
InitLinkScope<Emitter> InitScope(this, InitLink::This());
4795-
for (const auto *Init : Ctor->inits()) {
4796-
// Scope needed for the initializers.
4797-
BlockScope<Emitter> Scope(this);
4791+
const Expr *InitExpr = Init->getInit();
4792+
if (const FieldDecl *Member = Init->getMember()) {
4793+
const Record::Field *F = R->getField(Member);
47984794

4799-
const Expr *InitExpr = Init->getInit();
4800-
if (const FieldDecl *Member = Init->getMember()) {
4801-
const Record::Field *F = R->getField(Member);
4795+
if (!emitFieldInitializer(F, F->Offset, InitExpr))
4796+
return false;
4797+
} else if (const Type *Base = Init->getBaseClass()) {
4798+
const auto *BaseDecl = Base->getAsCXXRecordDecl();
4799+
assert(BaseDecl);
48024800

4803-
if (!emitFieldInitializer(F, F->Offset, InitExpr))
4801+
if (Init->isBaseVirtual()) {
4802+
assert(R->getVirtualBase(BaseDecl));
4803+
if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
48044804
return false;
4805-
} else if (const Type *Base = Init->getBaseClass()) {
4806-
const auto *BaseDecl = Base->getAsCXXRecordDecl();
4807-
assert(BaseDecl);
4808-
4809-
if (Init->isBaseVirtual()) {
4810-
assert(R->getVirtualBase(BaseDecl));
4811-
if (!this->emitGetPtrThisVirtBase(BaseDecl, InitExpr))
4812-
return false;
4813-
4814-
} else {
4815-
// Base class initializer.
4816-
// Get This Base and call initializer on it.
4817-
const Record::Base *B = R->getBase(BaseDecl);
4818-
assert(B);
4819-
if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
4820-
return false;
4821-
}
48224805

4823-
if (!this->visitInitializer(InitExpr))
4824-
return false;
4825-
if (!this->emitFinishInitPop(InitExpr))
4806+
} else {
4807+
// Base class initializer.
4808+
// Get This Base and call initializer on it.
4809+
const Record::Base *B = R->getBase(BaseDecl);
4810+
assert(B);
4811+
if (!this->emitGetPtrThisBase(B->Offset, InitExpr))
48264812
return false;
4827-
} else if (const IndirectFieldDecl *IFD = Init->getIndirectMember()) {
4828-
assert(IFD->getChainingSize() >= 2);
4813+
}
48294814

4830-
unsigned NestedFieldOffset = 0;
4831-
const Record::Field *NestedField = nullptr;
4832-
for (const NamedDecl *ND : IFD->chain()) {
4833-
const auto *FD = cast<FieldDecl>(ND);
4834-
const Record *FieldRecord =
4835-
this->P.getOrCreateRecord(FD->getParent());
4836-
assert(FieldRecord);
4815+
if (!this->visitInitializer(InitExpr))
4816+
return false;
4817+
if (!this->emitFinishInitPop(InitExpr))
4818+
return false;
4819+
} else if (const IndirectFieldDecl *IFD = Init->getIndirectMember()) {
4820+
assert(IFD->getChainingSize() >= 2);
48374821

4838-
NestedField = FieldRecord->getField(FD);
4839-
assert(NestedField);
4822+
unsigned NestedFieldOffset = 0;
4823+
const Record::Field *NestedField = nullptr;
4824+
for (const NamedDecl *ND : IFD->chain()) {
4825+
const auto *FD = cast<FieldDecl>(ND);
4826+
const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
4827+
assert(FieldRecord);
48404828

4841-
NestedFieldOffset += NestedField->Offset;
4842-
}
4829+
NestedField = FieldRecord->getField(FD);
48434830
assert(NestedField);
48444831

4845-
if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr))
4846-
return false;
4847-
} else {
4848-
assert(Init->isDelegatingInitializer());
4849-
if (!this->emitThis(InitExpr))
4850-
return false;
4851-
if (!this->visitInitializer(Init->getInit()))
4852-
return false;
4853-
if (!this->emitPopPtr(InitExpr))
4854-
return false;
4832+
NestedFieldOffset += NestedField->Offset;
48554833
}
4834+
assert(NestedField);
48564835

4857-
if (!Scope.destroyLocals())
4836+
if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr))
4837+
return false;
4838+
} else {
4839+
assert(Init->isDelegatingInitializer());
4840+
if (!this->emitThis(InitExpr))
4841+
return false;
4842+
if (!this->visitInitializer(Init->getInit()))
4843+
return false;
4844+
if (!this->emitPopPtr(InitExpr))
48584845
return false;
48594846
}
4847+
4848+
if (!Scope.destroyLocals())
4849+
return false;
48604850
}
48614851

4852+
if (const auto *Body = Ctor->getBody())
4853+
if (!visitStmt(Body))
4854+
return false;
4855+
4856+
return this->emitRetVoid(SourceInfo{});
4857+
}
4858+
4859+
template <class Emitter>
4860+
bool Compiler<Emitter>::visitFunc(const FunctionDecl *F) {
4861+
// Classify the return type.
4862+
ReturnType = this->classify(F->getReturnType());
4863+
4864+
if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(F))
4865+
return this->compileConstructor(Ctor);
4866+
4867+
// Emit custom code if this is a lambda static invoker.
4868+
if (const auto *MD = dyn_cast<CXXMethodDecl>(F);
4869+
MD && MD->isLambdaStaticInvoker())
4870+
return this->emitLambdaStaticInvokerBody(MD);
4871+
4872+
// Regular functions.
48624873
if (const auto *Body = F->getBody())
48634874
if (!visitStmt(Body))
48644875
return false;

clang/lib/AST/Interp/Compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
357357
unsigned collectBaseOffset(const QualType BaseType,
358358
const QualType DerivedType);
359359
bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD);
360+
bool compileConstructor(const CXXConstructorDecl *Ctor);
360361

361362
bool checkLiteralType(const Expr *E);
362363

0 commit comments

Comments
 (0)