Commit Graph

13 Commits

Author SHA1 Message Date
David Blaikie 095deba533 Provide the correct mangling and linkage for certain unnamed nested classes.
This corrects the mangling and linkage of classes (& their member functions) in
cases like this:

  struct foo {
    struct {
      void func() { ... }
    } x;
  };

we were accidentally giving this nested unnamed struct 'no' linkage where it
should've had the linkage of the outer class. The mangling was incorrecty too,
mangling as TU-wide unnamed type mangling of $_X rather than class-scoped
mangling of UtX_.

This also fixes -Wunused-member-function which would incorrectly diagnose
'func' as unused due to it having no linkage & thus appearing to be TU-local
when in fact it might be correctly used in another TU.

Similar mangling should be applied to function local classes in similar cases
but I've deferred that for a subsequent patch.

Review/discussion by Richard Smith, John McCall, & especially Eli Friedman.

llvm-svn: 167906
2012-11-14 01:52:05 +00:00
Richard Smith 59a8e49f01 Revert functional part of r166896 and just suppress -Wunneeded-internal-declaration for reference types for now. This needs more work; the cases we currently miss are a bit random.
llvm-svn: 166899
2012-10-28 07:39:29 +00:00
Richard Smith 27501e787c In -Wunneeded-internal-declaration, suppress the warning for variables which
might have been used in constant expressions, rather than suppressing it for
variables which are const. The important thing here is that such variables
can have their values used without actually being marked as 'used'.

llvm-svn: 166896
2012-10-28 04:47:21 +00:00
Argyrios Kyrtzidis 1618023018 We regard a function as 'unused' from the codegen perspective, so our warnings diverge from
gcc's unused warnings which don't get emitted if the function is referenced even in an unevaluated context
(e.g. in templates, sizeof, etc.). Also, saying that a function is 'unused' because it won't get codegen'ed
is somewhat misleading.

- Don't emit 'unused' warnings for functions that are referenced in any part of the user's code.
- A warning that an internal function/variable won't get emitted is useful though, so introduce
  -Wunneeded-internal-declaration which will warn if a function/variable with internal linkage is not
  "needed" ('used' from the codegen perspective), e.g:

  static void foo() { }

  template <int>
  void bar() {
    foo();
  }

test.cpp:1:13: warning: function 'foo' is not needed and will not be emitted
static void foo() { }
            ^

Addresses rdar://8733476.

llvm-svn: 129794
2011-04-19 19:51:10 +00:00
John McCall f768aa7613 Move the check that gives functions with unique-external types unique-external
linkage into Decl.cpp.  Disable this logic for extern "C" functions, because
the operative rule there is weaker.  Fixes rdar://problem/8898466

llvm-svn: 125268
2011-02-10 06:50:24 +00:00
Chandler Carruth 8e666510f6 Fix PR8841 by checking for both semantic and lecical dependent
contexts. This prevents -Wunused-function from firing on friend function
definitions inside of class templates for example.

llvm-svn: 122763
2011-01-03 19:27:19 +00:00
Argyrios Kyrtzidis beb71b315a Rename -Wunused-method -> -Wunused-member-function.
llvm-svn: 111305
2010-08-17 22:06:44 +00:00
Argyrios Kyrtzidis cad715fb9b Introduce -Wunused-method option for warning on unused class methods in anonymous namespace.
This option is not part of the Unused diagnostic group until the warnings on llvm codebase are fixed
and we are ready to turn it on. Suggestion by Daniel.

llvm-svn: 111298
2010-08-17 21:43:11 +00:00
Argyrios Kyrtzidis 04c7fa09e4 Don't warn for the common pattern of disallowing copying:
class S {
  S(const S&); // DO NOT IMPLEMENT
  void operator=(const S&); // DO NOT IMPLEMENT
};

llvm-svn: 111100
2010-08-15 10:17:33 +00:00
Argyrios Kyrtzidis 1b30d9c0f0 Commit improved version of 111026 & 111027.
Unused warnings for functions:
-static functions
-functions in anonymous namespace
-class methods in anonymous namespace
-class method specializations in anonymous namespace
-function specializations in anonymous namespace

Unused warnings for variables:
-static variables
-variables in anonymous namespace
-static data members in anonymous namespace
-static data members specializations in anonymous namespace

Reveals lots of opportunities for dead code removal in llvm codebase that will
interest my esteemed colleagues.

llvm-svn: 111086
2010-08-15 01:15:20 +00:00
Argyrios Kyrtzidis 98703d3883 Revert 111026 & 111027, build breakage.
llvm-svn: 111036
2010-08-13 20:13:06 +00:00
Argyrios Kyrtzidis 1063a71e43 The unused warnings extravaganza continues. Warn for:
-static variables
-variables in anonymous namespace (fixes rdar://7794535)
-static data members in anonymous namespace
-static data members specializations in anonymous namespace

llvm-svn: 111027
2010-08-13 18:42:40 +00:00
Argyrios Kyrtzidis 540bc01f50 Expand the unused warnings for functions. Warn for:
-static function declarations
-functions in anonymous namespace
-class methods in anonymous namespace
-class method specializations in anonymous namespace
-function specializations in anonymous namespace

llvm-svn: 111026
2010-08-13 18:42:29 +00:00