Commit Graph

13 Commits

Author SHA1 Message Date
John McCall c87d97231d Add -Wstatic-local-in-inline, which warns about using a static local
variable in a C99 inline (but not static-inline or extern-inline)
function definition.

The standard doesn't actually say that this doesn't apply to
"extern inline" definitions, but that seems like a useful extension,
and it at least doesn't have the obvious flaw that a static
mutable variable in an externally-available definition does.

rdar://13535367

llvm-svn: 178520
2013-04-02 02:48:58 +00:00
Fariborz Jahanian 7513fa346c c: small refactoring of checking for __attribute__(const))
per Richard's comment.

llvm-svn: 161786
2012-08-13 21:15:02 +00:00
Fariborz Jahanian 794ae1ea77 c: make __has_attribute(const) work for const
function attribute. // rdar://10253857

llvm-svn: 161767
2012-08-13 18:04:58 +00:00
Jordan Rose 815fe26ed3 Don't warn for -Wstatic-in-inline if the used function is also inline.
Also, don't warn if the used function is __attribute__((const)), in which case
it's not supposed to use global variables anyway.

The inline-in-inline thing is a heuristic, and one that's possibly incorrect
fairly often because the function being inlined could definitely use global
variables. However, even some C standard library functions are written using
other (trivial) static-inline functions in the headers, and we definitely don't
want to be warning on that (or on anything that /uses/ these trivial inline
functions). So we're using "inlined" as a marker for "fairly trivial".

(Note that __attribute__((pure)) does /not/ guarantee safety like ((const),
because ((const)) does not guarantee that global variables are not being used,
and the warning is about globals not being shared across TUs.)

llvm-svn: 158898
2012-06-21 05:54:50 +00:00
Jordan Rose dc753b625f Reword -Winternal-linkage-in-inline, and rename it to -Wstatic-in-inline.
Now that this is a C-only warning, we can use "static" instead of "internal
linkage", which is a term developers are probably more familiar with.
This makes for a better warning message. The warning name was changed to match,
since "internal linkage" is not mentioned in the warning text anymore.

llvm-svn: 158853
2012-06-20 21:09:10 +00:00
Jordan Rose 8cea63c5cd Change -Winternal-linkage-in-inline from ExtWarn to Warning in C++.
Per post-commit review, it's not appropriate to use ExtWarn in C++, because
we can't prove that the inline function will actually be defined in more than
one place (and thus we can't prove that this violates the ODR).

This removes the warning entirely from uses in the main source file in C++.

llvm-svn: 158689
2012-06-18 23:58:49 +00:00
Jordan Rose 28cd12f265 Support -Winternal-linkage-in-inline in C++ code.
This includes treating anonymous namespaces like internal linkage, and allowing
const variables to be used even if internal. The whole thing's been broken out
into a separate function to avoid nested ifs.

llvm-svn: 158683
2012-06-18 22:09:19 +00:00
Jordan Rose edff020011 Allow internal decls in inline functions if the function is in the main file.
This handles the very common case of people writing inline functions in their
main source files and not tagging them as inline. These cases should still
behave as the user intended. (The diagnostic is still emitted as an extension.)

I'm reworking this code anyway to account for C++'s equivalent restriction in
[basic.def.odr]p6, but this should get some bots back to green.

llvm-svn: 158666
2012-06-18 17:49:58 +00:00
Jordan Rose 2684c68ddc Warn when a static variable is referenced in a non-static inline function.
This is explicitly forbidden in C99 6.7.4p3. This is /not/ forbidden in C++,
probably because by default file-scope const/constexpr variables have internal
linkage, while functions have external linkage. There's also the issue of
anonymous namespaces to consider. Nevertheless, there should probably be a
similar warning, since the semantics of inlining a function that references
a variable with internal linkage do not seem well-defined.

<rdar://problem/11577619>

llvm-svn: 158531
2012-06-15 18:19:48 +00:00
Eli Friedman 51dd0185d6 Make __gnu_inline__ functions in gnu99 mode work the same way as inline functions in gnu89 mode in terms of redefinitions.
rdar://9559708 .

llvm-svn: 132953
2011-06-13 23:56:42 +00:00
Charles Davis fea4845609 Allow redefinitions of extern inline functions in GNU89 mode, just as GCC
does. Fixes PR5253.

llvm-svn: 96553
2010-02-18 02:00:42 +00:00
Daniel Dunbar 8fbe78f6fc Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.
- This is designed to make it obvious that %clang_cc1 is a "test variable"
   which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it
   can be useful to redefine what gets run as 'clang -cc1' (for example, to set
   a default target).

llvm-svn: 91446
2009-12-15 20:14:24 +00:00
Eli Friedman 574c745370 Diagnose uses of function specifiers on declarations which don't declare
functions.  Fixes PR3941.

llvm-svn: 68541
2009-04-07 19:37:57 +00:00