Skip to content

Commit d0957f9

Browse files
committed
merge main into amd-staging
Revret: b7e4fba Cleanup x86_mmx after removing IR type (llvm#100646) (Reason: dependent on dfeb399) Change-Id: I8e9a9a897b4a44dd5f0a79dd7a630f0051a3f1ad
2 parents a87f347 + 102f322 commit d0957f9

File tree

178 files changed

+10316
-2733
lines changed

Some content is hidden

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

178 files changed

+10316
-2733
lines changed

clang/include/clang/AST/ASTImporter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ class TypeSourceInfo;
258258
FoundDeclsTy findDeclsInToCtx(DeclContext *DC, DeclarationName Name);
259259

260260
void AddToLookupTable(Decl *ToD);
261-
llvm::Error ImportAttrs(Decl *ToD, Decl *FromD);
262261

263262
protected:
264263
/// Can be overwritten by subclasses to implement their own import logic.

clang/include/clang/AST/DeclCXX.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,10 +1188,6 @@ class CXXRecordDecl : public RecordDecl {
11881188
///
11891189
/// \note This does NOT include a check for union-ness.
11901190
bool isEmpty() const { return data().Empty; }
1191-
/// Marks this record as empty. This is used by DWARFASTParserClang
1192-
/// when parsing records with empty fields having [[no_unique_address]]
1193-
/// attribute
1194-
void markEmpty() { data().Empty = true; }
11951191

11961192
void setInitMethod(bool Val) { data().HasInitMethod = Val; }
11971193
bool hasInitMethod() const { return data().HasInitMethod; }

clang/include/clang/Analysis/FlowSensitive/AdornedCFG.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/AST/Decl.h"
1919
#include "clang/AST/Stmt.h"
2020
#include "clang/Analysis/CFG.h"
21+
#include "clang/Analysis/FlowSensitive/ASTOps.h"
2122
#include "llvm/ADT/BitVector.h"
2223
#include "llvm/ADT/DenseMap.h"
2324
#include "llvm/Support/Error.h"
@@ -27,6 +28,24 @@
2728
namespace clang {
2829
namespace dataflow {
2930

31+
namespace internal {
32+
class StmtToBlockMap {
33+
public:
34+
StmtToBlockMap(const CFG &Cfg);
35+
36+
const CFGBlock *lookup(const Stmt &S) const {
37+
return StmtToBlock.lookup(&ignoreCFGOmittedNodes(S));
38+
}
39+
40+
const llvm::DenseMap<const Stmt *, const CFGBlock *> &getMap() const {
41+
return StmtToBlock;
42+
}
43+
44+
private:
45+
llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock;
46+
};
47+
} // namespace internal
48+
3049
/// Holds CFG with additional information derived from it that is needed to
3150
/// perform dataflow analysis.
3251
class AdornedCFG {
@@ -49,8 +68,17 @@ class AdornedCFG {
4968
const CFG &getCFG() const { return *Cfg; }
5069

5170
/// Returns a mapping from statements to basic blocks that contain them.
71+
/// Deprecated. Use `blockForStmt()` instead (which prevents the potential
72+
/// error of forgetting to call `ignoreCFGOmittedNodes()` on the statement to
73+
/// look up).
5274
const llvm::DenseMap<const Stmt *, const CFGBlock *> &getStmtToBlock() const {
53-
return StmtToBlock;
75+
return StmtToBlock.getMap();
76+
}
77+
78+
/// Returns the basic block that contains `S`, or null if no basic block
79+
/// containing `S` is found.
80+
const CFGBlock *blockForStmt(const Stmt &S) const {
81+
return StmtToBlock.lookup(S);
5482
}
5583

5684
/// Returns whether `B` is reachable from the entry block.
@@ -73,8 +101,7 @@ class AdornedCFG {
73101
private:
74102
AdornedCFG(
75103
const Decl &D, std::unique_ptr<CFG> Cfg,
76-
llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock,
77-
llvm::BitVector BlockReachable,
104+
internal::StmtToBlockMap StmtToBlock, llvm::BitVector BlockReachable,
78105
llvm::DenseSet<const CFGBlock *> ContainsExprConsumedInDifferentBlock)
79106
: ContainingDecl(D), Cfg(std::move(Cfg)),
80107
StmtToBlock(std::move(StmtToBlock)),
@@ -85,7 +112,7 @@ class AdornedCFG {
85112
/// The `Decl` containing the statement used to construct the CFG.
86113
const Decl &ContainingDecl;
87114
std::unique_ptr<CFG> Cfg;
88-
llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock;
115+
internal::StmtToBlockMap StmtToBlock;
89116
llvm::BitVector BlockReachable;
90117
llvm::DenseSet<const CFGBlock *> ContainsExprConsumedInDifferentBlock;
91118
};

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ def err_function_needs_feature : Error<
288288
let CategoryName = "Codegen ABI Check" in {
289289
def err_function_always_inline_attribute_mismatch : Error<
290290
"always_inline function %1 and its caller %0 have mismatching %2 attributes">;
291+
def warn_function_always_inline_attribute_mismatch : Warning<
292+
"always_inline function %1 and its caller %0 have mismatching %2 attributes, "
293+
"inlining may change runtime behaviour">, InGroup<AArch64SMEAttributes>;
291294
def err_function_always_inline_new_za : Error<
292295
"always_inline function %0 has new za state">;
293296

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,15 @@ def Wsystem_headers_in_module_EQ : Joined<["-"], "Wsystem-headers-in-module=">,
980980
HelpText<"Enable -Wsystem-headers when building <module>">,
981981
MarshallingInfoStringVector<DiagnosticOpts<"SystemHeaderWarningsModules">>;
982982
def Wdeprecated : Flag<["-"], "Wdeprecated">, Group<W_Group>,
983-
Visibility<[ClangOption, CC1Option]>,
983+
Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
984984
HelpText<"Enable warnings for deprecated constructs and define __DEPRECATED">;
985985
def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group<W_Group>,
986986
Visibility<[ClangOption, CC1Option]>;
987987
defm invalid_constexpr : BoolWOption<"invalid-constexpr",
988988
LangOpts<"CheckConstexprFunctionBodies">,
989989
Default<!strconcat("!", cpp23.KeyPath)>,
990-
NegFlag<SetFalse, [], [ClangOption, CC1Option], "Disable">,
991-
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Enable">,
990+
NegFlag<SetFalse, [HelpHidden], [ClangOption, CC1Option], "Disable">,
991+
PosFlag<SetTrue, [HelpHidden], [ClangOption, CC1Option], "Enable">,
992992
BothFlags<[], [ClangOption, CC1Option], " checking of constexpr function bodies for validity within a constant expression context">>;
993993
def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, FlangOption]>,
994994
Flags<[LinkerInput, RenderAsInput]>,

clang/lib/AST/ASTImporter.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4179,12 +4179,6 @@ ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
41794179
D->getInClassInitStyle()))
41804180
return ToField;
41814181

4182-
// We need [[no_unqiue_address]] attributes to be added to FieldDecl, before
4183-
// we add fields in CXXRecordDecl::addedMember, otherwise record will be
4184-
// marked as having non-zero size.
4185-
Err = Importer.ImportAttrs(ToField, D);
4186-
if (Err)
4187-
return std::move(Err);
41884182
ToField->setAccess(D->getAccess());
41894183
ToField->setLexicalDeclContext(LexicalDC);
41904184
ToField->setImplicit(D->isImplicit());
@@ -9399,19 +9393,6 @@ TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) {
93999393
return FromDPos->second->getTranslationUnitDecl();
94009394
}
94019395

9402-
Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) {
9403-
if (!FromD->hasAttrs() || ToD->hasAttrs())
9404-
return Error::success();
9405-
for (const Attr *FromAttr : FromD->getAttrs()) {
9406-
auto ToAttrOrErr = Import(FromAttr);
9407-
if (ToAttrOrErr)
9408-
ToD->addAttr(*ToAttrOrErr);
9409-
else
9410-
return ToAttrOrErr.takeError();
9411-
}
9412-
return Error::success();
9413-
}
9414-
94159396
Expected<Decl *> ASTImporter::Import(Decl *FromD) {
94169397
if (!FromD)
94179398
return nullptr;
@@ -9545,8 +9526,15 @@ Expected<Decl *> ASTImporter::Import(Decl *FromD) {
95459526
}
95469527
// Make sure that ImportImpl registered the imported decl.
95479528
assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9548-
if (auto Error = ImportAttrs(ToD, FromD))
9549-
return std::move(Error);
9529+
9530+
if (FromD->hasAttrs())
9531+
for (const Attr *FromAttr : FromD->getAttrs()) {
9532+
auto ToAttrOrErr = Import(FromAttr);
9533+
if (ToAttrOrErr)
9534+
ToD->addAttr(*ToAttrOrErr);
9535+
else
9536+
return ToAttrOrErr.takeError();
9537+
}
95509538

95519539
// Notify subclasses.
95529540
Imported(FromD, ToD);

clang/lib/Analysis/FlowSensitive/AdornedCFG.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "clang/AST/Decl.h"
1717
#include "clang/AST/Stmt.h"
1818
#include "clang/Analysis/CFG.h"
19+
#include "clang/Analysis/FlowSensitive/ASTOps.h"
1920
#include "llvm/ADT/BitVector.h"
2021
#include "llvm/ADT/DenseMap.h"
2122
#include "llvm/Support/Error.h"
@@ -96,16 +97,15 @@ static llvm::BitVector findReachableBlocks(const CFG &Cfg) {
9697

9798
static llvm::DenseSet<const CFGBlock *>
9899
buildContainsExprConsumedInDifferentBlock(
99-
const CFG &Cfg,
100-
const llvm::DenseMap<const Stmt *, const CFGBlock *> &StmtToBlock) {
100+
const CFG &Cfg, const internal::StmtToBlockMap &StmtToBlock) {
101101
llvm::DenseSet<const CFGBlock *> Result;
102102

103103
auto CheckChildExprs = [&Result, &StmtToBlock](const Stmt *S,
104104
const CFGBlock *Block) {
105105
for (const Stmt *Child : S->children()) {
106106
if (!isa_and_nonnull<Expr>(Child))
107107
continue;
108-
const CFGBlock *ChildBlock = StmtToBlock.lookup(Child);
108+
const CFGBlock *ChildBlock = StmtToBlock.lookup(*Child);
109109
if (ChildBlock != Block)
110110
Result.insert(ChildBlock);
111111
}
@@ -126,6 +126,13 @@ buildContainsExprConsumedInDifferentBlock(
126126
return Result;
127127
}
128128

129+
namespace internal {
130+
131+
StmtToBlockMap::StmtToBlockMap(const CFG &Cfg)
132+
: StmtToBlock(buildStmtToBasicBlockMap(Cfg)) {}
133+
134+
} // namespace internal
135+
129136
llvm::Expected<AdornedCFG> AdornedCFG::build(const FunctionDecl &Func) {
130137
if (!Func.doesThisDeclarationHaveABody())
131138
return llvm::createStringError(
@@ -166,8 +173,7 @@ llvm::Expected<AdornedCFG> AdornedCFG::build(const Decl &D, Stmt &S,
166173
std::make_error_code(std::errc::invalid_argument),
167174
"CFG::buildCFG failed");
168175

169-
llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock =
170-
buildStmtToBasicBlockMap(*Cfg);
176+
internal::StmtToBlockMap StmtToBlock(*Cfg);
171177

172178
llvm::BitVector BlockReachable = findReachableBlocks(*Cfg);
173179

clang/lib/Analysis/FlowSensitive/Transfer.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@ namespace clang {
4040
namespace dataflow {
4141

4242
const Environment *StmtToEnvMap::getEnvironment(const Stmt &S) const {
43-
auto BlockIt = ACFG.getStmtToBlock().find(&ignoreCFGOmittedNodes(S));
44-
if (BlockIt == ACFG.getStmtToBlock().end()) {
43+
const CFGBlock *Block = ACFG.blockForStmt(S);
44+
if (Block == nullptr) {
4545
assert(false);
46-
// Return null to avoid dereferencing the end iterator in non-assert builds.
4746
return nullptr;
4847
}
49-
if (!ACFG.isBlockReachable(*BlockIt->getSecond()))
48+
if (!ACFG.isBlockReachable(*Block))
5049
return nullptr;
51-
if (BlockIt->getSecond()->getBlockID() == CurBlockID)
50+
if (Block->getBlockID() == CurBlockID)
5251
return &CurState.Env;
53-
const auto &State = BlockToState[BlockIt->getSecond()->getBlockID()];
52+
const auto &State = BlockToState[Block->getBlockID()];
5453
if (!(State))
5554
return nullptr;
5655
return &State->Env;

clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,11 @@ computeBlockInputState(const CFGBlock &Block, AnalysisContext &AC) {
243243
// See `NoreturnDestructorTest` for concrete examples.
244244
if (Block.succ_begin()->getReachableBlock() != nullptr &&
245245
Block.succ_begin()->getReachableBlock()->hasNoReturnElement()) {
246-
auto &StmtToBlock = AC.ACFG.getStmtToBlock();
247-
auto StmtBlock = StmtToBlock.find(Block.getTerminatorStmt());
248-
assert(StmtBlock != StmtToBlock.end());
249-
llvm::erase(Preds, StmtBlock->getSecond());
246+
const CFGBlock *StmtBlock = nullptr;
247+
if (const Stmt *Terminator = Block.getTerminatorStmt())
248+
StmtBlock = AC.ACFG.blockForStmt(*Terminator);
249+
assert(StmtBlock != nullptr);
250+
llvm::erase(Preds, StmtBlock);
250251
}
251252
}
252253

clang/lib/Analysis/LiveVariables.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,22 @@ static void AddLiveExpr(llvm::ImmutableSet<const Expr *> &Set,
214214
Set = F.add(Set, LookThroughExpr(E));
215215
}
216216

217+
/// Add as a live expression all individual conditions in a logical expression.
218+
/// For example, for the expression:
219+
/// "(a < b) || (c && d && ((e || f) != (g && h)))"
220+
/// the following expressions will be added as live:
221+
/// "a < b", "c", "d", "((e || f) != (g && h))"
222+
static void AddAllConditionalTerms(llvm::ImmutableSet<const Expr *> &Set,
223+
llvm::ImmutableSet<const Expr *>::Factory &F,
224+
const Expr *Cond) {
225+
AddLiveExpr(Set, F, Cond);
226+
if (auto const *BO = dyn_cast<BinaryOperator>(Cond->IgnoreParens());
227+
BO && BO->isLogicalOp()) {
228+
AddAllConditionalTerms(Set, F, BO->getLHS());
229+
AddAllConditionalTerms(Set, F, BO->getRHS());
230+
}
231+
}
232+
217233
void TransferFunctions::Visit(Stmt *S) {
218234
if (observer)
219235
observer->observeStmt(S, currentBlock, val);
@@ -313,7 +329,27 @@ void TransferFunctions::Visit(Stmt *S) {
313329
AddLiveExpr(val.liveExprs, LV.ESetFact, cast<ForStmt>(S)->getCond());
314330
return;
315331
}
316-
332+
case Stmt::ConditionalOperatorClass: {
333+
// Keep not only direct children alive, but also all the short-circuited
334+
// parts of the condition. Short-circuiting evaluation may cause the
335+
// conditional operator evaluation to skip the evaluation of the entire
336+
// condtion expression, so the value of the entire condition expression is
337+
// never computed.
338+
//
339+
// This makes a difference when we compare exploded nodes coming from true
340+
// and false expressions with no side effects: the only difference in the
341+
// state is the value of (part of) the condition.
342+
//
343+
// BinaryConditionalOperatorClass ('x ?: y') is not affected because it
344+
// explicitly calculates the value of the entire condition expression (to
345+
// possibly use as a value for the "true expr") even if it is
346+
// short-circuited.
347+
auto const *CO = cast<ConditionalOperator>(S);
348+
AddAllConditionalTerms(val.liveExprs, LV.ESetFact, CO->getCond());
349+
AddLiveExpr(val.liveExprs, LV.ESetFact, CO->getTrueExpr());
350+
AddLiveExpr(val.liveExprs, LV.ESetFact, CO->getFalseExpr());
351+
return;
352+
}
317353
}
318354

319355
// HACK + FIXME: What is this? One could only guess that this is an attempt to

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,12 @@ CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method,
19931993
if (Method->isStatic())
19941994
return cast_or_null<llvm::DISubroutineType>(
19951995
getOrCreateType(QualType(Func, 0), Unit));
1996-
return getOrCreateInstanceMethodType(Method->getThisType(), Func, Unit);
1996+
1997+
QualType ThisType;
1998+
if (!Method->hasCXXExplicitFunctionObjectParameter())
1999+
ThisType = Method->getThisType();
2000+
2001+
return getOrCreateInstanceMethodType(ThisType, Func, Unit);
19972002
}
19982003

19992004
llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
@@ -2025,27 +2030,31 @@ llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
20252030
Elts.push_back(Args[0]);
20262031

20272032
// "this" pointer is always first argument.
2028-
const CXXRecordDecl *RD = ThisPtr->getPointeeCXXRecordDecl();
2029-
if (isa<ClassTemplateSpecializationDecl>(RD)) {
2030-
// Create pointer type directly in this case.
2031-
const PointerType *ThisPtrTy = cast<PointerType>(ThisPtr);
2032-
uint64_t Size = CGM.getContext().getTypeSize(ThisPtrTy);
2033-
auto Align = getTypeAlignIfRequired(ThisPtrTy, CGM.getContext());
2034-
llvm::DIType *PointeeType =
2035-
getOrCreateType(ThisPtrTy->getPointeeType(), Unit);
2036-
llvm::DIType *ThisPtrType =
2037-
DBuilder.createPointerType(PointeeType, Size, Align);
2038-
TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
2039-
// TODO: This and the artificial type below are misleading, the
2040-
// types aren't artificial the argument is, but the current
2041-
// metadata doesn't represent that.
2042-
ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
2043-
Elts.push_back(ThisPtrType);
2044-
} else {
2045-
llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
2046-
TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
2047-
ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
2048-
Elts.push_back(ThisPtrType);
2033+
// ThisPtr may be null if the member function has an explicit 'this'
2034+
// parameter.
2035+
if (!ThisPtr.isNull()) {
2036+
const CXXRecordDecl *RD = ThisPtr->getPointeeCXXRecordDecl();
2037+
if (isa<ClassTemplateSpecializationDecl>(RD)) {
2038+
// Create pointer type directly in this case.
2039+
const PointerType *ThisPtrTy = cast<PointerType>(ThisPtr);
2040+
uint64_t Size = CGM.getContext().getTypeSize(ThisPtrTy);
2041+
auto Align = getTypeAlignIfRequired(ThisPtrTy, CGM.getContext());
2042+
llvm::DIType *PointeeType =
2043+
getOrCreateType(ThisPtrTy->getPointeeType(), Unit);
2044+
llvm::DIType *ThisPtrType =
2045+
DBuilder.createPointerType(PointeeType, Size, Align);
2046+
TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
2047+
// TODO: This and the artificial type below are misleading, the
2048+
// types aren't artificial the argument is, but the current
2049+
// metadata doesn't represent that.
2050+
ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
2051+
Elts.push_back(ThisPtrType);
2052+
} else {
2053+
llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
2054+
TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
2055+
ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
2056+
Elts.push_back(ThisPtrType);
2057+
}
20492058
}
20502059

20512060
// Copy rest of the arguments.

clang/lib/CodeGen/Targets/AArch64.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,10 @@ void AArch64TargetCodeGenInfo::checkFunctionCallABIStreaming(
883883

884884
if (!CalleeIsStreamingCompatible &&
885885
(CallerIsStreaming != CalleeIsStreaming || CallerIsStreamingCompatible))
886-
CGM.getDiags().Report(CallLoc,
887-
diag::err_function_always_inline_attribute_mismatch)
886+
CGM.getDiags().Report(
887+
CallLoc, CalleeIsStreaming
888+
? diag::err_function_always_inline_attribute_mismatch
889+
: diag::warn_function_always_inline_attribute_mismatch)
888890
<< Caller->getDeclName() << Callee->getDeclName() << "streaming";
889891
if (auto *NewAttr = Callee->getAttr<ArmNewAttr>())
890892
if (NewAttr->isNewZA())

0 commit comments

Comments
 (0)