summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-01-12 10:48:03 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-01-12 10:48:03 +0000
commit569ad73d6b64cc7b5ed9340e5246f10fbaaf1da9 (patch)
tree78206d8f7bfea5a4ac9bf8be793c5cdbd04835c5 /clang/test
parent4294de3aa08bf135d192a2911fc52590cda17124 (diff)
downloadbcm5719-llvm-569ad73d6b64cc7b5ed9340e5246f10fbaaf1da9.tar.gz
bcm5719-llvm-569ad73d6b64cc7b5ed9340e5246f10fbaaf1da9.zip
Avoid multiple -Wunreachable-code diagnostics that are triggered by
the same source range and use the unary operator fixit only when it actually silences the warning. rdar://24570531 Differential Revision: https://reviews.llvm.org/D28231 llvm-svn: 291757
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Sema/warn-unreachable.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/clang/test/Sema/warn-unreachable.c b/clang/test/Sema/warn-unreachable.c
index 31beff9cf1e..34e0296a204 100644
--- a/clang/test/Sema/warn-unreachable.c
+++ b/clang/test/Sema/warn-unreachable.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wunreachable-code-aggressive -Wno-unused-value -Wno-covered-switch-default -I %S/Inputs
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wunreachable-code-aggressive -Wno-unused-value -Wno-covered-switch-default -fdiagnostics-parseable-fixits -I %S/Inputs %s 2>&1 | FileCheck %s
#include "warn-unreachable.h"
@@ -396,3 +397,57 @@ void test_with_paren_silencing(int x) {
else
calledFun();
}
+
+// rdar://24570531
+
+struct StructWithPointer {
+ void *p;
+};
+
+void emitJustOneWarningForOr(struct StructWithPointer *s) {
+ if (1 || !s->p) // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
+ return; // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:7}:"/* DISABLES CODE */ ("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:8-[[@LINE-2]]:8}:")"
+ emitJustOneWarningForOr(s); // expected-warning {{code will never be executed}}
+}
+
+void emitJustOneWarningForOrSilenced(struct StructWithPointer *s) {
+ if ((1) || !s->p)
+ return;
+
+ emitJustOneWarningForOrSilenced(s); // no warning
+}
+
+void emitJustOneWarningForOr2(struct StructWithPointer *s) {
+ if (1 || !s->p) // expected-warning {{code will never be executed}}
+ return; // expected-note@-1 {{silence by adding parentheses to mark code as explicitly dead}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:7-[[@LINE-2]]:7}:"/* DISABLES CODE */ ("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:")"
+}
+
+void wrapOneInFixit(struct StructWithPointer *s) {
+ if (!s->p || 1) // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
+ return; // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"/* DISABLES CODE */ ("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:")"
+ wrapOneInFixit(s); // expected-warning {{code will never be executed}}
+}
+
+void unaryOpNoFixit() {
+ if (- 1)
+ return; // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
+ unaryOpNoFixit(); // expected-warning {{code will never be executed}}
+}
+
+void unaryOpStrictFixit(struct StructWithPointer *s) {
+ if (!(s->p && 0)) // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
+ return; // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:17-[[@LINE-1]]:17}:"/* DISABLES CODE */ ("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:18-[[@LINE-2]]:18}:")"
+ unaryOpStrictFixit(s); // expected-warning {{code will never be executed}}
+}
+
+void unaryOpFixitCastSubExpr(int x) {
+ if (! (int)0) // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
+ return; // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:7}:"/* DISABLES CODE */ ("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:")"
+ unaryOpFixitCastSubExpr(x); // expected-warning {{code will never be executed}}
+}
OpenPOWER on IntegriCloud