Skip to content

Commit d116379

Browse files
committedJul 17, 2018
[analyzer] Assert that nonloc::SymbolVal always wraps a non-Loc-type symbol.
In the current SVal hierarchy there are multiple ways of representing certain values but few are actually used and expected to be seen by the code. In particular, a value of a symbolic pointer is always represented by a loc::MemRegionVal that wraps a SymbolicRegion that wraps the pointer symbol and never by a nonloc::SymbolVal that wraps that symbol directly. Assert the aforementioned fact. Fix one minor violation of it. Differential Revision: https://reviews.llvm.org/D48205 llvm-svn: 337227
1 parent 0a9969b commit d116379

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed
 

Diff for: ‎clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,14 @@ class Loc : public DefinedSVal {
343343

344344
namespace nonloc {
345345

346-
/// Represents symbolic expression.
346+
/// Represents symbolic expression that isn't a location.
347347
class SymbolVal : public NonLoc {
348348
public:
349349
SymbolVal() = delete;
350-
SymbolVal(SymbolRef sym) : NonLoc(SymbolValKind, sym) { assert(sym); }
350+
SymbolVal(SymbolRef sym) : NonLoc(SymbolValKind, sym) {
351+
assert(sym);
352+
assert(!Loc::isLocType(sym->getType()));
353+
}
351354

352355
SymbolRef getSymbol() const {
353356
return (const SymExpr *) Data;

Diff for: ‎clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ SVal SimpleSValBuilder::simplifySVal(ProgramStateRef State, SVal V) {
12381238

12391239
SVal VisitSymbolData(const SymbolData *S) {
12401240
if (const llvm::APSInt *I =
1241-
SVB.getKnownValue(State, nonloc::SymbolVal(S)))
1241+
SVB.getKnownValue(State, SVB.makeSymbolVal(S)))
12421242
return Loc::isLocType(S->getType()) ? (SVal)SVB.makeIntLocVal(*I)
12431243
: (SVal)SVB.makeIntVal(*I);
12441244
return SVB.makeSymbolVal(S);

0 commit comments

Comments
 (0)
Please sign in to comment.