[cfe-commits] r149387 - in /cfe/trunk: lib/Analysis/FormatString.cpp test/SemaCXX/format-strings.cpp

Hans Wennborg hans at hanshq.net
Tue Jan 31 06:59:59 PST 2012


Author: hans
Date: Tue Jan 31 08:59:59 2012
New Revision: 149387

URL: http://llvm.org/viewvc/llvm-project?rev=149387&view=rev
Log:
Format string warnings: don't a.k.a. wchar_t with wchar_t.

This fixes the case where Clang would output:
 error: format specifies type 'wchar_t *' (aka 'wchar_t *')

ArgTypeResult::getRepresentativeTypeName needs to take into account
that wchar_t can be a built-in type (as opposed to in C, where it is a
typedef).

Modified:
    cfe/trunk/lib/Analysis/FormatString.cpp
    cfe/trunk/test/SemaCXX/format-strings.cpp

Modified: cfe/trunk/lib/Analysis/FormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/FormatString.cpp?rev=149387&r1=149386&r2=149387&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/FormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/FormatString.cpp Tue Jan 31 08:59:59 2012
@@ -373,7 +373,7 @@
 
 std::string ArgTypeResult::getRepresentativeTypeName(ASTContext &C) const {
   std::string S = getRepresentativeType(C).getAsString();
-  if (Name)
+  if (Name && S != Name)
     return std::string("'") + Name + "' (aka '" + S + "')";
   return std::string("'") + S + "'";
 }

Modified: cfe/trunk/test/SemaCXX/format-strings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/format-strings.cpp?rev=149387&r1=149386&r2=149387&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/format-strings.cpp (original)
+++ cfe/trunk/test/SemaCXX/format-strings.cpp Tue Jan 31 08:59:59 2012
@@ -13,3 +13,7 @@
   printf("%a", 1.0);
   scanf("%afoobar", fp);
 }
+
+void g() {
+  printf("%ls", "foo"); // expected-warning{{format specifies type 'wchar_t *' but the argument has type 'const char *'}}
+}





More information about the cfe-commits mailing list