aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-02-19 02:53:41 +0000
committerJohn McCall <rjmccall@apple.com>2011-02-19 02:53:41 +0000
commit15e310a3b970b64a84cb30f0005bc396b4d978cb (patch)
treea07be31cb50547b6d1a6f71a6397f500a58e300d /test
parent370e6e984cc32167228b66eaf9610c010da0d794 (diff)
Warn about code that uses variables and functions with internal linkage
without defining them. This should be an error, but I'm paranoid about "uses" that end up not actually requiring a definition. I'll revisit later. Also, teach IR generation to not set internal linkage on variable declarations, just for safety's sake. Doing so produces an invalid module if the variable is not ultimately defined. Also, fix several places in the test suite where we were using internal functions without definitions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126016 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Analysis/cxx-crashes.cpp2
-rw-r--r--test/Analysis/misc-ps-64.m2
-rw-r--r--test/CodeGen/regparm.c3
-rw-r--r--test/CodeGen/sizeof-vla.c2
-rw-r--r--test/CodeGenCXX/constructor-convert.cpp2
-rw-r--r--test/CodeGenCXX/internal-linkage.cpp4
-rw-r--r--test/CodeGenCXX/key-function-vtable.cpp1
-rw-r--r--test/CodeGenCXX/thunks.cpp44
-rw-r--r--test/Rewriter/properties.m2
-rw-r--r--test/SemaCXX/undefined-internal.cpp86
10 files changed, 116 insertions, 32 deletions
diff --git a/test/Analysis/cxx-crashes.cpp b/test/Analysis/cxx-crashes.cpp
index cebc55bd42..ae2f3cb5eb 100644
--- a/test/Analysis/cxx-crashes.cpp
+++ b/test/Analysis/cxx-crashes.cpp
@@ -18,7 +18,7 @@ namespace {
struct A { };
struct B {
- operator A();
+ operator A() { return A(); }
};
A f(char *dst) {
diff --git a/test/Analysis/misc-ps-64.m b/test/Analysis/misc-ps-64.m
index 0dbd6cb948..f65673eea2 100644
--- a/test/Analysis/misc-ps-64.m
+++ b/test/Analysis/misc-ps-64.m
@@ -14,7 +14,7 @@ typedef unsigned char Boolean;
typedef const struct __CFDictionary * CFDictionaryRef;
extern Boolean CFDictionaryGetValueIfPresent(CFDictionaryRef theDict, const void *key, const void **value);
-static void shazam(NSUInteger i, unsigned char **out);
+void shazam(NSUInteger i, unsigned char **out);
void rdar_6440393_1(NSDictionary *dict) {
NSInteger x = 0;
diff --git a/test/CodeGen/regparm.c b/test/CodeGen/regparm.c
index dd0be96818..d628b685f9 100644
--- a/test/CodeGen/regparm.c
+++ b/test/CodeGen/regparm.c
@@ -11,8 +11,7 @@ typedef struct {
typedef void (*FType)(int, int) __attribute ((regparm (3), stdcall));
FType bar;
-static void FASTCALL
-reduced(char b, double c, foo* d, double e, int f);
+extern void FASTCALL reduced(char b, double c, foo* d, double e, int f);
// PR7025
void FASTCALL f1(int i, int j, int k);
diff --git a/test/CodeGen/sizeof-vla.c b/test/CodeGen/sizeof-vla.c
index b0c514fd01..c5fc912519 100644
--- a/test/CodeGen/sizeof-vla.c
+++ b/test/CodeGen/sizeof-vla.c
@@ -2,7 +2,7 @@
// PR3442
-static void *g(unsigned long len);
+void *g(unsigned long len);
void
f(int n)
diff --git a/test/CodeGenCXX/constructor-convert.cpp b/test/CodeGenCXX/constructor-convert.cpp
index 338febbe97..9122dae128 100644
--- a/test/CodeGenCXX/constructor-convert.cpp
+++ b/test/CodeGenCXX/constructor-convert.cpp
@@ -5,7 +5,7 @@ class Twine {
Twine(const char *Str) { }
};
-static void error(const Twine &Message);
+static void error(const Twine &Message) {}
template<typename>
struct opt_storage {
diff --git a/test/CodeGenCXX/internal-linkage.cpp b/test/CodeGenCXX/internal-linkage.cpp
index 9fdb7274e1..39bce8545f 100644
--- a/test/CodeGenCXX/internal-linkage.cpp
+++ b/test/CodeGenCXX/internal-linkage.cpp
@@ -1,11 +1,11 @@
// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
struct Global { Global(); };
-template<typename T> struct X { X(); };
+template<typename T> struct X { X() {} };
namespace {
- struct Anon { Anon(); };
+ struct Anon { Anon() {} };
// CHECK: @_ZN12_GLOBAL__N_15anon0E = internal global
Global anon0;
diff --git a/test/CodeGenCXX/key-function-vtable.cpp b/test/CodeGenCXX/key-function-vtable.cpp
index 8378bbd234..8e474bdf95 100644
--- a/test/CodeGenCXX/key-function-vtable.cpp
+++ b/test/CodeGenCXX/key-function-vtable.cpp
@@ -30,6 +30,7 @@ void testf::a() {}
namespace {
struct testg { virtual void a(); };
}
+void testg::a() {}
testg *testgvar = new testg;
struct X0 { virtual ~X0(); };
diff --git a/test/CodeGenCXX/thunks.cpp b/test/CodeGenCXX/thunks.cpp
index 238032cc6d..a74cc053db 100644
--- a/test/CodeGenCXX/thunks.cpp
+++ b/test/CodeGenCXX/thunks.cpp
@@ -88,31 +88,29 @@ void C::f() { }
}
// Check that the thunk gets internal linkage.
-namespace {
-
-struct A {
- virtual void f();
-};
-
-struct B {
- virtual void f();
-};
-
-struct C : A, B {
- virtual void c();
-
- virtual void f();
-};
+namespace Test4B {
+ struct A {
+ virtual void f();
+ };
-void C::f() { }
+ struct B {
+ virtual void f();
+ };
-}
+ namespace {
+ struct C : A, B {
+ virtual void c();
+ virtual void f();
+ };
+ }
+ void C::c() {}
+ void C::f() {}
-// Force C::f to be used.
-void f() {
- C c;
-
- c.f();
+ // Force C::f to be used.
+ void f() {
+ C c;
+ c.f();
+ }
}
namespace Test5 {
@@ -283,4 +281,4 @@ namespace Test11 {
// This is from Test5:
// CHECK: define linkonce_odr void @_ZTv0_n24_N5Test51B1fEv
-// CHECK: define internal void @_ZThn8_N12_GLOBAL__N_11C1fEv(
+// CHECK: define internal void @_ZThn8_N6Test4B12_GLOBAL__N_11C1fEv(
diff --git a/test/Rewriter/properties.m b/test/Rewriter/properties.m
index 89177d7e64..ca4a199cc6 100644
--- a/test/Rewriter/properties.m
+++ b/test/Rewriter/properties.m
@@ -38,7 +38,7 @@ void *sel_registerName(const char *);
@implementation Bar
-static int func(int i);
+static int func(int i) { return 0; }
- (void)baz {
Foo *obj1, *obj2;
diff --git a/test/SemaCXX/undefined-internal.cpp b/test/SemaCXX/undefined-internal.cpp
new file mode 100644
index 0000000000..bb87ce0f12
--- /dev/null
+++ b/test/SemaCXX/undefined-internal.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Make sure we don't produce invalid IR.
+// RUN: %clang_cc1 -emit-llvm-only %s
+
+namespace test1 {
+ static void foo(); // expected-warning {{function 'test1::foo' has internal linkage but is not defined}}
+ template <class T> static void bar(); // expected-warning {{function 'test1::bar<int>' has internal linkage but is not defined}}
+
+ void test() {
+ foo(); // expected-note {{used here}}
+ bar<int>(); // expected-note {{used here}}
+ }
+}
+
+namespace test2 {
+ namespace {
+ void foo(); // expected-warning {{function 'test2::<anonymous namespace>::foo' has internal linkage but is not defined}}
+ extern int var; // expected-warning {{variable 'test2::<anonymous namespace>::var' has internal linkage but is not defined}}
+ template <class T> void bar(); // expected-warning {{function 'test2::<anonymous namespace>::bar<int>' has internal linkage but is not defined}}
+ }
+ void test() {
+ foo(); // expected-note {{used here}}
+ var = 0; // expected-note {{used here}}
+ bar<int>(); // expected-note {{used here}}
+ }
+}
+
+namespace test3 {
+ namespace {
+ void foo();
+ extern int var;
+ template <class T> void bar();
+ }
+
+ void test() {
+ foo();
+ var = 0;
+ bar<int>();
+ }
+
+ namespace {
+ void foo() {}
+ int var = 0;
+ template <class T> void bar() {}
+ }
+}
+
+namespace test4 {
+ namespace {
+ struct A {
+ A(); // expected-warning {{function 'test4::<anonymous namespace>::A::A' has internal linkage but is not defined}}
+ ~A();// expected-warning {{function 'test4::<anonymous namespace>::A::~A' has internal linkage but is not defined}}
+ virtual void foo(); // expected-warning {{function 'test4::<anonymous namespace>::A::foo' has internal linkage but is not defined}}
+ virtual void bar() = 0;
+ virtual void baz(); // expected-warning {{function 'test4::<anonymous namespace>::A::baz' has internal linkage but is not defined}}
+ };
+ }
+
+ void test(A &a) {
+ a.foo(); // expected-note {{used here}}
+ a.bar();
+ a.baz(); // expected-note {{used here}}
+ }
+
+ struct Test : A {
+ Test() {} // expected-note 2 {{used here}}
+ };
+}
+
+// rdar://problem/9014651
+namespace test5 {
+ namespace {
+ struct A {};
+ }
+
+ template <class N> struct B {
+ static int var; // expected-warning {{variable 'test5::B<test5::<anonymous>::A>::var' has internal linkage but is not defined}}
+ static void foo(); // expected-warning {{function 'test5::B<test5::<anonymous>::A>::foo' has internal linkage but is not defined}}
+ };
+
+ void test() {
+ B<A>::var = 0; // expected-note {{used here}}
+ B<A>::foo(); // expected-note {{used here}}
+ }
+}