Skip to content

Commit e756590

Browse files
Merge remote-tracking branch 'upstream/main' into gh-101657
2 parents 362b39c + cede236 commit e756590

File tree

227 files changed

+6842
-2973
lines changed

Some content is hidden

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

227 files changed

+6842
-2973
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,8 @@ OpenMP Support
920920
``partial`` was an invalid expression. (#GH139267)
921921
- Fixed a crashing bug with ``omp tile sizes`` if the argument to ``sizes`` was
922922
an invalid expression. (#GH139073)
923+
- Fixed a crashing bug with ``omp simd collapse`` if the argument to
924+
``collapse`` was an invalid expression. (#GH138493)
923925
- Fixed a crashing bug with ``omp distribute dist_schedule`` if the argument to
924926
``dist_schedule`` was not strictly positive. (#GH139266)
925927

clang/include/clang/Analysis/CFG.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ class CFGElement {
122122
return (Kind) x;
123123
}
124124

125-
void dumpToStream(llvm::raw_ostream &OS) const;
125+
void dumpToStream(llvm::raw_ostream &OS,
126+
bool TerminateWithNewLine = true) const;
126127

127128
void dump() const {
128129
dumpToStream(llvm::errs());
@@ -695,6 +696,11 @@ class CFGBlock {
695696
void dump() const {
696697
dumpToStream(llvm::errs());
697698
}
699+
700+
void Profile(llvm::FoldingSetNodeID &ID) const {
701+
ID.AddPointer(Parent);
702+
ID.AddInteger(Index);
703+
}
698704
};
699705

700706
template <bool IsReverse, bool IsConst> class ElementRefIterator {
@@ -1190,6 +1196,8 @@ class CFGBlock {
11901196
}
11911197
};
11921198

1199+
using ConstCFGElementRef = CFGBlock::ConstCFGElementRef;
1200+
11931201
/// CFGCallback defines methods that should be called when a logical
11941202
/// operator error is found when building the CFG.
11951203
class CFGCallback {

clang/include/clang/Basic/SourceManager.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,15 @@ class SourceManager : public RefCountedBase<SourceManager> {
15291529
return Filename == "<scratch space>";
15301530
}
15311531

1532+
/// Returns whether \p Loc is located in a built-in or command line source.
1533+
bool isInPredefinedFile(SourceLocation Loc) const {
1534+
PresumedLoc Presumed = getPresumedLoc(Loc);
1535+
if (Presumed.isInvalid())
1536+
return false;
1537+
StringRef Filename(Presumed.getFilename());
1538+
return Filename == "<built-in>" || Filename == "<command line>";
1539+
}
1540+
15321541
/// Returns if a SourceLocation is in a system header.
15331542
bool isInSystemHeader(SourceLocation Loc) const {
15341543
if (Loc.isInvalid())

clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "clang/AST/DeclCXX.h"
2020
#include "clang/StaticAnalyzer/Core/PathSensitive/SValVisitor.h"
2121
#include "llvm/ADT/StringExtras.h"
22+
#include "llvm/Support/raw_ostream.h"
2223

2324
namespace clang {
2425

@@ -29,6 +30,13 @@ class SValExplainer : public FullSValVisitor<SValExplainer, std::string> {
2930
ASTContext &ACtx;
3031
ProgramStateRef State;
3132

33+
std::string printCFGElementRef(ConstCFGElementRef Elem) {
34+
std::string Str;
35+
llvm::raw_string_ostream OS(Str);
36+
Elem->dumpToStream(OS, /*TerminateWithNewLine=*/false);
37+
return Str;
38+
}
39+
3240
std::string printStmt(const Stmt *S) {
3341
std::string Str;
3442
llvm::raw_string_ostream OS(Str);
@@ -114,7 +122,8 @@ class SValExplainer : public FullSValVisitor<SValExplainer, std::string> {
114122

115123
std::string VisitSymbolConjured(const SymbolConjured *S) {
116124
return "symbol of type '" + S->getType().getAsString() +
117-
"' conjured at statement '" + printStmt(S->getStmt()) + "'";
125+
"' conjured at CFG element '" +
126+
printCFGElementRef(S->getCFGElementRef()) + "'";
118127
}
119128

120129
std::string VisitSymbolDerived(const SymbolDerived *S) {

clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,19 @@ ANALYZER_OPTION(
414414
"any target.",
415415
true)
416416

417+
ANALYZER_OPTION(
418+
bool, InlineFunctionsWithAmbiguousLoops, "inline-functions-with-ambiguous-loops",
419+
"If disabled (the default), the analyzer puts functions on a \"do not "
420+
"inline this\" list if it finds an execution path within that function "
421+
"that may potentially perform 'analyzer-max-loop' (= 4 by default) "
422+
"iterations in a loop. (Note that functions that _definitely_ reach the "
423+
"loop limit on some execution path are currently marked as \"do not "
424+
"inline\" even if this option is enabled.) Enabling this option "
425+
"eliminates this (somewhat arbitrary) restriction from the analysis "
426+
"scope, which increases the analysis runtime (on average by ~10%, but "
427+
"a few translation units may see much larger slowdowns).",
428+
false)
429+
417430
//===----------------------------------------------------------------------===//
418431
// Unsigned analyzer options.
419432
//===----------------------------------------------------------------------===//

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ class CheckerContext {
151151
return Pred->getSVal(S);
152152
}
153153

154+
ConstCFGElementRef getCFGElementRef() const { return Eng.getCFGElementRef(); }
155+
154156
/// Returns true if the value of \p E is greater than or equal to \p
155157
/// Val under unsigned comparison.
156158
bool isGreaterOrEqual(const Expr *E, unsigned long long Val);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class ExprEngine {
226226
return (*G.roots_begin())->getLocation().getLocationContext();
227227
}
228228

229-
CFGBlock::ConstCFGElementRef getCFGElementRef() const {
229+
ConstCFGElementRef getCFGElementRef() const {
230230
const CFGBlock *blockPtr = currBldrCtx ? currBldrCtx->getBlock() : nullptr;
231231
return {blockPtr, currStmtIdx};
232232
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ class FunctionSummariesTy {
8181
I->second.MayInline = 0;
8282
}
8383

84-
void markReachedMaxBlockCount(const Decl *D) {
85-
markShouldNotInline(D);
86-
}
87-
8884
std::optional<bool> mayInline(const Decl *D) {
8985
MapTy::const_iterator I = Map.find(D);
9086
if (I != Map.end() && I->second.InlineChecked)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ namespace ento {
2727
/// by the loop body in any iteration.
2828
ProgramStateRef getWidenedLoopState(ProgramStateRef PrevState,
2929
const LocationContext *LCtx,
30-
unsigned BlockCount, const Stmt *LoopStmt);
30+
unsigned BlockCount,
31+
ConstCFGElementRef Elem);
3132

3233
} // end namespace ento
3334
} // end namespace clang

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class ProgramState : public llvm::FoldingSetNode {
313313
/// be triggered by this event.
314314
///
315315
/// \param Regions the set of regions to be invalidated.
316-
/// \param E the expression that caused the invalidation.
316+
/// \param Elem The CFG Element that caused the invalidation.
317317
/// \param BlockCount The number of times the current basic block has been
318318
/// visited.
319319
/// \param CausesPointerEscape the flag is set to true when the invalidation
@@ -325,16 +325,17 @@ class ProgramState : public llvm::FoldingSetNode {
325325
/// \param ITraits information about special handling for particular regions
326326
/// or symbols.
327327
[[nodiscard]] ProgramStateRef
328-
invalidateRegions(ArrayRef<const MemRegion *> Regions, const Stmt *S,
329-
unsigned BlockCount, const LocationContext *LCtx,
330-
bool CausesPointerEscape, InvalidatedSymbols *IS = nullptr,
328+
invalidateRegions(ArrayRef<const MemRegion *> Regions,
329+
ConstCFGElementRef Elem, unsigned BlockCount,
330+
const LocationContext *LCtx, bool CausesPointerEscape,
331+
InvalidatedSymbols *IS = nullptr,
331332
const CallEvent *Call = nullptr,
332333
RegionAndSymbolInvalidationTraits *ITraits = nullptr) const;
333334

334335
[[nodiscard]] ProgramStateRef
335-
invalidateRegions(ArrayRef<SVal> Values, const Stmt *S, unsigned BlockCount,
336-
const LocationContext *LCtx, bool CausesPointerEscape,
337-
InvalidatedSymbols *IS = nullptr,
336+
invalidateRegions(ArrayRef<SVal> Values, ConstCFGElementRef Elem,
337+
unsigned BlockCount, const LocationContext *LCtx,
338+
bool CausesPointerEscape, InvalidatedSymbols *IS = nullptr,
338339
const CallEvent *Call = nullptr,
339340
RegionAndSymbolInvalidationTraits *ITraits = nullptr) const;
340341

0 commit comments

Comments
 (0)