llvm.org GIT mirror llvm / ba0f991
[weak vtables] Place class definitions into anonymous namespaces to prevent weak vtables. This patch places class definitions in implementation files into anonymous namespaces to prevent weak vtables. This eliminates the need of providing an out-of-line definition to pin the vtable explicitly to the file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195092 91177308-0d34-0410-b5e6-96231b3b80d8 Juergen Ributzka 5 years ago
14 changed file(s) with 83 addition(s) and 158 deletion(s). Raw diff Collapse all Expand all
15611561 return(outerCatchFunct);
15621562 }
15631563
1564
1564 namespace {
15651565 /// Represents our foreign exceptions
15661566 class OurCppRunException : public std::runtime_error {
15671567 public:
15761576 std::runtime_error::operator=(toCopy)));
15771577 }
15781578
1579 ~OurCppRunException (void) throw ();
1579 virtual ~OurCppRunException (void) throw () {}
15801580 };
1581
1582 // Provide out-of-line definition to prevent weak vtable.
1583 OurCppRunException::~OurCppRunException() throw () {}
1581 } // end anonymous namespace
15841582
15851583 /// Throws foreign C++ exception.
15861584 /// @param ignoreIt unused parameter that allows function to match implied
7474 //===----------------------------------------------------------------------===//
7575 // Abstract Syntax Tree (aka Parse Tree)
7676 //===----------------------------------------------------------------------===//
77
77 namespace {
7878 /// ExprAST - Base class for all expression nodes.
7979 class ExprAST {
8080 public:
81 virtual ~ExprAST();
81 virtual ~ExprAST() {}
8282 };
8383
8484 /// NumberExprAST - Expression class for numeric literals like "1.0".
8585 class NumberExprAST : public ExprAST {
8686 public:
8787 NumberExprAST(double val) {}
88 virtual ~NumberExprAST();
8988 };
9089
9190 /// VariableExprAST - Expression class for referencing a variable, like "a".
9392 std::string Name;
9493 public:
9594 VariableExprAST(const std::string &name) : Name(name) {}
96 virtual ~VariableExprAST();
9795 };
9896
9997 /// BinaryExprAST - Expression class for a binary operator.
10098 class BinaryExprAST : public ExprAST {
10199 public:
102100 BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs) {}
103 virtual ~BinaryExprAST();
104101 };
105102
106103 /// CallExprAST - Expression class for function calls.
110107 public:
111108 CallExprAST(const std::string &callee, std::vector &args)
112109 : Callee(callee), Args(args) {}
113 virtual ~CallExprAST();
114 };
115
116 // Provide out-of-line definitions to prevent weak vtables.
117 ExprAST::~ExprAST() {}
118 NumberExprAST::~NumberExprAST() {}
119 VariableExprAST::~VariableExprAST() {}
120 BinaryExprAST::~BinaryExprAST() {}
121 CallExprAST::~CallExprAST() {}
110 };
122111
123112 /// PrototypeAST - This class represents the "prototype" for a function,
124113 /// which captures its name, and its argument names (thus implicitly the number
137126 public:
138127 FunctionAST(PrototypeAST *proto, ExprAST *body) {}
139128 };
129 } // end anonymous namespace
140130
141131 //===----------------------------------------------------------------------===//
142132 // Parser
168158 /// Error* - These are little helper functions for error handling.
169159 ExprAST *Error(const char *Str) { fprintf(stderr, "Error: %s\n", Str);return 0;}
170160 PrototypeAST *ErrorP(const char *Str) { Error(Str); return 0; }
171 FunctionAST *ErrorF(const char *Str) { Error(Str); return 0; }
172161
173162 static ExprAST *ParseExpression();
174163
7979 //===----------------------------------------------------------------------===//
8080 // Abstract Syntax Tree (aka Parse Tree)
8181 //===----------------------------------------------------------------------===//
82
82 namespace {
8383 /// ExprAST - Base class for all expression nodes.
8484 class ExprAST {
8585 public:
86 virtual ~ExprAST();
86 virtual ~ExprAST() {}
8787 virtual Value *Codegen() = 0;
8888 };
89
90 // Provide out-of-line definition to prevent weak vtable.
91 ExprAST::~ExprAST() {}
9289
9390 /// NumberExprAST - Expression class for numeric literals like "1.0".
9491 class NumberExprAST : public ExprAST {
149146
150147 Function *Codegen();
151148 };
149 } // end anonymous namespace
152150
153151 //===----------------------------------------------------------------------===//
154152 // Parser
8686 //===----------------------------------------------------------------------===//
8787 // Abstract Syntax Tree (aka Parse Tree)
8888 //===----------------------------------------------------------------------===//
89
89 namespace {
9090 /// ExprAST - Base class for all expression nodes.
9191 class ExprAST {
9292 public:
93 virtual ~ExprAST();
93 virtual ~ExprAST() {}
9494 virtual Value *Codegen() = 0;
9595 };
96
97 // Provide out-of-line definition to prevent weak vtable.
98 ExprAST::~ExprAST() {}
9996
10097 /// NumberExprAST - Expression class for numeric literals like "1.0".
10198 class NumberExprAST : public ExprAST {
156153
157154 Function *Codegen();
158155 };
156 } // end anonymous namespace
159157
160158 //===----------------------------------------------------------------------===//
161159 // Parser
9595 //===----------------------------------------------------------------------===//
9696 // Abstract Syntax Tree (aka Parse Tree)
9797 //===----------------------------------------------------------------------===//
98
98 namespace {
9999 /// ExprAST - Base class for all expression nodes.
100100 class ExprAST {
101101 public:
102 virtual ~ExprAST();
102 virtual ~ExprAST() {}
103103 virtual Value *Codegen() = 0;
104104 };
105
106 // Provide out-of-line definition to prevent weak vtable.
107 ExprAST::~ExprAST() {}
108105
109106 /// NumberExprAST - Expression class for numeric literals like "1.0".
110107 class NumberExprAST : public ExprAST {
185182
186183 Function *Codegen();
187184 };
185 } // end anonymous namespace
188186
189187 //===----------------------------------------------------------------------===//
190188 // Parser
100100 //===----------------------------------------------------------------------===//
101101 // Abstract Syntax Tree (aka Parse Tree)
102102 //===----------------------------------------------------------------------===//
103
103 namespace {
104104 /// ExprAST - Base class for all expression nodes.
105105 class ExprAST {
106106 public:
107 virtual ~ExprAST();
107 virtual ~ExprAST() {}
108108 virtual Value *Codegen() = 0;
109109 };
110
111 // Provide out-of-line definition to prevent weak vtable.
112 ExprAST::~ExprAST() {}
113110
114111 /// NumberExprAST - Expression class for numeric literals like "1.0".
115112 class NumberExprAST : public ExprAST {
213210
214211 Function *Codegen();
215212 };
213 } // end anonymous namespace
216214
217215 //===----------------------------------------------------------------------===//
218216 // Parser
104104 //===----------------------------------------------------------------------===//
105105 // Abstract Syntax Tree (aka Parse Tree)
106106 //===----------------------------------------------------------------------===//
107
107 namespace {
108108 /// ExprAST - Base class for all expression nodes.
109109 class ExprAST {
110110 public:
111 virtual ~ExprAST();
111 virtual ~ExprAST() {}
112112 virtual Value *Codegen() = 0;
113113 };
114
115 // Provide out-of-line definition to prevent weak vtable.
116 ExprAST::~ExprAST() {}
117114
118115 /// NumberExprAST - Expression class for numeric literals like "1.0".
119116 class NumberExprAST : public ExprAST {
231228
232229 Function *Codegen();
233230 };
231 } // end anonymous namespace
234232
235233 //===----------------------------------------------------------------------===//
236234 // Parser
5151 static cl::opt GenX86MMX("generate-x86-mmx",
5252 cl::desc("Generate X86 MMX floating-point values"), cl::init(false));
5353
54 namespace {
5455 /// A utility class to provide a pseudo-random number generator which is
5556 /// the same across all platforms. This is somewhat close to the libc
5657 /// implementation. Note: This is not a cryptographically secure pseudorandom
127128 BB(Block),PT(PT),Ran(R),Context(BB->getContext()) {}
128129
129130 /// virtual D'tor to silence warnings.
130 virtual ~Modifier();
131 virtual ~Modifier() {}
131132
132133 /// Add a new instruction.
133134 virtual void Act() = 0;
286287
287288 struct LoadModifier: public Modifier {
288289 LoadModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
289 virtual ~LoadModifier();
290290 virtual void Act() {
291291 // Try to use predefined pointers. If non exist, use undef pointer value;
292292 Value *Ptr = getRandomPointerValue();
297297
298298 struct StoreModifier: public Modifier {
299299 StoreModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
300 virtual ~StoreModifier();
301300 virtual void Act() {
302301 // Try to use predefined pointers. If non exist, use undef pointer value;
303302 Value *Ptr = getRandomPointerValue();
316315
317316 struct BinModifier: public Modifier {
318317 BinModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
319 virtual ~BinModifier();
320318
321319 virtual void Act() {
322320 Value *Val0 = getRandomVal();
361359 /// Generate constant values.
362360 struct ConstModifier: public Modifier {
363361 ConstModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
364 virtual ~ConstModifier();
365
366362 virtual void Act() {
367363 Type *Ty = pickType();
368364
409405
410406 struct AllocaModifier: public Modifier {
411407 AllocaModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R){}
412 virtual ~AllocaModifier();
413408
414409 virtual void Act() {
415410 Type *Tp = pickType();
420415 struct ExtractElementModifier: public Modifier {
421416 ExtractElementModifier(BasicBlock *BB, PieceTable *PT, Random *R):
422417 Modifier(BB, PT, R) {}
423 virtual ~ExtractElementModifier();
424418
425419 virtual void Act() {
426420 Value *Val0 = getRandomVectorValue();
434428
435429 struct ShuffModifier: public Modifier {
436430 ShuffModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
437 virtual ~ShuffModifier();
438
439431 virtual void Act() {
440432
441433 Value *Val0 = getRandomVectorValue();
464456 struct InsertElementModifier: public Modifier {
465457 InsertElementModifier(BasicBlock *BB, PieceTable *PT, Random *R):
466458 Modifier(BB, PT, R) {}
467 virtual ~InsertElementModifier();
468459
469460 virtual void Act() {
470461 Value *Val0 = getRandomVectorValue();
481472
482473 struct CastModifier: public Modifier {
483474 CastModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
484 virtual ~CastModifier();
485
486475 virtual void Act() {
487476
488477 Value *V = getRandomVal();
569558 struct SelectModifier: public Modifier {
570559 SelectModifier(BasicBlock *BB, PieceTable *PT, Random *R):
571560 Modifier(BB, PT, R) {}
572 virtual ~SelectModifier();
573561
574562 virtual void Act() {
575563 // Try a bunch of different select configuration until a valid one is found.
594582
595583 struct CmpModifier: public Modifier {
596584 CmpModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
597 virtual ~CmpModifier();
598
599585 virtual void Act() {
600586
601587 Value *Val0 = getRandomVal();
621607 }
622608 };
623609
624 // Use out-of-line definitions to prevent weak vtables.
625 Modifier::~Modifier() {}
626 LoadModifier::~LoadModifier() {}
627 StoreModifier::~StoreModifier() {}
628 BinModifier::~BinModifier() {}
629 ConstModifier::~ConstModifier() {}
630 AllocaModifier::~AllocaModifier() {}
631 ExtractElementModifier::~ExtractElementModifier() {}
632 ShuffModifier::~ShuffModifier() {}
633 InsertElementModifier::~InsertElementModifier() {}
634 CastModifier::~CastModifier() {}
635 SelectModifier::~SelectModifier() {}
636 CmpModifier::~CmpModifier() {}
637
638 void FillFunction(Function *F, Random &R) {
610 } // end anonymous namespace
611
612 static void FillFunction(Function *F, Random &R) {
639613 // Create a legal entry block.
640614 BasicBlock *BB = BasicBlock::Create(F->getContext(), "BB", F);
641615 ReturnInst::Create(F->getContext(), BB);
682656 SM->ActN(5); // Throw in a few stores.
683657 }
684658
685 void IntroduceControlFlow(Function *F, Random &R) {
659 static void IntroduceControlFlow(Function *F, Random &R) {
686660 std::vector BoolInst;
687661 for (BasicBlock::iterator it = F->begin()->begin(),
688662 e = F->begin()->end(); it != e; ++it) {
99 #include "llvm/ADT/IntrusiveRefCntPtr.h"
1010 #include "gtest/gtest.h"
1111
12 namespace {
13 struct VirtualRefCounted : public llvm::RefCountedBaseVPTR {
14 virtual void f() {}
15 };
16 }
17
1218 namespace llvm {
13
14 struct VirtualRefCounted : public RefCountedBaseVPTR {
15 virtual void f();
16 };
17
18 // Provide out-of-line definition to prevent weak vtable.
19 void VirtualRefCounted::f() {}
2019
2120 // Run this test with valgrind to detect memory leaks.
2221 TEST(IntrusiveRefCntPtr, RefCountedBaseVPTRCopyDoesNotLeak) {
5858 delete static_cast(object);
5959 }
6060
61 namespace {
6162 class MCJITCAPITest : public testing::Test, public MCJITTestAPICommon {
6263 protected:
6364 MCJITCAPITest() {
8283 UnsupportedOSs.push_back(Triple::Cygwin);
8384 }
8485
85 virtual void SetUp();
86
86 virtual void SetUp() {
87 didCallAllocateCodeSection = false;
88 Module = 0;
89 Function = 0;
90 Engine = 0;
91 Error = 0;
92 }
93
8794 virtual void TearDown() {
8895 if (Engine)
8996 LLVMDisposeExecutionEngine(Engine);
149156 LLVMExecutionEngineRef Engine;
150157 char *Error;
151158 };
152
153 // Provide out-of-line definition to prevent weak vtable.
154 void MCJITCAPITest::SetUp() {
155 didCallAllocateCodeSection = false;
156 Module = 0;
157 Function = 0;
158 Engine = 0;
159 Error = 0;
160 }
159 } // end anonymous namespace
161160
162161 TEST_F(MCJITCAPITest, simple_function) {
163162 SKIP_UNSUPPORTED_PLATFORM;
1717
1818 using namespace llvm;
1919
20 class MCJITMultipleModuleTest : public testing::Test, public MCJITTestBase {
21 public:
22 virtual ~MCJITMultipleModuleTest();
23 };
24
25 // Provide out-of-line definition to prevent weak vtable.
26 MCJITMultipleModuleTest::~MCJITMultipleModuleTest() {}
27
2820 namespace {
21
22 class MCJITMultipleModuleTest : public testing::Test, public MCJITTestBase {};
2923
3024 // FIXME: ExecutionEngine has no support empty modules
3125 /*
1717
1818 using namespace llvm;
1919
20 namespace {
21
2022 class MCJITTest : public testing::Test, public MCJITTestBase {
2123 protected:
22
23 virtual void SetUp();
24 virtual void SetUp() { M.reset(createEmptyModule("
")); }
2425 };
25
26 // Provide out-of-line definition to prevent weak vtable.
27 void MCJITTest::SetUp() {
28 M.reset(createEmptyModule("
"));
29 }
30
31 namespace {
3226
3327 // FIXME: Ensure creating an execution engine does not crash when constructed
3428 // with a null module.
3535 }
3636 #endif
3737
38 namespace {
3839 // (instrs a, b, ...) Evaluate and union all arguments. Identical to AddOp.
3940 struct InstrsOp : public SetTheory::Operator {
4041 virtual void apply(SetTheory &ST, DagInit *Expr, SetTheory::RecSet &Elts,
41 ArrayRef Loc);
42 ArrayRef Loc) {
43 ST.evaluate(Expr->arg_begin(), Expr->arg_end(), Elts, Loc);
44 }
4245 };
43
44 // Provide out-of-line definition to prevent weak vtable.
45 void InstrsOp::apply(SetTheory &ST, DagInit *Expr, SetTheory::RecSet &Elts,
46 ArrayRef Loc) {
47 ST.evaluate(Expr->arg_begin(), Expr->arg_end(), Elts, Loc);
48 }
4946
5047 // (instregex "OpcPat",...) Find all instructions matching an opcode pattern.
5148 //
5956 const CodeGenTarget &Target;
6057 InstRegexOp(const CodeGenTarget &t): Target(t) {}
6158
62 virtual void apply(SetTheory &ST, DagInit *Expr, SetTheory::RecSet &Elts,
63 ArrayRef Loc);
59 void apply(SetTheory &ST, DagInit *Expr, SetTheory::RecSet &Elts,
60 ArrayRef Loc) {
61 SmallVector RegexList;
62 for (DagInit::const_arg_iterator
63 AI = Expr->arg_begin(), AE = Expr->arg_end(); AI != AE; ++AI) {
64 StringInit *SI = dyn_cast(*AI);
65 if (!SI)
66 PrintFatalError(Loc, "instregex requires pattern string: "
67 + Expr->getAsString());
68 std::string pat = SI->getValue();
69 // Implement a python-style prefix match.
70 if (pat[0] != '^') {
71 pat.insert(0, "^(");
72 pat.insert(pat.end(), ')');
73 }
74 RegexList.push_back(new Regex(pat));
75 }
76 for (CodeGenTarget::inst_iterator I = Target.inst_begin(),
77 E = Target.inst_end(); I != E; ++I) {
78 for (SmallVectorImpl::iterator
79 RI = RegexList.begin(), RE = RegexList.end(); RI != RE; ++RI) {
80 if ((*RI)->match((*I)->TheDef->getName()))
81 Elts.insert((*I)->TheDef);
82 }
83 }
84 DeleteContainerPointers(RegexList);
85 }
6486 };
65
66 // Provide out-of-line definition to prevent weak vtable.
67 void InstRegexOp::apply(SetTheory &ST, DagInit *Expr, SetTheory::RecSet &Elts,
68 ArrayRef Loc) {
69 SmallVector RegexList;
70 for (DagInit::const_arg_iterator
71 AI = Expr->arg_begin(), AE = Expr->arg_end(); AI != AE; ++AI) {
72 StringInit *SI = dyn_cast(*AI);
73 if (!SI)
74 PrintFatalError(Loc, "instregex requires pattern string: "
75 + Expr->getAsString());
76 std::string pat = SI->getValue();
77 // Implement a python-style prefix match.
78 if (pat[0] != '^') {
79 pat.insert(0, "^(");
80 pat.insert(pat.end(), ')');
81 }
82 RegexList.push_back(new Regex(pat));
83 }
84 for (CodeGenTarget::inst_iterator I = Target.inst_begin(),
85 E = Target.inst_end(); I != E; ++I) {
86 for (SmallVectorImpl::iterator
87 RI = RegexList.begin(), RE = RegexList.end(); RI != RE; ++RI) {
88 if ((*RI)->match((*I)->TheDef->getName()))
89 Elts.insert((*I)->TheDef);
90 }
91 }
92 DeleteContainerPointers(RegexList);
93 }
87 } // end anonymous namespace
9488
9589 /// CodeGenModels ctor interprets machine model records and populates maps.
9690 CodeGenSchedModels::CodeGenSchedModels(RecordKeeper &RK,
4242
4343 }
4444
45 namespace {
4546 class ExtendedIntegerType : public Type {
4647 unsigned BitWidth;
4748 public:
4849 explicit ExtendedIntegerType(unsigned bits)
4950 : Type(TK_ExtendedIntegerType), BitWidth(bits) {}
50 virtual ~ExtendedIntegerType();
5151 static bool classof(const Type *T) {
5252 return T->getKind() == TK_ExtendedIntegerType;
5353 }
5959 }
6060 };
6161
62 // Provide out-of-line definition to prevent weak vtable.
63 ExtendedIntegerType::~ExtendedIntegerType() {}
64
6562 class ExtendedVectorType : public Type {
6663 EVT ElementType;
6764 unsigned NumElements;
6865 public:
6966 ExtendedVectorType(EVT elty, unsigned num)
7067 : Type(TK_ExtendedVectorType), ElementType(elty), NumElements(num) {}
71 virtual ~ExtendedVectorType();
7268 static bool classof(const Type *T) {
7369 return T->getKind() == TK_ExtendedVectorType;
7470 }
8278 return NumElements;
8379 }
8480 };
85
86 // Provide out-of-line definition to prevent weak vtable.
87 ExtendedVectorType::~ExtendedVectorType() {}
81 } // end anonymous namespace
8882
8983 static std::map
9084 ExtendedIntegerTypeMap;