Skip to content

Commit 359b6a4

Browse files
Reduce minimum number of affected pointers for -warn-root-cause to 1 (#721)
Root causes will now be emitted if they affect at least one pointer. This is a change from the previous minimum of two affected pointers. Fixes #685.
1 parent 48ebd6c commit 359b6a4

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

clang/lib/3C/RewriteUtils.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,10 @@ void RewriteConsumer::emitRootCauseDiagnostics(ASTContext &Context) {
589589
if (!File.getError()) {
590590
SourceLocation SL =
591591
SM.translateFileLineCol(*File, PSL.getLineNo(), PSL.getColSNo());
592-
// Limit emitted root causes to those that effect more than one pointer
593-
// or are in the main file of the TU. Alternatively, don't filter causes
594-
// if -warn-all-root-cause is passed.
592+
// Limit emitted root causes to those that effect at least one pointer.
593+
// Alternatively, don't filter causes if -warn-all-root-cause is passed.
595594
int PtrCount = I.getNumPtrsAffected(WReason.first);
596-
if (_3COpts.WarnAllRootCause || SM.isInMainFile(SL) || PtrCount > 1) {
595+
if (_3COpts.WarnAllRootCause || PtrCount > 0) {
597596
// SL is invalid when the File is not in the current translation unit.
598597
if (SL.isValid()) {
599598
EmittedDiagnostics.insert(PSL);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: cd %S
22
// RUN: 3c -use-malloc=my_malloc -alltypes -addcr -output-dir=%t.checked/base_subdir -warn-all-root-cause %s -- -Xclang -verify=unwritable-expected -Wno-everything
3+
// RUN: 3c -use-malloc=my_malloc -alltypes -addcr -output-dir=%t.checked/base_subdir -warn-root-cause %s -- -Xclang -verify=not-all-unwritable-expected -Wno-everything
4+
// not-all-unwritable-expected-no-diagnostics
35

46
#include "../root_cause.c"

clang/test/3C/root_cause.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: 3c -use-malloc=my_malloc -base-dir=%S -alltypes -warn-all-root-cause %s -- -Xclang -verify -Wno-everything
2+
// RUN: 3c -use-malloc=my_malloc -base-dir=%S -alltypes -warn-root-cause %s -- -Xclang -verify -Wno-everything
23

34
// This test is unusual in that it checks for the errors in the code
45

@@ -106,5 +107,4 @@ void test_conflict() {
106107
// expected-note@#as_ptr {{Operand of address-of has PTR lower bound}}
107108
// expected-note@#as_nt {{Assigning from c to s}}
108109

109-
110-
110+
#include "root_cause.h"

clang/test/3C/root_cause.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Test that root cause errors are reported correctly in include header files.
2+
// Included by root_cause.c
3+
4+
void outside_of_main() {
5+
// expected-warning@+3 {{1 unchecked pointer: Cast from int to int *}}
6+
// unwritable-expected-warning@+2 {{0 unchecked pointers: Source code in non-writable file}}
7+
// unwritable-expected-warning@+1 {{0 unchecked pointers: Source code in non-writable file}}
8+
int *c = 1;
9+
}

0 commit comments

Comments
 (0)