Skip to content

Commit ad9a953

Browse files
authored
[clang] Fix -Wuninitialized for values passed by const pointers (#147221)
This enables producing a "variable is uninitialized" warning when a value is passed to a pointer-to-const argument: ``` void foo(const int *); void test() { int *v; foo(v); } ``` Fixes #37460
1 parent a32040e commit ad9a953

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

clang/lib/Analysis/UninitializedValues.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,6 @@ void ClassifyRefs::VisitCallExpr(CallExpr *CE) {
446446
const auto *UO = dyn_cast<UnaryOperator>(Ex);
447447
if (UO && UO->getOpcode() == UO_AddrOf)
448448
classify(UO->getSubExpr(), isTrivialBody ? Ignore : ConstPtrUse);
449-
else
450-
classify(Ex, Ignore);
451449
}
452450
}
453451
}

clang/test/SemaCXX/uninitialized.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ void test_const_ptr() {
185185
const int *ptr2;
186186
foo(ptr); // expected-warning {{variable 'ptr' is uninitialized when used here}}
187187
foobar(&ptr2);
188+
int *ptr3; // expected-note {{initialize the variable 'ptr3' to silence this warning}}
189+
const int *ptr4; // expected-note {{initialize the variable 'ptr4' to silence this warning}}
190+
bar(ptr3); // expected-warning {{variable 'ptr3' is uninitialized when used here}}
191+
bar(ptr4); // expected-warning {{variable 'ptr4' is uninitialized when used here}}
188192
}
189193
}
190194

0 commit comments

Comments
 (0)