mirror of https://github.com/microsoft/clang.git
Disable #pragma redefine_extname for C++ code as it does not make sense in such a context.
Patch by Andrey Bokhanko! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242420 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d04e4b6afa
commit
236d794324
|
@ -6343,6 +6343,10 @@ def warn_cast_qual : Warning<"cast from %0 to %1 drops %select{const and "
|
||||||
InGroup<CastQual>, DefaultIgnore;
|
InGroup<CastQual>, DefaultIgnore;
|
||||||
def warn_cast_qual2 : Warning<"cast from %0 to %1 must have all intermediate "
|
def warn_cast_qual2 : Warning<"cast from %0 to %1 must have all intermediate "
|
||||||
"pointers const qualified to be safe">, InGroup<CastQual>, DefaultIgnore;
|
"pointers const qualified to be safe">, InGroup<CastQual>, DefaultIgnore;
|
||||||
|
def warn_redefine_extname_not_applied : Warning<
|
||||||
|
"#pragma redefine_extname is applicable to external C declarations only; "
|
||||||
|
"not applied to %select{function|variable}0 %1">,
|
||||||
|
InGroup<Pragmas>;
|
||||||
} // End of general sema category.
|
} // End of general sema category.
|
||||||
|
|
||||||
// inline asm.
|
// inline asm.
|
||||||
|
|
|
@ -5568,15 +5568,12 @@ bool Sema::adjustContextForLocalExternDecl(DeclContext *&DC) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Returns true if given declaration is TU-scoped and externally
|
/// \brief Returns true if given declaration has external C language linkage.
|
||||||
/// visible.
|
static bool isDeclExternC(const Decl *D) {
|
||||||
static bool isDeclTUScopedExternallyVisible(const Decl *D) {
|
if (const auto *FD = dyn_cast<FunctionDecl>(D))
|
||||||
if (auto *FD = dyn_cast<FunctionDecl>(D))
|
return FD->isExternC();
|
||||||
return (FD->getDeclContext()->isTranslationUnit() || FD->isExternC()) &&
|
if (const auto *VD = dyn_cast<VarDecl>(D))
|
||||||
FD->hasExternalFormalLinkage();
|
return VD->isExternC();
|
||||||
else if (auto *VD = dyn_cast<VarDecl>(D))
|
|
||||||
return (VD->getDeclContext()->isTranslationUnit() || VD->isExternC()) &&
|
|
||||||
VD->hasExternalFormalLinkage();
|
|
||||||
|
|
||||||
llvm_unreachable("Unknown type of decl!");
|
llvm_unreachable("Unknown type of decl!");
|
||||||
}
|
}
|
||||||
|
@ -6005,13 +6002,16 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
|
||||||
|
|
||||||
NewVD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0),
|
NewVD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0),
|
||||||
Context, Label, 0));
|
Context, Label, 0));
|
||||||
} else if (!ExtnameUndeclaredIdentifiers.empty() &&
|
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
|
||||||
isDeclTUScopedExternallyVisible(NewVD)) {
|
|
||||||
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
|
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
|
||||||
ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier());
|
ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier());
|
||||||
if (I != ExtnameUndeclaredIdentifiers.end()) {
|
if (I != ExtnameUndeclaredIdentifiers.end()) {
|
||||||
NewVD->addAttr(I->second);
|
if (isDeclExternC(NewVD)) {
|
||||||
ExtnameUndeclaredIdentifiers.erase(I);
|
NewVD->addAttr(I->second);
|
||||||
|
ExtnameUndeclaredIdentifiers.erase(I);
|
||||||
|
} else
|
||||||
|
Diag(NewVD->getLocation(), diag::warn_redefine_extname_not_applied)
|
||||||
|
<< /*Variable*/1 << NewVD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7533,13 +7533,16 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
|
||||||
StringLiteral *SE = cast<StringLiteral>(E);
|
StringLiteral *SE = cast<StringLiteral>(E);
|
||||||
NewFD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0), Context,
|
NewFD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0), Context,
|
||||||
SE->getString(), 0));
|
SE->getString(), 0));
|
||||||
} else if (!ExtnameUndeclaredIdentifiers.empty() &&
|
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
|
||||||
isDeclTUScopedExternallyVisible(NewFD)) {
|
|
||||||
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
|
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
|
||||||
ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier());
|
ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier());
|
||||||
if (I != ExtnameUndeclaredIdentifiers.end()) {
|
if (I != ExtnameUndeclaredIdentifiers.end()) {
|
||||||
NewFD->addAttr(I->second);
|
if (isDeclExternC(NewFD)) {
|
||||||
ExtnameUndeclaredIdentifiers.erase(I);
|
NewFD->addAttr(I->second);
|
||||||
|
ExtnameUndeclaredIdentifiers.erase(I);
|
||||||
|
} else
|
||||||
|
Diag(NewFD->getLocation(), diag::warn_redefine_extname_not_applied)
|
||||||
|
<< /*Variable*/0 << NewFD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14388,12 +14391,14 @@ void Sema::ActOnPragmaRedefineExtname(IdentifierInfo* Name,
|
||||||
// 1) declares a function or a variable
|
// 1) declares a function or a variable
|
||||||
// 2) has external linkage
|
// 2) has external linkage
|
||||||
// already exists, add a label attribute to it.
|
// already exists, add a label attribute to it.
|
||||||
if (PrevDecl &&
|
if (PrevDecl && (isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl))) {
|
||||||
(isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl)) &&
|
if (isDeclExternC(PrevDecl))
|
||||||
PrevDecl->hasExternalFormalLinkage())
|
PrevDecl->addAttr(Attr);
|
||||||
PrevDecl->addAttr(Attr);
|
else
|
||||||
|
Diag(PrevDecl->getLocation(), diag::warn_redefine_extname_not_applied)
|
||||||
|
<< /*Variable*/(isa<FunctionDecl>(PrevDecl) ? 0 : 1) << PrevDecl;
|
||||||
// Otherwise, add a label atttibute to ExtnameUndeclaredIdentifiers.
|
// Otherwise, add a label atttibute to ExtnameUndeclaredIdentifiers.
|
||||||
else
|
} else
|
||||||
(void)ExtnameUndeclaredIdentifiers.insert(std::make_pair(Name, Attr));
|
(void)ExtnameUndeclaredIdentifiers.insert(std::make_pair(Name, Attr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,3 +24,9 @@ int f() {
|
||||||
extern int foo() { return 1; }
|
extern int foo() { return 1; }
|
||||||
// CHECK: define i32 @bar()
|
// CHECK: define i32 @bar()
|
||||||
|
|
||||||
|
// Check that pragma redefine_extname applies to external declarations only.
|
||||||
|
#pragma redefine_extname foo_static bar_static
|
||||||
|
static int foo_static() { return 1; }
|
||||||
|
int baz() { return foo_static(); }
|
||||||
|
// CHECK-NOT: call i32 @bar_static()
|
||||||
|
|
||||||
|
|
|
@ -28,3 +28,9 @@ extern "C" {
|
||||||
// CHECK: define i32 @bar()
|
// CHECK: define i32 @bar()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that pragma redefine_extname applies to C code only, and shouldn't be
|
||||||
|
// applied to C++.
|
||||||
|
#pragma redefine_extname foo_cpp bar_cpp
|
||||||
|
extern int foo_cpp() { return 1; }
|
||||||
|
// CHECK-NOT: define i32 @bar_cpp()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
// RUN: %clang_cc1 -triple=x86_64-unknown-linux -Wpragmas -verify %s
|
||||||
|
|
||||||
|
// Check that pragma redefine_extname applies to C code only, and shouldn't be
|
||||||
|
// applied to C++.
|
||||||
|
#pragma redefine_extname foo_cpp bar_cpp
|
||||||
|
extern int foo_cpp() { return 1; } // expected-warning {{#pragma redefine_extname is applicable to external C declarations only; not applied to function 'foo_cpp'}}
|
Loading…
Reference in New Issue