Skip to content

Commit 2188dfe

Browse files
committed
Merge from 'master' to 'sycl-web' (intel#7)
2 parents 99ca82f + e3d8ee3 commit 2188dfe

File tree

33 files changed

+351
-197
lines changed

33 files changed

+351
-197
lines changed

clang/include/clang/AST/ASTConsumer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ class ASTConsumer {
102102
/// modified by the introduction of an implicit zero initializer.
103103
virtual void CompleteTentativeDefinition(VarDecl *D) {}
104104

105+
/// CompleteExternalDeclaration - Callback invoked at the end of a translation
106+
/// unit to notify the consumer that the given external declaration should be
107+
/// completed.
108+
virtual void CompleteExternalDeclaration(VarDecl *D) {}
109+
105110
/// Callback invoked when an MSInheritanceAttr has been attached to a
106111
/// CXXRecordDecl.
107112
virtual void AssignInheritanceModel(CXXRecordDecl *RD) {}

clang/include/clang/Basic/TargetInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,9 @@ class TargetInfo : public virtual TransferrableTargetInfo,
13891389

13901390
virtual void setAuxTarget(const TargetInfo *Aux) {}
13911391

1392+
/// Whether target allows debuginfo types for decl only variables.
1393+
virtual bool allowDebugInfoForExternalVar() const { return false; }
1394+
13921395
protected:
13931396
/// Copy type and layout related info.
13941397
void copyAuxTarget(const TargetInfo *Aux);

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,9 @@ class Sema final {
790790
/// All the tentative definitions encountered in the TU.
791791
TentativeDefinitionsType TentativeDefinitions;
792792

793+
/// All the external declarations encoutered and used in the TU.
794+
SmallVector<VarDecl *, 4> ExternalDeclarations;
795+
793796
typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
794797
&ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
795798
UnusedFileScopedDeclsType;

clang/lib/Basic/Targets/BPF.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
7676
return None;
7777
}
7878

79+
bool allowDebugInfoForExternalVar() const override { return true; }
80+
7981
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
8082
switch (CC) {
8183
default:

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4485,7 +4485,7 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
44854485

44864486
GVE = DBuilder.createGlobalVariableExpression(
44874487
DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
4488-
Var->hasLocalLinkage(),
4488+
Var->hasLocalLinkage(), true,
44894489
Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
44904490
getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
44914491
Align);
@@ -4588,10 +4588,29 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
45884588

45894589
GV.reset(DBuilder.createGlobalVariableExpression(
45904590
DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
4591-
true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
4591+
true, true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
45924592
TemplateParameters, Align));
45934593
}
45944594

4595+
void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
4596+
const VarDecl *D) {
4597+
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
4598+
if (D->hasAttr<NoDebugAttr>())
4599+
return;
4600+
4601+
auto Align = getDeclAlignIfRequired(D, CGM.getContext());
4602+
llvm::DIFile *Unit = getOrCreateFile(D->getLocation());
4603+
StringRef Name = D->getName();
4604+
llvm::DIType *Ty = getOrCreateType(D->getType(), Unit);
4605+
4606+
llvm::DIScope *DContext = getDeclContextDescriptor(D);
4607+
llvm::DIGlobalVariableExpression *GVE =
4608+
DBuilder.createGlobalVariableExpression(
4609+
DContext, Name, StringRef(), Unit, getLineNumber(D->getLocation()),
4610+
Ty, false, false, nullptr, nullptr, nullptr, Align);
4611+
Var->addDebugInfo(GVE);
4612+
}
4613+
45954614
llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
45964615
if (!LexicalBlockStack.empty())
45974616
return LexicalBlockStack.back();

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ class CGDebugInfo {
478478
/// Emit a constant global variable's debug info.
479479
void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);
480480

481+
/// Emit information about an external variable.
482+
void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
483+
481484
/// Emit C++ using directive.
482485
void EmitUsingDirective(const UsingDirectiveDecl &UD);
483486

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ namespace clang {
336336
Gen->CompleteTentativeDefinition(D);
337337
}
338338

339+
void CompleteExternalDeclaration(VarDecl *D) override {
340+
Gen->CompleteExternalDeclaration(D);
341+
}
342+
339343
void AssignInheritanceModel(CXXRecordDecl *RD) override {
340344
Gen->AssignInheritanceModel(RD);
341345
}

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3768,6 +3768,10 @@ void CodeGenModule::EmitTentativeDefinition(const VarDecl *D) {
37683768
EmitGlobalVarDefinition(D);
37693769
}
37703770

3771+
void CodeGenModule::EmitExternalDeclaration(const VarDecl *D) {
3772+
EmitExternalVarDeclaration(D);
3773+
}
3774+
37713775
CharUnits CodeGenModule::GetTargetTypeStoreSize(llvm::Type *Ty) const {
37723776
return Context.toCharUnitsFromBits(
37733777
getDataLayout().getTypeStoreSizeInBits(Ty));
@@ -4285,6 +4289,19 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
42854289
DI->EmitGlobalVariable(GV, D);
42864290
}
42874291

4292+
void CodeGenModule::EmitExternalVarDeclaration(const VarDecl *D) {
4293+
if (CGDebugInfo *DI = getModuleDebugInfo())
4294+
if (getCodeGenOpts().getDebugInfo() >= codegenoptions::LimitedDebugInfo) {
4295+
QualType ASTTy = D->getType();
4296+
llvm::Type *Ty = getTypes().ConvertTypeForMem(D->getType());
4297+
llvm::PointerType *PTy =
4298+
llvm::PointerType::get(Ty, getContext().getTargetAddressSpace(ASTTy));
4299+
llvm::Constant *GV = GetOrCreateLLVMGlobal(D->getName(), PTy, D);
4300+
DI->EmitExternalVariable(
4301+
cast<llvm::GlobalVariable>(GV->stripPointerCasts()), D);
4302+
}
4303+
}
4304+
42884305
static bool isVarDeclStrongDefinition(const ASTContext &Context,
42894306
CodeGenModule &CGM, const VarDecl *D,
42904307
bool NoCommon) {

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,8 @@ class CodeGenModule : public CodeGenTypeCache {
11831183

11841184
void EmitTentativeDefinition(const VarDecl *D);
11851185

1186+
void EmitExternalDeclaration(const VarDecl *D);
1187+
11861188
void EmitVTable(CXXRecordDecl *Class);
11871189

11881190
void RefreshTypeCacheForClass(const CXXRecordDecl *Class);
@@ -1418,6 +1420,7 @@ class CodeGenModule : public CodeGenTypeCache {
14181420
void EmitMultiVersionFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
14191421

14201422
void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
1423+
void EmitExternalVarDeclaration(const VarDecl *D);
14211424
void EmitAliasDefinition(GlobalDecl GD);
14221425
void emitIFuncDefinition(GlobalDecl GD);
14231426
void emitCPUDispatchDefinition(GlobalDecl GD);

clang/lib/CodeGen/ModuleBuilder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ namespace {
290290
Builder->EmitTentativeDefinition(D);
291291
}
292292

293+
void CompleteExternalDeclaration(VarDecl *D) override {
294+
Builder->EmitExternalDeclaration(D);
295+
}
296+
293297
void HandleVTable(CXXRecordDecl *RD) override {
294298
if (Diags.hasErrorOccurred())
295299
return;

clang/lib/Sema/Sema.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,13 @@ void Sema::ActOnEndOfTranslationUnit() {
11571157
Consumer.CompleteTentativeDefinition(VD);
11581158
}
11591159

1160+
for (auto D : ExternalDeclarations) {
1161+
if (!D || D->isInvalidDecl() || D->getPreviousDecl() || !D->isUsed())
1162+
continue;
1163+
1164+
Consumer.CompleteExternalDeclaration(D);
1165+
}
1166+
11601167
// If there were errors, disable 'unused' warnings since they will mostly be
11611168
// noise. Don't warn for a use from a module: either we should warn on all
11621169
// file-scope declarations in modules or not at all, but whether the

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12223,6 +12223,10 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
1222312223
Diag(Var->getLocation(), diag::note_private_extern);
1222412224
}
1222512225

12226+
if (Context.getTargetInfo().allowDebugInfoForExternalVar() &&
12227+
!Var->isInvalidDecl() && !getLangOpts().CPlusPlus)
12228+
ExternalDeclarations.push_back(Var);
12229+
1222612230
return;
1222712231

1222812232
case VarDecl::TentativeDefinition:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple bpf-linux-gnu -emit-llvm %s -o - | FileCheck %s
2+
3+
extern char ch;
4+
int test() {
5+
return ch;
6+
}
7+
8+
int test2() {
9+
extern char ch2;
10+
return ch2;
11+
}
12+
13+
extern int (*foo)(int);
14+
int test3() {
15+
return foo(0);
16+
}
17+
18+
// CHECK: distinct !DIGlobalVariable(name: "ch",{{.*}} type: ![[CHART:[0-9]+]], isLocal: false, isDefinition: false
19+
// CHECK: distinct !DIGlobalVariable(name: "ch2",{{.*}} type: ![[CHART]], isLocal: false, isDefinition: false
20+
// CHECK: ![[CHART]] = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
21+
22+
// CHECK: distinct !DIGlobalVariable(name: "foo",{{.*}} type: ![[FUNC:[0-9]+]], isLocal: false, isDefinition: false)
23+
// CHECK: ![[FUNC]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[SUB:[0-9]+]], size: 64)
24+
// CHECK: ![[SUB]] = !DISubroutineType(types: ![[TYPES:[0-9]+]])
25+
// CHECK: ![[TYPES]] = !{![[BASET:[0-9]+]], ![[BASET]]}
26+
// CHECK: ![[BASET]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple bpf-linux-gnu -emit-llvm %s -o - | FileCheck %s
2+
3+
extern char ch;
4+
extern char ch;
5+
int test() {
6+
return ch;
7+
}
8+
9+
// CHECK: distinct !DIGlobalVariable(name: "ch",{{.*}} type: ![[T:[0-9]+]], isLocal: false, isDefinition: false
10+
// CHECK-NOT: distinct !DIGlobalVariable(name: "ch"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple bpf-linux-gnu -emit-llvm %s -o - | FileCheck %s
2+
3+
extern char ch;
4+
int test() {
5+
extern short sh;
6+
return ch + sh;
7+
}
8+
9+
extern char (*foo)(char);
10+
int test2() {
11+
return foo(0) + ch;
12+
}
13+
14+
// CHECK: distinct !DIGlobalVariable(name: "ch",{{.*}} type: ![[Tch:[0-9]+]], isLocal: false, isDefinition: false
15+
// CHECK: distinct !DIGlobalVariable(name: "sh",{{.*}} type: ![[Tsh:[0-9]+]], isLocal: false, isDefinition: false
16+
// CHECK: ![[Tsh]] = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed)
17+
18+
// CHECK: distinct !DIGlobalVariable(name: "foo",{{.*}} type: ![[Tptr:[0-9]+]], isLocal: false, isDefinition: false
19+
// ![[Tptr]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[Tsub:[0-9]+]], size: 64)
20+
// ![[Tsub]] = !DISubroutineType(types: ![[Tproto:[0-9]+]])
21+
// ![[Tproto]] = !{![[Tch]], ![[Tch]]}
22+
// CHECK: ![[Tch]] = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple bpf-linux-gnu -emit-llvm %s -o - | FileCheck %s
2+
3+
extern char ch;
4+
int test() {
5+
return 0;
6+
}
7+
8+
int test2() {
9+
extern char ch2;
10+
return 0;
11+
}
12+
13+
extern int (*foo)(int);
14+
int test3() {
15+
return 0;
16+
}
17+
18+
int test4() {
19+
extern int (*foo2)(int);
20+
return 0;
21+
}
22+
23+
// CHECK-NOT: distinct !DIGlobalVariable(name: "ch"
24+
// CHECK-NOT: distinct !DIGlobalVariable(name: "ch2"
25+
// CHECK-NOT: distinct !DIGlobalVariable(name: "foo"
26+
// CHECK-NOT: distinct !DIGlobalVariable(name: "foo2"

lld/ELF/Relocations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ static bool isStaticLinkTimeConstant(RelExpr e, RelType type, const Symbol &sym,
375375
R_AARCH64_GOT_PAGE_PC, R_GOT_PC, R_GOTONLY_PC, R_GOTPLTONLY_PC,
376376
R_PLT_PC, R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC, R_PPC32_PLTREL,
377377
R_PPC64_CALL_PLT, R_PPC64_RELAX_TOC, R_RISCV_ADD, R_TLSDESC_CALL,
378-
R_TLSDESC_PC, R_AARCH64_TLSDESC_PAGE, R_HINT, R_TLSLD_HINT,
379-
R_TLSIE_HINT>(e))
378+
R_TLSDESC_PC, R_AARCH64_TLSDESC_PAGE, R_TLSLD_HINT, R_TLSIE_HINT>(
379+
e))
380380
return true;
381381

382382
// These never do, except if the entire file is position dependent or if

lldb/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
cmake_minimum_required(VERSION 3.4.3)
2+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
3+
cmake_minimum_required(VERSION 3.13)
4+
endif()
25

36
if(POLICY CMP0075)
47
cmake_policy(SET CMP0075 NEW)

0 commit comments

Comments
 (0)