From 815fe26ed35a0ff22b176c2c76bb0c0b2d9c16d9 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 21 Jun 2012 05:54:50 +0000 Subject: 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 --- clang/test/Sema/inline.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'clang/test/Sema/inline.c') diff --git a/clang/test/Sema/inline.c b/clang/test/Sema/inline.c index 6c95a7a14b4..c27c00efaad 100644 --- a/clang/test/Sema/inline.c +++ b/clang/test/Sema/inline.c @@ -26,6 +26,20 @@ static inline int useStaticFromStatic () { return staticVar; // no-warning } +extern inline int useStaticInlineFromExtern () { + // Heuristic: if the function we're using is also inline, don't warn. + // This can still be wrong (in this case, we end up inlining calls to + // staticFunction and staticVar) but this got very noisy even using + // standard headers. + return useStaticFromStatic(); // no-warning +} + +static int constFunction() __attribute__((const)); + +inline int useConst () { + return constFunction(); // no-warning +} + #else // ------- // This is the main source file. -- cgit v1.2.3