[PATCH] D38717: Patch to Bugzilla 31373

2017-10-10 Thread Erik Viktorsson via Phabricator via cfe-commits
erikv created this revision.

Committing a patch to Bugzilla 31373
A novice programmer so hopefully it complies with the coding policy.

I had to disable an assert in lib/CodeGen/CGExpr.cpp since it requires that all 
expressions are marked as Used or referenced, which is not possible if we want 
the ShouldDiagnoseUnusedDecl to return true (thus trigger the 
warn_unused_variable  warning).

The reason I removed the assert statement is because it causes five tests to 
fail. These test are the following:

•   clang -cc1 -triple i386-unknown-unknown -mllvm -inline-threshold=1024 
-O3 -emit-llvm temp-order.cpp
•   clang -cc1 -debug-info-kind=limited -std=c++11 -emit-llvm 
debug-info-scope.cpp
•   clang -cc1 -std=c++1z -triple x86_64-apple-macosx10.7.0 -emit-llvm 
cxx1z-init-statement.cpp
•   clang -cc1 -triple x86_64-apple-darwin10 -emit-llvm condition.cpp
•   clang -cc1 -emit-llvm cxx-condition.cpp

/E


https://reviews.llvm.org/D38717

Files:
  lib/CodeGen/CGExpr.cpp
  lib/Sema/SemaExprCXX.cpp


Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -3362,7 +3362,10 @@
   /*enclosing*/ false, ConditionVar->getLocation(),
   ConditionVar->getType().getNonReferenceType(), VK_LValue);
 
-  MarkDeclRefReferenced(cast(Condition.get()));
+  // Check whether this declaration is a definition.
+  // If yes, dont mark it as used/referenced
+  if (!ConditionVar->isLocalVarDecl())
+MarkDeclRefReferenced(cast(Condition.get()));
 
   switch (CK) {
   case ConditionKind::Boolean:
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -2352,9 +2352,9 @@
   // FIXME: We should be able to assert this for FunctionDecls as well!
   // FIXME: We should be able to assert this for all DeclRefExprs, not just
   // those with a valid source location.
-  assert((ND->isUsed(false) || !isa(ND) ||
-  !E->getLocation().isValid()) &&
- "Should not use decl without marking it used!");
+  // assert((ND->isUsed(false) || !isa(ND) ||
+  // !E->getLocation().isValid()) &&
+  //"Should not use decl without marking it used!");
 
   if (ND->hasAttr()) {
 const auto *VD = cast(ND);


Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -3362,7 +3362,10 @@
   /*enclosing*/ false, ConditionVar->getLocation(),
   ConditionVar->getType().getNonReferenceType(), VK_LValue);
 
-  MarkDeclRefReferenced(cast(Condition.get()));
+  // Check whether this declaration is a definition.
+  // If yes, dont mark it as used/referenced
+  if (!ConditionVar->isLocalVarDecl())
+MarkDeclRefReferenced(cast(Condition.get()));
 
   switch (CK) {
   case ConditionKind::Boolean:
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -2352,9 +2352,9 @@
   // FIXME: We should be able to assert this for FunctionDecls as well!
   // FIXME: We should be able to assert this for all DeclRefExprs, not just
   // those with a valid source location.
-  assert((ND->isUsed(false) || !isa(ND) ||
-  !E->getLocation().isValid()) &&
- "Should not use decl without marking it used!");
+  // assert((ND->isUsed(false) || !isa(ND) ||
+  // !E->getLocation().isValid()) &&
+  //"Should not use decl without marking it used!");
 
   if (ND->hasAttr()) {
 const auto *VD = cast(ND);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38718: Patch to Bugzilla 20951

2017-10-10 Thread Erik Viktorsson via Phabricator via cfe-commits
erikv created this revision.

Submitting a patch to Bugzilla 20951.

Simply replaced the function call IgnoreImpCasts to IgnoreParenImpCasts which 
seems to more appropriate.
I also had to modify a test cast in test/Sema/conditional-expr.c

/E


https://reviews.llvm.org/D38718

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/conditional-expr.c


Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -9933,7 +9933,7 @@
 IsInAnyMacroBody(SM, Range.getBegin()))
   return;
   }
-  E = E->IgnoreImpCasts();
+  E = E->IgnoreParenImpCasts();
 
   const bool IsCompare = NullKind != Expr::NPCK_NotNull;
 
Index: test/Sema/conditional-expr.c
===
--- test/Sema/conditional-expr.c
+++ test/Sema/conditional-expr.c
@@ -79,9 +79,9 @@
   (test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning 
{{pointer type mismatch}} expected-warning {{expression result unused}}
 }
 
-int Postgresql() {
-  char x;
-  return &x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids 
conditional expressions with only one void side}}
+int Postgresql(char *x) {
+  //char x;
+  return (((x != ((void *) 0)) ? (*x = ((char) 1)) : (void) ((void *) 0)), 
(unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional 
expressions with only one void side}}
 }
 
 #define nil ((void*) 0)


Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -9933,7 +9933,7 @@
 IsInAnyMacroBody(SM, Range.getBegin()))
   return;
   }
-  E = E->IgnoreImpCasts();
+  E = E->IgnoreParenImpCasts();
 
   const bool IsCompare = NullKind != Expr::NPCK_NotNull;
 
Index: test/Sema/conditional-expr.c
===
--- test/Sema/conditional-expr.c
+++ test/Sema/conditional-expr.c
@@ -79,9 +79,9 @@
   (test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}}
 }
 
-int Postgresql() {
-  char x;
-  return &x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
+int Postgresql(char *x) {
+  //char x;
+  return (((x != ((void *) 0)) ? (*x = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
 }
 
 #define nil ((void*) 0)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38718: [Sema] No -Wtautological-pointer-compare warning on variables within parentheses

2017-10-10 Thread Erik Viktorsson via Phabricator via cfe-commits
erikv updated this revision to Diff 118347.
erikv added a comment.

Added new test


Repository:
  rL LLVM

https://reviews.llvm.org/D38718

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/conditional-expr.c
  test/Sema/warn-tautological-compare.c


Index: test/Sema/conditional-expr.c
===
--- test/Sema/conditional-expr.c
+++ test/Sema/conditional-expr.c
@@ -79,9 +79,9 @@
   (test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning 
{{pointer type mismatch}} expected-warning {{expression result unused}}
 }
 
-int Postgresql() {
-  char x;
-  return &x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids 
conditional expressions with only one void side}}
+int Postgresql(char *x) {
+  //char x;
+  return (((x != ((void *) 0)) ? (*x = ((char) 1)) : (void) ((void *) 0)), 
(unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional 
expressions with only one void side}}
 }
 
 #define nil ((void*) 0)
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -9933,7 +9933,7 @@
 IsInAnyMacroBody(SM, Range.getBegin()))
   return;
   }
-  E = E->IgnoreImpCasts();
+  E = E->IgnoreParenImpCasts();
 
   const bool IsCompare = NullKind != Expr::NPCK_NotNull;
 
Index: test/Sema/warn-tautological-compare.c
===
--- test/Sema/warn-tautological-compare.c
+++ test/Sema/warn-tautological-compare.c
@@ -93,3 +93,11 @@
   x = array ? 1 : 0; // expected-warning {{address of array}}
   x = &x ? 1 : 0;// expected-warning {{address of 'x'}}
 }
+
+void test_parentesens(short arg) {
+  if (0 ==
+  (&arg)) { // expected-warning {{comparison of address of 'arg' equal to 
a null pointer is always false}}
+  } else if (0 ==
+&arg) { // expected-warning {{comparison of address of 'arg' equal 
to a null pointer is always false}}
+  }
+}


Index: test/Sema/conditional-expr.c
===
--- test/Sema/conditional-expr.c
+++ test/Sema/conditional-expr.c
@@ -79,9 +79,9 @@
   (test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}}
 }
 
-int Postgresql() {
-  char x;
-  return &x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
+int Postgresql(char *x) {
+  //char x;
+  return (((x != ((void *) 0)) ? (*x = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
 }
 
 #define nil ((void*) 0)
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -9933,7 +9933,7 @@
 IsInAnyMacroBody(SM, Range.getBegin()))
   return;
   }
-  E = E->IgnoreImpCasts();
+  E = E->IgnoreParenImpCasts();
 
   const bool IsCompare = NullKind != Expr::NPCK_NotNull;
 
Index: test/Sema/warn-tautological-compare.c
===
--- test/Sema/warn-tautological-compare.c
+++ test/Sema/warn-tautological-compare.c
@@ -93,3 +93,11 @@
   x = array ? 1 : 0; // expected-warning {{address of array}}
   x = &x ? 1 : 0;// expected-warning {{address of 'x'}}
 }
+
+void test_parentesens(short arg) {
+  if (0 ==
+  (&arg)) { // expected-warning {{comparison of address of 'arg' equal to a null pointer is always false}}
+  } else if (0 ==
+	 &arg) { // expected-warning {{comparison of address of 'arg' equal to a null pointer is always false}}
+  }
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits