[llvm-commits] [llvm-gcc-4.2] r66340 - in /llvm-gcc-4.2/trunk/gcc: c-opts.c common.opt llvm-backend.cpp llvm-convert.cpp
Duncan Sands
baldrick at free.fr
Sat Mar 7 07:51:59 PST 2009
Author: baldrick
Date: Sat Mar 7 09:51:50 2009
New Revision: 66340
URL: http://llvm.org/viewvc/llvm-project?rev=66340&view=rev
Log:
When compiling C++, output one-definition-rule (ODR)
linkage types except if the user may have explicitly
specified the linkage, in which case conservatively
produce the more general linkage type.
Modified:
llvm-gcc-4.2/trunk/gcc/c-opts.c
llvm-gcc-4.2/trunk/gcc/common.opt
llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Modified: llvm-gcc-4.2/trunk/gcc/c-opts.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/c-opts.c?rev=66340&r1=66339&r2=66340&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/c-opts.c (original)
+++ llvm-gcc-4.2/trunk/gcc/c-opts.c Sat Mar 7 09:51:50 2009
@@ -238,6 +238,9 @@
/* APPLE LOCAL end -Wfour-char-constants */
flag_exceptions = c_dialect_cxx ();
+ /* LLVM local begin One Definition Rule */
+ flag_odr = c_dialect_cxx ();
+ /* LLVM local end */
warn_pointer_arith = c_dialect_cxx ();
warn_write_strings = c_dialect_cxx();
Modified: llvm-gcc-4.2/trunk/gcc/common.opt
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/common.opt?rev=66340&r1=66339&r2=66340&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/common.opt (original)
+++ llvm-gcc-4.2/trunk/gcc/common.opt Sat Mar 7 09:51:50 2009
@@ -761,6 +761,12 @@
Common RejectNegative Report Var(flag_mudflap_ignore_reads)
Ignore read operations when inserting mudflap instrumentation
+; LLVM local begin One Definition Rule
+fone-definition-rule
+Common Report Var(flag_odr)
+Assume all definitions of a multiply defined global are equivalent
+; LLVM local end
+
; APPLE LOCAL begin optimization pragmas 3124235/3420242
freschedule-modulo-scheduled-loops
Common Report Var(flag_resched_modulo_sched) PerFunc
Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=66340&r1=66339&r2=66340&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Sat Mar 7 09:51:50 2009
@@ -1025,17 +1025,15 @@
if (!Aliasee) {
if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))) {
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
- Aliasee = new GlobalVariable(GV->getType(),
- GV->isConstant(),
- GlobalVariable::ExternalWeakLinkage,
- NULL,
- AliaseeName,
- TheModule);
+ // The user explicitly asked for weak linkage - ignore flag_odr.
+ Aliasee = new GlobalVariable(GV->getType(), GV->isConstant(),
+ GlobalVariable::ExternalWeakAnyLinkage,
+ NULL, AliaseeName, TheModule);
else if (Function *F = dyn_cast<Function>(V))
+ // The user explicitly asked for weak linkage - ignore flag_odr.
Aliasee = Function::Create(F->getFunctionType(),
- Function::ExternalWeakLinkage,
- AliaseeName,
- TheModule);
+ Function::ExternalWeakAnyLinkage,
+ AliaseeName, TheModule);
else
assert(0 && "Unsuported global value");
} else {
@@ -1052,7 +1050,8 @@
if (DECL_LLVM_PRIVATE(decl))
Linkage = GlobalValue::PrivateLinkage;
else if (DECL_WEAK(decl))
- Linkage = GlobalValue::WeakLinkage;
+ // The user may have explicitly asked for weak linkage - ignore flag_odr.
+ Linkage = GlobalValue::WeakAnyLinkage;
else if (!TREE_PUBLIC(decl))
Linkage = GlobalValue::InternalLinkage;
else
@@ -1300,14 +1299,17 @@
GV->setLinkage(GlobalValue::PrivateLinkage);
} else if (!TREE_PUBLIC(decl)) {
GV->setLinkage(GlobalValue::InternalLinkage);
- } else if (DECL_WEAK(decl) || DECL_ONE_ONLY(decl)) {
- GV->setLinkage(GlobalValue::WeakLinkage);
+ } else if (DECL_WEAK(decl)) {
+ // The user may have explicitly asked for weak linkage - ignore flag_odr.
+ GV->setLinkage(GlobalValue::WeakAnyLinkage);
+ } else if (DECL_ONE_ONLY(decl)) {
+ GV->setLinkage(GlobalValue::getWeakLinkage(flag_odr));
} else if (DECL_COMMON(decl) && // DECL_COMMON is only meaningful if no init
- (!DECL_INITIAL(decl) || DECL_INITIAL(decl) == error_mark_node)) {
+ (!DECL_INITIAL(decl) || DECL_INITIAL(decl) == error_mark_node)) {
// llvm-gcc also includes DECL_VIRTUAL_P here.
- GV->setLinkage(GlobalValue::CommonLinkage);
+ GV->setLinkage(GlobalValue::getCommonLinkage(flag_odr));
} else if (DECL_COMDAT(decl)) {
- GV->setLinkage(GlobalValue::LinkOnceLinkage);
+ GV->setLinkage(GlobalValue::getLinkOnceLinkage(flag_odr));
}
#ifdef TARGET_ADJUST_LLVM_LINKAGE
@@ -1498,10 +1500,11 @@
FnEntry->setCallingConv(CC);
FnEntry->setAttributes(PAL);
- // Check for external weak linkage
+ // Check for external weak linkage. The user may have explicitly asked
+ // for weak linkage - ignore flag_odr.
if (DECL_EXTERNAL(decl) && DECL_WEAK(decl))
- FnEntry->setLinkage(Function::ExternalWeakLinkage);
-
+ FnEntry->setLinkage(Function::ExternalWeakAnyLinkage);
+
#ifdef TARGET_ADJUST_LLVM_LINKAGE
TARGET_ADJUST_LLVM_LINKAGE(FnEntry,decl);
#endif /* TARGET_ADJUST_LLVM_LINKAGE */
@@ -1544,10 +1547,11 @@
GV = new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage, 0,
"", TheModule);
- // Check for external weak linkage
+ // Check for external weak linkage. The user may have explicitly asked
+ // for weak linkage - ignore flag_odr.
if (DECL_EXTERNAL(decl) && DECL_WEAK(decl))
- GV->setLinkage(GlobalValue::ExternalWeakLinkage);
-
+ GV->setLinkage(GlobalValue::ExternalWeakAnyLinkage);
+
#ifdef TARGET_ADJUST_LLVM_LINKAGE
TARGET_ADJUST_LLVM_LINKAGE(GV,decl);
#endif /* TARGET_ADJUST_LLVM_LINKAGE */
@@ -1562,10 +1566,11 @@
GV = new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage,0,
Name, TheModule);
- // Check for external weak linkage
+ // Check for external weak linkage. The user may have explicitly asked
+ // for weak linkage - ignore flag_odr.
if (DECL_EXTERNAL(decl) && DECL_WEAK(decl))
- GV->setLinkage(GlobalValue::ExternalWeakLinkage);
-
+ GV->setLinkage(GlobalValue::ExternalWeakAnyLinkage);
+
#ifdef TARGET_ADJUST_LLVM_LINKAGE
TARGET_ADJUST_LLVM_LINKAGE(GV,decl);
#endif /* TARGET_ADJUST_LLVM_LINKAGE */
@@ -1647,11 +1652,12 @@
GlobalValue *GV = cast<GlobalValue>(DECL_LLVM(decl));
// Do not mark something that is already known to be linkonce or internal.
+ // The user may have explicitly asked for weak linkage - ignore flag_odr.
if (GV->hasExternalLinkage()) {
if (GV->isDeclaration())
- GV->setLinkage(GlobalValue::ExternalWeakLinkage);
+ GV->setLinkage(GlobalValue::ExternalWeakAnyLinkage);
else
- GV->setLinkage(GlobalValue::WeakLinkage);
+ GV->setLinkage(GlobalValue::WeakAnyLinkage);
}
}
Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=66340&r1=66339&r2=66340&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Sat Mar 7 09:51:50 2009
@@ -470,9 +470,12 @@
lookup_attribute ("always_inline", DECL_ATTRIBUTES (FnDecl))) {
Fn->setLinkage(Function::InternalLinkage);
} else if (DECL_COMDAT(FnDecl)) {
- Fn->setLinkage(Function::LinkOnceLinkage);
- } else if (DECL_WEAK(FnDecl) || DECL_ONE_ONLY(FnDecl)) {
- Fn->setLinkage(Function::WeakLinkage);
+ Fn->setLinkage(Function::getLinkOnceLinkage(flag_odr));
+ } else if (DECL_WEAK(FnDecl)) {
+ // The user may have explicitly asked for weak linkage - ignore flag_odr.
+ Fn->setLinkage(Function::WeakAnyLinkage);
+ } else if (DECL_ONE_ONLY(FnDecl)) {
+ Fn->setLinkage(Function::getWeakLinkage(flag_odr));
}
#ifdef TARGET_ADJUST_LLVM_LINKAGE
More information about the llvm-commits
mailing list