Commit Graph

501 Commits

Author SHA1 Message Date
Sylvestre Ledru 830885ca64 Fix a typo (the the => the)
llvm-svn: 160622
2012-07-23 08:59:39 +00:00
Jordan Rose 3e0ec58c09 For varargs, diagnose passing ObjC objects by value like other non-POD types.
While we still want to consider this a hard error (non-POD variadic args are
normally a DefaultError warning), delaying the diagnostic allows us to give
better error messages, which also match the usual non-POD errors more closely.

In addition, this change improves the diagnostic messages for format string
argument type mismatches by passing down the type of the callee, so we can
say "variadic method" or "variadic function" appropriately.

<rdar://problem/11825593>

llvm-svn: 160517
2012-07-19 18:10:23 +00:00
Jordan Rose 58bbe4206f Don't crash checking a format string if one of the arguments is invalid.
Previously, we would ask for the SourceLocation of an argument even if
it were NULL (i.e. if Sema resulted in an ExprError trying to build it).

<rdar://problem/11890818>

llvm-svn: 160515
2012-07-19 18:10:08 +00:00
David Blaikie 1f4ff15c91 Simplify float comparison checks by using early return.
Found while investigating PR13330

llvm-svn: 160318
2012-07-16 20:47:22 +00:00
Simon Atanasyan ecedf3ddec MIPS: Range check __builtin_mips_wrdsp / __builtin_mips_rddsp arguments against the upper/lower values.
llvm-svn: 159911
2012-07-08 09:30:00 +00:00
Fariborz Jahanian dabd133186 objc-arc: warn when assigning retained object to
a 'weak' property just as we do the same for
'weak' variables. // rdar://11814185

llvm-svn: 159859
2012-07-06 21:09:27 +00:00
Douglas Gregor 98c3cfc3b9 When a builtin that requires a constant is given a type- or
value-dependent expression, don't complain that it wasn't the constant
we wanted. Fixes <rdar://problem/11688587> and PR11074.

llvm-svn: 159404
2012-06-29 01:05:22 +00:00
Richard Smith 55ce352d4d Unrevert r158887, reverted in r158949, along with a fix for the bug which
resulted in it being reverted. A test for that bug was added in r158950.

Original comment:

If an object (such as a std::string) with an appropriate c_str() member function
is passed to a variadic function in a position where a format string indicates
that c_str()'s return type is desired, provide a note suggesting that the user
may have intended to call the c_str() member.

Factor the non-POD-vararg checking out of DefaultVariadicArgumentPromotion and
move it to SemaChecking in order to facilitate this. Factor the call checking
out of function call checking and block call checking, and extend it to cover
constructor calls too.

Patch by Sam Panzer!

llvm-svn: 159159
2012-06-25 20:30:08 +00:00
Rafael Espindola c368817101 Revert r158887. This fixes pr13168.
Revert "If an object (such as a std::string) with an appropriate c_str() member function"

This reverts commit 7d96f6106bfbd85b1af06f34fdbf2834aad0e47e.

llvm-svn: 158949
2012-06-21 23:44:21 +00:00
David Blaikie 8cf439f85a PR13165: False positive when initializing member data pointers with NULL.
This now correctly covers, I believe, all the pointer types:
* 'any' pointers (both function and data normal pointers and ObjC object pointers)
* member pointers (both function and data)
* block pointers

llvm-svn: 158931
2012-06-21 18:51:10 +00:00
Richard Smith c7b0bdffe7 If an object (such as a std::string) with an appropriate c_str() member function
is passed to a variadic function in a position where a format string indicates
that c_str()'s return type is desired, provide a note suggesting that the user
may have intended to call the c_str() member.

Factor the non-POD-vararg checking out of DefaultVariadicArgumentPromotion and
move it to SemaChecking in order to facilitate this. Factor the call checking
out of function call checking and block call checking, and extend it to cover
constructor calls too.

Patch by Sam Panzer!

llvm-svn: 158887
2012-06-21 01:08:35 +00:00
David Blaikie 9366d2b32d Enable -Wnull-conversion for non-integral target types (eg: double).
llvm-svn: 158744
2012-06-19 21:19:06 +00:00
Eli Friedman 93ee5ca805 Fix Sema and IRGen for atomic compound assignment so it has the right semantics when promotions are involved.
(As far as I can tell, this only affects some edge cases.)

llvm-svn: 158591
2012-06-16 02:19:17 +00:00
Richard Smith 4060f77462 PR13099: Teach -Wformat about raw string literals, UTF-8 strings and Unicode escape sequences.
llvm-svn: 158390
2012-06-13 05:37:23 +00:00
Jordan Rose 97c6f2b9e5 Teach format string checking about compile-time CFString constants.
Within the guts of CheckFormatHandler, the IsObjCLiteral flag was being used in
two ways: to see if null bytes were allowed, and to see if the '%@' specifier
is allowed.* The former usage has been changed to an explicit test and the
latter pushed down to CheckPrintfHandler and renamed ObjCContext, since it
applies to CFStrings as well.

* This also changes how wide chars are interpreted; in OS X Foundation, the
wide character type is 'unichar', a typedef for short, rather than wchar_t.

llvm-svn: 157968
2012-06-04 23:52:23 +00:00
Jordan Rose 98709985a6 Teach printf/scanf about enums with fixed underlying types.
llvm-svn: 157961
2012-06-04 22:48:57 +00:00
Anna Zaks d08d9159c2 Change wording of 'memcpy' type mismatch warning and remove fixit.
As per comments following r157659.

llvm-svn: 157722
2012-05-30 23:14:52 +00:00
Anna Zaks 869aeccada Add fixits for memory access warnings.
Also, do not display the builtin name and macro expansion when the
function is a builtin.

llvm-svn: 157659
2012-05-30 00:34:21 +00:00
Matt Beaumont-Gay 32d825a4db Use the argument location instead of the format string location when warning
about argument type mismatch.

This gives a nicer diagnostic in cases like
  printf(fmt,
         i);
where previously the snippet just pointed at 'fmt' (with a note at the
definition of fmt).

It's a wash for cases like
  printf("%f",
         i);
where previously we snippeted the offending portion of the format string,
but didn't indicate which argument was at fault.

llvm-svn: 156968
2012-05-17 00:03:16 +00:00
David Blaikie 18e9ac7914 Don't warn when NULL is used within a macro but its conversion is outside a macro.
This fixes the included test case & was reported by Nico Weber.

It's a little bit nasty using the difference in the conversion context, but
seems to me like a not unreasonable solution. I did have to fix up the
conversion context for conditional operators (it seems correct to me to include
the context for which we're actually doing the comparison - across all the
nested conditionals, rather than the innermost conditional which might not
actually have the problematic implicit conversion at all) and template default
arguments (this is a bit of a hack, since we don't have the source location of
the '=' anymore, so I just used the start of the parameter - open to
suggestions there)

llvm-svn: 156861
2012-05-15 21:57:38 +00:00
David Blaikie 9b88cc0a40 Changing std::string to SmallString for r156826.
Based on code review feedback by Jordan Rose.

llvm-svn: 156827
2012-05-15 17:18:27 +00:00
David Blaikie 7555b6a4e5 Improve some of the conversion warnings to fire on conversion to bool.
Moves the bool bail-out down a little in SemaChecking - so now
-Wnull-conversion and -Wliteral-conversion can fire when the target type is
bool.

Also improve the wording/details in the -Wliteral-conversion warning to match
the -Wconstant-conversion.

llvm-svn: 156826
2012-05-15 16:56:36 +00:00
Matt Beaumont-Gay d873508975 Merge branch 'format-string-braced-init'
llvm-svn: 156653
2012-05-11 22:10:59 +00:00
Ted Kremenek 7ebb493375 Teach IsTailPaddedMemberArray() (used by -Warray-bounds) that a FieldDecl may have a Typedef type, and not always a ConstantArrayType.
Fixes <rdar://problem/11387038>.

llvm-svn: 156464
2012-05-09 05:35:08 +00:00
Jean-Daniel Dupas 2b7da83759 Inhibit ObjC format warning only in system headers (NSLocalizedString).
Add a test case for the related NSAssert workaround.

llvm-svn: 156205
2012-05-04 21:08:08 +00:00
Sean Callanan 06a48a62b3 IsTailPaddedMemberArray uses a FieldDecl's
getTypeSourceInfo() without checking for NULL.
FieldDecls may have NULL TypeSourceInfo, and in
fact some FieldDecls generated by Clang -- and
all FieldDecls generated by LLDB -- have no
TypeSourceInfo.

This patch makes IsTailPaddedMemberArray check
for NULL.

llvm-svn: 156186
2012-05-04 18:22:53 +00:00
Douglas Gregor 7bfb2d026e Move Sema::RequireCompleteType() and Sema::RequireCompleteExprType()
off PartialDiagnostic. PartialDiagnostic is rather heavyweight for
something that is in the critical path and is rarely used. So, switch
over to an abstract-class-based callback mechanism that delays most of
the work until a diagnostic is actually produced. Good for ~11k code
size reduction in the compiler and 1% speedup in -fsyntax-only on the
code in <rdar://problem/11004361>.

llvm-svn: 156176
2012-05-04 16:32:21 +00:00
James Molloy 3636554b63 Fix handling of wint_t - we can't assume wint_t is purely an integer promotion of wchar_t - they may differ in signedness.
Teach ASTContext about WIntType, and have it taken from TargetInfo like WCharType. Should fix test/Sema/format-strings.c for ARM, with the exception of one subtest which will fail if wint_t and wchar_t are the same size and wint_t is signed, wchar_t is unsigned.

There'll be a followup commit to fix that.

Reviewed by Chandler and Hans at http://llvm.org/reviews/r/8

llvm-svn: 156165
2012-05-04 10:55:22 +00:00
Bob Wilson 23cd434202 Disable -Wformat-extra-args for arguments defined in system headers.
Some of the NSAssert macros in OS X 10.7 are implemented in a way that
adds extra arguments that trigger the -Wformat-extra-args warning.
Earlier versions of clang failed to detect those -Wformat issues, but now
that clang is reporting those problems, we need to quiet them since there's
nothing to be done to fix them.  <rdar://problem/11317765>

I don't know how to write a testcase for this.  Suggestions welcome.
Patch by Ted Kremenek!

llvm-svn: 156092
2012-05-03 19:47:19 +00:00
Douglas Gregor bfb4a2138c Turn the mixed-sign-comparison diagnostic into a runtime behavior
diagnostic, from Eitan Adler!

llvm-svn: 155876
2012-05-01 01:53:49 +00:00
Argyrios Kyrtzidis b4015e1877 When going through references to check if the function returns the address
of a local variable, make sure we don't infinitely recurse when the
reference binds to itself.

e.g:

int* func() {
    int& i = i;    // assign non-exist variable to a reference which has same name.
    return &i;    // return pointer
}

rdar://11345441

llvm-svn: 155856
2012-04-30 23:23:55 +00:00
David Blaikie 7665a62cf7 Add FixItHint for -Wnull-conversion to initialize with an appropriate literal.
Reviewed by Doug Gregor.

llvm-svn: 155839
2012-04-30 18:27:22 +00:00
Julien Lerouge 4a5b444371 Currently __builtin_annotation() only annotates an i32.
i32 __builtin_annotation(i32, string);

Applying it to i64 (e.g., long long) generates the following IR.

        trunc i64 {{.*}} to i32
        call i32 @llvm.annotation.i32
        zext i32 {{.*}} to i64

The redundant truncation and extension make the result difficult to use.

This patch makes __builtin_annotation() generic.

        type __builtin_annotation(type, string);

For the i64 example, it simplifies the generated IR to:

        call i64 @llvm.annotation.i64

Patch by Xi Wang!

llvm-svn: 155764
2012-04-28 17:39:16 +00:00
Richard Smith d65cee9423 Implement __atomic_fetch_nand and __atomic_nand_fetch to complete our set of
GNU __atomic builtins.

llvm-svn: 154659
2012-04-13 06:31:38 +00:00
David Blaikie 9455da0ea9 Warn on 64-to-32 for source value of x bits where 64 >= x > 32.
The codepath already only works for source bits > target bits, it's just that
it was testing for the source expr bits to be exactly 64. This meant simple
cases (int i = x_long / 2) were missed & ended up under the general
-Wconversion warning, which a user might not have enabled.

llvm-svn: 154626
2012-04-12 22:40:54 +00:00
Richard Smith feea883de4 Implement support for 18 of the GNU-compatible __atomic builtins.
This is not quite sufficient for libstdc++'s <atomic>: we still need
__atomic_test_and_set and __atomic_clear, and may need a more complete
__atomic_is_lock_free implementation.

We are also missing an implementation of __atomic_always_lock_free,
__atomic_nand_fetch, and __atomic_fetch_nand, but those aren't needed
for libstdc++.

llvm-svn: 154579
2012-04-12 05:08:17 +00:00
Richard Smith b1e36c662b Provide, and document, a set of __c11_atomic_* intrinsics to implement C11's
<stdatomic.h> header.

In passing, fix LanguageExtensions to note that C11 and C++11 are no longer
"upcoming standards" but are now actually standardized.

llvm-svn: 154513
2012-04-11 17:55:32 +00:00
Ted Kremenek e69340c42c Remove dead assignment to local variable.
llvm-svn: 153985
2012-04-04 00:55:21 +00:00
David Chisnall 891ec2870d Pass parameters in the correct order when assembling an AtomicExpr.
llvm-svn: 153665
2012-03-29 17:58:59 +00:00
David Blaikie ae12b18ad8 Suppress macro expansion of NULL in NULL warnings.
For "int i = NULL;" we would produce:

null.cpp:5:11: warning: implicit conversion of NULL constant to integer [-Wconversion]
  int i = NULL;
      ~   ^~~~
null.cpp:1:14: note: expanded from macro 'NULL'
\#define NULL __null
              ^~~~~~

But we really shouldn't trace that macro expansion back into the header, yet we
still want macro back traces for code like this:

\#define FOO NULL
int i = FOO;

or

\#define FOO int i = NULL;
FOO

While providing appropriate tagging at different levels of the expansion, etc.

The included test case exercises these cases & does some basic validation (to
ensure we don't have macro expansion notes where we shouldn't, and do where we
should) - but doesn't go as far as to validate the source location/ranges
used in those notes and warnings.

llvm-svn: 152940
2012-03-16 20:30:12 +00:00
David Blaikie e7fd58006d Provide the specific target type in the -Wnull-conversion warning.
llvm-svn: 152835
2012-03-15 20:48:26 +00:00
David Blaikie bbafb8a745 Unify naming of LangOptions variable/get function across the Clang stack (Lex to AST).
The member variable is always "LangOpts" and the member function is always "getLangOpts".

Reviewed by Chris Lattner

llvm-svn: 152536
2012-03-11 07:00:24 +00:00
John McCall 113bee0536 Remove BlockDeclRefExpr and introduce a bit on DeclRefExpr to
track whether the referenced declaration comes from an enclosing
local context.  I'm amenable to suggestions about the exact meaning
of this bit.

llvm-svn: 152491
2012-03-10 09:33:50 +00:00
Hans Wennborg aa8c61cf94 -Wformat-non-iso: warn about positional arguments (pr12017)
This renames the -Wformat-non-standard flag to -Wformat-non-iso,
rewords the current warnings a bit (pointing out that a format string
is not supported by ISO C rather than being "non standard"),
and adds a warning about positional arguments.

llvm-svn: 152403
2012-03-09 10:10:54 +00:00
Eli Friedman 84e6e5cd1a Fix a couple bugs in the way we handle array indexes in array bounds checking. Specifically, make sure we don't ignore explicit casts in indexes, and make sure we use unsigned extension/comparisons on indexes. Fixes <rdar://problem/10916006>.
llvm-svn: 151569
2012-02-27 21:21:40 +00:00
Eli Friedman 8195ad7b87 Modernize some code which processes CastExprs to use CastKinds. No intended functional change.
llvm-svn: 151298
2012-02-23 23:04:32 +00:00
Hans Wennborg c9dd946852 Warn about non-standard format strings (pr12017)
This adds the -Wformat-non-standard flag (off by default,
enabled by -pedantic), which warns about non-standard
things in format strings (such as the 'q' length modifier,
the 'S' conversion specifier, etc.)

llvm-svn: 151154
2012-02-22 10:17:01 +00:00
Douglas Gregor ed90df3800 Generate an AST for the conversion from a lambda closure type to a
block pointer that returns a block literal which captures (by copy)
the lambda closure itself. Some aspects of the block literal are left
unspecified, namely the capture variable (which doesn't actually
exist) and the body (which will be filled in by IRgen because it can't
be written as an AST).

Because we're switching to this model, this patch also eliminates
tracking the copy-initialization expression for the block capture of
the conversion function, since that information is now embedded in the
synthesized block literal. -1 side tables FTW.

llvm-svn: 151131
2012-02-22 05:02:47 +00:00
Jean-Daniel Dupas 58dab6829a When calling a non variadic format function(vprintf, vscanf, NSLogv, …), warn if the format string argument is a parameter that is not itself declared as a format string with compatible format.
llvm-svn: 151080
2012-02-21 20:00:53 +00:00
Hans Wennborg d99d688358 Make -Wformat fix-its preserve original conversion specifiers.
This commit makes PrintfSpecifier::fixType() and ScanfSpecifier::fixType()
only fix a conversion specification enough that Clang wouldn't warn about it,
as opposed to always changing it to use the "canonical" conversion specifier.
(PR11975)

This preserves the user's choice of conversion specifier in cases like:

printf("%a", (long double)1);
where we previously suggested "%Lf", we now suggest "%La"

printf("%x", (long)1);
where we previously suggested "%ld", we now suggest "%lx".

llvm-svn: 150578
2012-02-15 09:59:46 +00:00