]> granicus.if.org Git - clang/commitdiff
No fixit hint for builtin expressions which are
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 13 Apr 2011 20:31:26 +0000 (20:31 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 13 Apr 2011 20:31:26 +0000 (20:31 +0000)
defined in a macro. // rdar://9091893

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129465 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/FixIt/no-macro-fixit.c [new file with mode: 0644]

index 96b2e56b4154fa4857b417804cbe894e9bc2afcd..3d2b14933e2734e1c91e12ad2f15c5c1547d57e7 100644 (file)
@@ -10070,9 +10070,6 @@ void Sema::DiagnoseAssignmentAsCondition(Expr *E) {
     return;
   }
 
-  SourceLocation Open = E->getSourceRange().getBegin();
-  SourceLocation Close = PP.getLocForEndOfToken(E->getSourceRange().getEnd());
-
   Diag(Loc, diagnostic) << E->getSourceRange();
 
   if (IsOrAssign)
@@ -10082,9 +10079,14 @@ void Sema::DiagnoseAssignmentAsCondition(Expr *E) {
     Diag(Loc, diag::note_condition_assign_to_comparison)
       << FixItHint::CreateReplacement(Loc, "==");
 
-  Diag(Loc, diag::note_condition_assign_silence)
-    << FixItHint::CreateInsertion(Open, "(")
-    << FixItHint::CreateInsertion(Close, ")");
+  SourceLocation Open = E->getSourceRange().getBegin();
+  SourceLocation Close = E->getSourceRange().getEnd();
+  if (!Open.isMacroID() && !Close.isMacroID()) {
+    SourceLocation LocForEndOfToken = PP.getLocForEndOfToken(Close);
+    Diag(Loc, diag::note_condition_assign_silence)
+      << FixItHint::CreateInsertion(Open, "(")
+      << FixItHint::CreateInsertion(LocForEndOfToken, ")");
+  }
 }
 
 /// \brief Redundant parentheses over an equality comparison can indicate
diff --git a/test/FixIt/no-macro-fixit.c b/test/FixIt/no-macro-fixit.c
new file mode 100644 (file)
index 0000000..3685ab1
--- /dev/null
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -pedantic -fixit -x c %s
+// rdar://9091893
+
+#define va_arg(ap, type)    __builtin_va_arg(ap, type)
+typedef __builtin_va_list va_list;
+
+void myFunc() {
+    va_list values;
+    
+    int value;
+
+    while (value = va_arg(values, int)) {  // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+                                           // expected-note {{use '==' to turn this assignment into an equality comparison}}
+    }
+}