Skip to content

Commit f0f5dfd

Browse files
authored
Merge branch 'main' into fix/163224
2 parents 253af19 + c7a9be8 commit f0f5dfd

File tree

239 files changed

+4773
-3049
lines changed

Some content is hidden

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

239 files changed

+4773
-3049
lines changed

clang/Maintainers.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ Clang static analyzer
147147
148148
| Balázs Benics
149149
| benicsbalazs\@gmail.com (email), steakhal (Phabricator), steakhal (GitHub)
150-
| balazs.benics\@sonarsource.com (email), balazs-benics-sonarsource (GitHub)
151150
152151
Compiler options
153152
~~~~~~~~~~~~~~~~

clang/docs/analyzer/checkers.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ as error. Specifically on x86/x86-64 target if the pointer address space is
198198
dereference is not defined as error. See `X86/X86-64 Language Extensions
199199
<https://clang.llvm.org/docs/LanguageExtensions.html#memory-references-to-specified-segments>`__
200200
for reference.
201-
201+
202202
If the analyzer option ``suppress-dereferences-from-any-address-space`` is set
203203
to true (the default value), then this checker never reports dereference of
204204
pointers with a specified address space. If the option is set to false, then
@@ -1664,6 +1664,23 @@ Warn on uses of the 'bzero' function.
16641664
bzero(ptr, n); // warn
16651665
}
16661666
1667+
.. _security-insecureAPI-decodeValueOfObjCType:
1668+
1669+
security.insecureAPI.decodeValueOfObjCType (C)
1670+
""""""""""""""""""""""""""""""""""""""""""""""
1671+
Warn on uses of the Objective-C method ``-decodeValueOfObjCType:at:``.
1672+
1673+
.. code-block:: objc
1674+
1675+
void test(NSCoder *decoder) {
1676+
unsigned int x;
1677+
[decoder decodeValueOfObjCType:"I" at:&x]; // warn
1678+
}
1679+
1680+
This diagnostic is emitted only on Apple platforms where the safer
1681+
``-decodeValueOfObjCType:at:size:`` alternative is available
1682+
(iOS 11+, macOS 10.13+, tvOS 11+, watchOS 4.0+).
1683+
16671684
.. _security-insecureAPI-getpw:
16681685
16691686
security.insecureAPI.getpw (C)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ SVal getDynamicExtentWithOffset(ProgramStateRef State, SVal BufV);
5858
DefinedOrUnknownSVal getDynamicElementCountWithOffset(ProgramStateRef State,
5959
SVal BufV, QualType Ty);
6060

61+
void markAllDynamicExtentLive(ProgramStateRef State, SymbolReaper &SymReaper);
62+
6163
} // namespace ento
6264
} // namespace clang
6365

clang/lib/CodeGen/CGVTables.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ static void resolveTopLevelMetadata(llvm::Function *Fn,
125125
if (!DIS)
126126
return;
127127
auto *NewDIS = llvm::MDNode::replaceWithDistinct(DIS->clone());
128+
// As DISubprogram remapping is avoided, clear retained nodes list of
129+
// cloned DISubprogram from retained nodes local to original DISubprogram.
130+
// FIXME: Thunk function signature is produced wrong in DWARF, as retained
131+
// nodes are not remapped.
132+
NewDIS->replaceRetainedNodes(llvm::MDTuple::get(Fn->getContext(), {}));
128133
VMap.MD()[DIS].reset(NewDIS);
129134

130135
// Find all llvm.dbg.declare intrinsics and resolve the DILocalVariable nodes

clang/lib/StaticAnalyzer/Checkers/StdVariantChecker.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ bool isStdVariant(const Type *Type) {
9090
static std::optional<ArrayRef<TemplateArgument>>
9191
getTemplateArgsFromVariant(const Type *VariantType) {
9292
const auto *TempSpecType = VariantType->getAs<TemplateSpecializationType>();
93+
while (TempSpecType && TempSpecType->isTypeAlias())
94+
TempSpecType =
95+
TempSpecType->getAliasedType()->getAs<TemplateSpecializationType>();
9396
if (!TempSpecType)
9497
return {};
9598

@@ -219,10 +222,12 @@ class StdVariantChecker : public Checker<eval::Call, check::RegionChanges> {
219222
bool handleStdGetCall(const CallEvent &Call, CheckerContext &C) const {
220223
ProgramStateRef State = C.getState();
221224

222-
const auto &ArgType = Call.getArgSVal(0)
223-
.getType(C.getASTContext())
224-
->getPointeeType()
225-
.getTypePtr();
225+
SVal ArgSVal = Call.getArgSVal(0);
226+
if (ArgSVal.isUnknown())
227+
return false;
228+
229+
const auto &ArgType =
230+
ArgSVal.getType(C.getASTContext())->getPointeeType().getTypePtr();
226231
// We have to make sure that the argument is an std::variant.
227232
// There is another std::get with std::pair argument
228233
if (!isStdVariant(ArgType))

clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,12 @@ ProgramStateRef setDynamicExtent(ProgramStateRef State, const MemRegion *MR,
128128
return State->set<DynamicExtentMap>(MR->StripCasts(), Size);
129129
}
130130

131+
void markAllDynamicExtentLive(ProgramStateRef State, SymbolReaper &SymReaper) {
132+
for (const auto &I : State->get<DynamicExtentMap>())
133+
if (SymbolRef Sym = I.second.getAsSymbol())
134+
if (SymReaper.isLiveRegion(I.first))
135+
SymReaper.markLive(Sym);
136+
}
137+
131138
} // namespace ento
132139
} // namespace clang

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,11 @@ void ExprEngine::removeDead(ExplodedNode *Pred, ExplodedNodeSet &Out,
10791079
getCheckerManager().runCheckersForDeadSymbols(CheckedSet, Pred, SymReaper,
10801080
DiagnosticStmt, *this, K);
10811081

1082+
// Extend lifetime of symbols used for dynamic extent while the parent region
1083+
// is live. In this way size information about memory allocations is not lost
1084+
// if the region remains live.
1085+
markAllDynamicExtentLive(CleanedState, SymReaper);
1086+
10821087
// For each node in CheckedSet, generate CleanedNodes that have the
10831088
// environment, the store, and the constraints cleaned up but have the
10841089
// user-supplied states as the predecessors.

clang/test/Analysis/ArrayBound/verbose-tests.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -381,30 +381,12 @@ int *symbolicExtent(int arg) {
381381
return 0;
382382
int *mem = (int*)malloc(arg);
383383

384-
// TODO: without the following reference to 'arg', the analyzer would discard
385-
// the range information about (the symbolic value of) 'arg'. This is
386-
// incorrect because while the variable itself is inaccessible, it becomes
387-
// the symbolic extent of 'mem', so we still want to reason about its
388-
// potential values.
389-
(void)arg;
390-
391384
mem[8] = -2;
392385
// expected-warning@-1 {{Out of bound access to memory after the end of the heap area}}
393386
// expected-note@-2 {{Access of 'int' element in the heap area at index 8}}
394387
return mem;
395388
}
396389

397-
int *symbolicExtentDiscardedRangeInfo(int arg) {
398-
// This is a copy of the case 'symbolicExtent' without the '(void)arg' hack.
399-
// TODO: if the analyzer can detect the out-of-bounds access within this
400-
// testcase, then remove this and the `(void)arg` hack from `symbolicExtent`.
401-
if (arg >= 5)
402-
return 0;
403-
int *mem = (int*)malloc(arg);
404-
mem[8] = -2;
405-
return mem;
406-
}
407-
408390
void symbolicIndex(int arg) {
409391
// expected-note@+2 {{Assuming 'arg' is >= 12}}
410392
// expected-note@+1 {{Taking true branch}}
@@ -426,9 +408,5 @@ int *nothingIsCertain(int x, int y) {
426408
// {{Access of 'int' element in the heap area at an overflowing index}}
427409
// but apparently the analyzer isn't smart enough to deduce this.
428410

429-
// Keep constraints alive. (Without this, the overeager garbage collection of
430-
// constraints would _also_ prevent the intended behavior in this testcase.)
431-
(void)x;
432-
433411
return mem;
434412
}

clang/test/Analysis/std-variant-checker.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,31 @@ void nonInlineFunctionCallPtr() {
355355
char c = std::get<char> (v); // no-warning
356356
(void)a;
357357
(void)c;
358-
}
358+
}
359+
360+
// ----------------------------------------------------------------------------//
361+
// Misc
362+
// ----------------------------------------------------------------------------//
363+
364+
void unknownVal() {
365+
// force the argument to be UnknownVal
366+
(void)std::get<int>(*(std::variant<int, float>*)(int)3.14f); // no crash
367+
}
368+
369+
template <typename T>
370+
using MyVariant = std::variant<int, float>;
371+
372+
void typeAlias() {
373+
MyVariant<bool> v;
374+
375+
(void)std::get<int>(v); // no-warning
376+
}
377+
378+
template <template<typename> typename Container>
379+
using MySpecialVariant = std::variant<int, float>;
380+
381+
void complexTypeAlias() {
382+
MySpecialVariant<std::vector> v;
383+
384+
(void)std::get<int>(v); // no crash
385+
}

clang/test/CodeGenCXX/tmp-md-nodes1.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
// RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | \
33
// RUN: FileCheck %s
44

5+
// Trigger GenerateVarArgsThunk.
6+
// RUN: %clang_cc1 -O0 -triple riscv64-linux-gnu -debug-info-kind=limited -emit-llvm %s -o - | \
7+
// RUN: FileCheck %s
8+
9+
// Check that retainedNodes are properly maintained at function cloning.
10+
// RUN: %clang_cc1 -O1 -triple riscv64-linux-gnu -debug-info-kind=limited -emit-llvm %s -o - | \
11+
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DI
12+
513
// This test simply checks that the varargs thunk is created. The failing test
614
// case asserts.
715

@@ -16,3 +24,11 @@ struct CharlieImpl : Charlie, Alpha {
1624
} delta;
1725

1826
// CHECK: define {{.*}} void @_ZThn{{[48]}}_N11CharlieImpl5bravoEz(
27+
28+
// CHECK-DI: distinct !DISubprogram({{.*}}, linkageName: "_ZN11CharlieImpl5bravoEz", {{.*}}, retainedNodes: [[RN1:![0-9]+]]
29+
// A non-empty retainedNodes list of original DISubprogram.
30+
// CHECK-DI: [[RN1]] = !{!{{.*}}}
31+
32+
// CHECK-DI: distinct !DISubprogram({{.*}}, linkageName: "_ZN11CharlieImpl5bravoEz", {{.*}}, retainedNodes: [[EMPTY:![0-9]+]]
33+
// An empty retainedNodes list of cloned DISubprogram.
34+
// CHECK-DI: [[EMPTY]] = !{}

0 commit comments

Comments
 (0)