Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from llvm:main #768

Merged
merged 36 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a5f0054
[ORC] Update LinkGraph unit tests for API change in 75404e9ef88.
lhames Sep 26, 2022
a6d699b
[LoongArch] Add codegen support for strict_fsetccs and any_fsetcc
gonglingqin Sep 26, 2022
80c698d
[ADT] Use std::conditional_t (NFC)
kazutakahirata Sep 26, 2022
06b1e5f
[llvm] Use std::underlying_type_t (NFC)
kazutakahirata Sep 26, 2022
e2398a4
[Analysis] Introduce getStaticBonusApplied (NFC)
kazutakahirata Sep 26, 2022
9c8abbf
[mlir][Arithmetic] Support commutative canonicalization for continuou…
Sep 20, 2022
730ae80
[MLIR] Expose `getAsValues` in `StaticValueUtils.h` (NFC)
chelini Sep 25, 2022
a3df255
[mlir][Bazel] Port afb0b21f24adecfa0b302c79366980453b15ba7b
akuegel Sep 26, 2022
ec8f08c
[mlir][Bazel] Port 730ae80d3e1c47f93f725acb2d37f06fcba06953
akuegel Sep 26, 2022
b4cc363
[mlir][Bazel] Port 730ae80d3e1c47f93f725acb2d37f06fcba06953 part 2.
akuegel Sep 26, 2022
939c5cf
[MLIR] Migrate MemRef -> LLVM conversion pass to the auto-generated c…
mscuttari Sep 25, 2022
941d122
Revert "[MLIR] Expose `getAsValues` in `StaticValueUtils.h` (NFC)"
chelini Sep 26, 2022
a096164
Revert "[mlir][Bazel] Port 730ae80d3e1c47f93f725acb2d37f06fcba06953 p…
akuegel Sep 26, 2022
37bd099
[LLD][COFF] Fix absolute & synthetic symbols in COFF symbol table
alvinhochun Sep 26, 2022
be55829
[llvm-readobj][COFF] Print forwarder export symbols correctly
alvinhochun Sep 26, 2022
8a3597d
[lldb] Fix CommandInterpreter::DidProcessStopAbnormally() with multip…
mstorsjo Sep 16, 2022
585010b
Revert "[mlir][Bazel] Port 730ae80d3e1c47f93f725acb2d37f06fcba06953"
akuegel Sep 26, 2022
95597e9
[mlir] Fix typo in parameter name annotation.
akuegel Sep 26, 2022
5dcd6af
[mlir] Apply ClangTidyLegacy finding.
akuegel Sep 26, 2022
e66345d
[clang-tidy] adjust treating of array-of-pointers when 'AnalyzePointe…
JonasToth Sep 25, 2022
bebc969
[AArch64] Enable FeatureFuseAdrpAdd for all Arm cpus
davemgreen Sep 26, 2022
75e90ea
Fix MSVC "not all control paths return a value" warning. NFCI.
RKSimon Sep 26, 2022
4ff836a
[analyzer] Pass correct bldrCtx to computeObjectUnderConstruction
Sep 26, 2022
a412e9c
[ARM] Enable and/cmp0 folding - precommit test
momchil-velikov Sep 26, 2022
6602110
[ARM] Enable and/cmp0 folding
momchil-velikov Sep 26, 2022
0e91241
[LLDB] Add an llvm::Optional version of GetRegisterInfo
DavidSpickett Sep 23, 2022
4f1c124
[mlir] Add IteratorType enum to StructuredOpsUtils.
olegshyshkov Sep 26, 2022
9f97577
[LoopDistribute] Add LAA invalidation test for #50940.
fhahn Sep 26, 2022
91babd3
Update the status of a few more C99 DRs
AaronBallman Sep 26, 2022
8a55daf
[libc][NFC] introduce inline_bzero
gchatelet Sep 26, 2022
2188cf9
[libc][NFC] Remove new framework, a simpler one is coming
gchatelet Sep 26, 2022
aec908f
[libc][NFC] Move bzero_inline to separate file
gchatelet Sep 26, 2022
76c76e9
[VE] Support smax/smin
kaz7 Sep 24, 2022
ab3779a
[MustExecute] Add additional test for PR57780 (NFC)
nikic Sep 26, 2022
1cef30b
[VE] Disable automatic maxnum/minnum selection
kaz7 Sep 24, 2022
5ac8cc6
[flang] Lowers calls to procedure with CONTIGUOUS assumed shape dummies
jeanPerier Sep 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"

#include <iostream>

using namespace clang::ast_matchers;

namespace clang {
Expand Down Expand Up @@ -132,6 +130,12 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
VC = VariableCategory::Reference;
if (Variable->getType()->isPointerType())
VC = VariableCategory::Pointer;
if (Variable->getType()->isArrayType()) {
if (const auto *ArrayT = dyn_cast<ArrayType>(Variable->getType())) {
if (ArrayT->getElementType()->isPointerType())
VC = VariableCategory::Pointer;
}
}

// Each variable can only be in one category: Value, Pointer, Reference.
// Analysis can be controlled for every category.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,65 @@ void potential_const_pointer() {
double *p_local0 = &np_local0[1];
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double *' can be declared 'const'
// CHECK-FIXES: double *const p_local0

using doublePtr = double*;
using doubleArray = double[15];
doubleArray np_local1;
doublePtr p_local1 = &np_local1[0];
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'doublePtr' (aka 'double *') can be declared 'const'
// CHECK-FIXES: doublePtr const p_local1
}

void range_for() {
int np_local0[2] = {1, 2};
int *p_local0[2] = {&np_local0[0], &np_local0[1]};
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int *[2]' can be declared 'const'
// CHECK-FIXES: int *const p_local0[2]
for (const int *p_local1 : p_local0) {
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: variable 'p_local1' of type 'const int *' can be declared 'const'
// CHECK-FIXES: for (const int *const p_local1 : p_local0)
}

int *p_local2[2] = {nullptr, nullptr};
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local2' of type 'int *[2]' can be declared 'const'
// CHECK-FIXES: int *const p_local2[2]
for (const auto *con_ptr : p_local2) {
}

}

template <typename T>
struct SmallVectorBase {
T data[4];
void push_back(const T &el) {}
int size() const { return 4; }
T *begin() { return data; }
const T *begin() const { return data; }
T *end() { return data + 4; }
const T *end() const { return data + 4; }
};

template <typename T>
struct SmallVector : SmallVectorBase<T> {};

template <class T>
void EmitProtocolMethodList(T &&Methods) {
// Note: If the template is uninstantiated the analysis does not figure out,
// that p_local0 could be const. Not sure why, but probably bails because
// some expressions are type-dependent.
SmallVector<const int *> p_local0;
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'SmallVector<const int *>' can be declared 'const'
// CHECK-FIXES: SmallVector<const int *> const p_local0
SmallVector<const int *> np_local0;
for (const auto *I : Methods) {
if (I == nullptr)
np_local0.push_back(I);
}
p_local0.size();
}
void instantiate() {
int *p_local0[4] = {nullptr, nullptr, nullptr, nullptr};
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int *[4]' can be declared 'const'
// CHECK-FIXES: int *const p_local0[4]
EmitProtocolMethodList(p_local0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -526,18 +526,13 @@ void range_for() {
// CHECK-FIXES: int const p_local1[2]
for (const int &const_ref : p_local1) {
}
}

int *p_local2[2] = {&np_local0[0], &np_local0[1]};
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local2' of type 'int *[2]' can be declared 'const'
// CHECK-FIXES: int *const p_local2[2]
for (const int *con_ptr : p_local2) {
}

int *p_local3[2] = {nullptr, nullptr};
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local3' of type 'int *[2]' can be declared 'const'
// CHECK-FIXES: int *const p_local3[2]
for (const auto *con_ptr : p_local3) {
}
void arrays_of_pointers_are_ignored() {
int *np_local0[2] = {nullptr, nullptr};

using intPtr = int*;
intPtr np_local1[2] = {nullptr, nullptr};
}

inline void *operator new(decltype(sizeof(void *)), void *p) { return p; }
Expand Down Expand Up @@ -908,41 +903,6 @@ void vlas() {
sizeof(int[++N]);
}

template <typename T>
struct SmallVectorBase {
T data[4];
void push_back(const T &el) {}
int size() const { return 4; }
T *begin() { return data; }
const T *begin() const { return data; }
T *end() { return data + 4; }
const T *end() const { return data + 4; }
};

template <typename T>
struct SmallVector : SmallVectorBase<T> {};

template <class T>
void EmitProtocolMethodList(T &&Methods) {
// Note: If the template is uninstantiated the analysis does not figure out,
// that p_local0 could be const. Not sure why, but probably bails because
// some expressions are type-dependent.
SmallVector<const int *> p_local0;
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'SmallVector<const int *>' can be declared 'const'
// CHECK-FIXES: SmallVector<const int *> const p_local0
SmallVector<const int *> np_local0;
for (const auto *I : Methods) {
if (I == nullptr)
np_local0.push_back(I);
}
p_local0.size();
}
void instantiate() {
int *p_local0[4] = {nullptr, nullptr, nullptr, nullptr};
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int *[4]' can be declared 'const'
// CHECK-FIXES: int *const p_local0[4]
EmitProtocolMethodList(p_local0);
}
struct base {
int member;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,14 @@ struct NodeBuilderContext {
const CFGBlock *Block;
const LocationContext *LC;

NodeBuilderContext(const CoreEngine &E, const CFGBlock *B,
const LocationContext *L)
: Eng(E), Block(B), LC(L) {
assert(B);
}

NodeBuilderContext(const CoreEngine &E, const CFGBlock *B, ExplodedNode *N)
: Eng(E), Block(B), LC(N->getLocationContext()) { assert(B); }
: NodeBuilderContext(E, B, N->getLocationContext()) {}

/// Return the CFGBlock associated with this builder.
const CFGBlock *getBlock() const { return Block; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ class ExprEngine {
/// A multi-dimensional array is also a continuous memory location in a
/// row major order, so for arr[0][0] Idx is 0 and for arr[2][2] Idx is 8.
SVal computeObjectUnderConstruction(const Expr *E, ProgramStateRef State,
const NodeBuilderContext *BldrCtx,
const LocationContext *LCtx,
const ConstructionContext *CC,
EvalCallOptions &CallOpts,
Expand All @@ -748,13 +749,13 @@ class ExprEngine {

/// A convenient wrapper around computeObjectUnderConstruction
/// and updateObjectsUnderConstruction.
std::pair<ProgramStateRef, SVal>
handleConstructionContext(const Expr *E, ProgramStateRef State,
const LocationContext *LCtx,
const ConstructionContext *CC,
EvalCallOptions &CallOpts, unsigned Idx = 0) {
std::pair<ProgramStateRef, SVal> handleConstructionContext(
const Expr *E, ProgramStateRef State, const NodeBuilderContext *BldrCtx,
const LocationContext *LCtx, const ConstructionContext *CC,
EvalCallOptions &CallOpts, unsigned Idx = 0) {

SVal V = computeObjectUnderConstruction(E, State, LCtx, CC, CallOpts, Idx);
SVal V = computeObjectUnderConstruction(E, State, BldrCtx, LCtx, CC,
CallOpts, Idx);
State = updateObjectsUnderConstruction(V, E, State, LCtx, CC, CallOpts);

return std::make_pair(State, V);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ CGDebugInfo::computeChecksum(FileID FID, SmallString<64> &Checksum) const {
llvm::toHex(llvm::SHA256::hash(Data), /*LowerCase=*/true, Checksum);
return llvm::DIFile::CSK_SHA256;
}
llvm_unreachable("Unhandled DebugSrcHashKind enum");
}

Optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM,
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Core/CallEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ CallEvent::getReturnValueUnderConstruction() const {

EvalCallOptions CallOpts;
ExprEngine &Engine = getState()->getStateManager().getOwningEngine();
SVal RetVal =
Engine.computeObjectUnderConstruction(getOriginExpr(), getState(),
getLocationContext(), CC, CallOpts);
SVal RetVal = Engine.computeObjectUnderConstruction(
getOriginExpr(), getState(), &Engine.getBuilderContext(),
getLocationContext(), CC, CallOpts);
return RetVal;
}

Expand Down
25 changes: 17 additions & 8 deletions clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,15 @@ SVal ExprEngine::makeElementRegion(ProgramStateRef State, SVal LValue,
return LValue;
}

// In case when the prvalue is returned from the function (kind is one of
// SimpleReturnedValueKind, CXX17ElidedCopyReturnedValueKind), then
// it's materialization happens in context of the caller.
// We pass BldrCtx explicitly, as currBldrCtx always refers to callee's context.
SVal ExprEngine::computeObjectUnderConstruction(
const Expr *E, ProgramStateRef State, const LocationContext *LCtx,
const ConstructionContext *CC, EvalCallOptions &CallOpts, unsigned Idx) {
const Expr *E, ProgramStateRef State, const NodeBuilderContext *BldrCtx,
const LocationContext *LCtx, const ConstructionContext *CC,
EvalCallOptions &CallOpts, unsigned Idx) {

SValBuilder &SVB = getSValBuilder();
MemRegionManager &MRMgr = SVB.getRegionManager();
ASTContext &ACtx = SVB.getContext();
Expand Down Expand Up @@ -210,8 +216,11 @@ SVal ExprEngine::computeObjectUnderConstruction(
CallerLCtx = CallerLCtx->getParent();
assert(!isa<BlockInvocationContext>(CallerLCtx));
}

NodeBuilderContext CallerBldrCtx(getCoreEngine(),
SFC->getCallSiteBlock(), CallerLCtx);
return computeObjectUnderConstruction(
cast<Expr>(SFC->getCallSite()), State, CallerLCtx,
cast<Expr>(SFC->getCallSite()), State, &CallerBldrCtx, CallerLCtx,
RTC->getConstructionContext(), CallOpts);
} else {
// We are on the top frame of the analysis. We do not know where is the
Expand Down Expand Up @@ -251,7 +260,7 @@ SVal ExprEngine::computeObjectUnderConstruction(
EvalCallOptions PreElideCallOpts = CallOpts;

SVal V = computeObjectUnderConstruction(
TCC->getConstructorAfterElision(), State, LCtx,
TCC->getConstructorAfterElision(), State, BldrCtx, LCtx,
TCC->getConstructionContextAfterElision(), CallOpts);

// FIXME: This definition of "copy elision has not failed" is unreliable.
Expand Down Expand Up @@ -319,7 +328,7 @@ SVal ExprEngine::computeObjectUnderConstruction(
CallEventManager &CEMgr = getStateManager().getCallEventManager();
auto getArgLoc = [&](CallEventRef<> Caller) -> Optional<SVal> {
const LocationContext *FutureSFC =
Caller->getCalleeStackFrame(currBldrCtx->blockCount());
Caller->getCalleeStackFrame(BldrCtx->blockCount());
// Return early if we are unable to reliably foresee
// the future stack frame.
if (!FutureSFC)
Expand All @@ -338,7 +347,7 @@ SVal ExprEngine::computeObjectUnderConstruction(
// because this-argument is implemented as a normal argument in
// operator call expressions but not in operator declarations.
const TypedValueRegion *TVR = Caller->getParameterLocation(
*Caller->getAdjustedParameterIndex(Idx), currBldrCtx->blockCount());
*Caller->getAdjustedParameterIndex(Idx), BldrCtx->blockCount());
if (!TVR)
return None;

Expand Down Expand Up @@ -643,8 +652,8 @@ void ExprEngine::handleConstructor(const Expr *E,
}

// The target region is found from construction context.
std::tie(State, Target) =
handleConstructionContext(CE, State, LCtx, CC, CallOpts, Idx);
std::tie(State, Target) = handleConstructionContext(
CE, State, currBldrCtx, LCtx, CC, CallOpts, Idx);
break;
}
case CXXConstructExpr::CK_VirtualBase: {
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ ProgramStateRef ExprEngine::bindReturnValue(const CallEvent &Call,
SVal Target;
assert(RTC->getStmt() == Call.getOriginExpr());
EvalCallOptions CallOpts; // FIXME: We won't really need those.
std::tie(State, Target) =
handleConstructionContext(Call.getOriginExpr(), State, LCtx,
RTC->getConstructionContext(), CallOpts);
std::tie(State, Target) = handleConstructionContext(
Call.getOriginExpr(), State, currBldrCtx, LCtx,
RTC->getConstructionContext(), CallOpts);
const MemRegion *TargetR = Target.getAsRegion();
assert(TargetR);
// Invalidate the region so that it didn't look uninitialized. If this is
Expand Down
29 changes: 29 additions & 0 deletions clang/test/Analysis/copy-elision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#endif

void clang_analyzer_eval(bool);
void clang_analyzer_dump(int);

namespace variable_functional_cast_crash {

Expand Down Expand Up @@ -418,3 +419,31 @@ void test_copy_elision() {
}

} // namespace address_vector_tests

namespace arg_directly_from_return_in_loop {

struct Result {
int value;
};

Result create() {
return Result{10};
}

int accessValue(Result r) {
return r.value;
}

void test() {
for (int i = 0; i < 3; ++i) {
int v = accessValue(create());
if (i == 0) {
clang_analyzer_dump(v); // expected-warning {{10 S32b}}
} else {
clang_analyzer_dump(v); // expected-warning {{10 S32b}}
// was {{reg_${{[0-9]+}}<int r.value> }} for C++11
}
}
}

} // namespace arg_directly_from_return_in_loop
Loading