-
Notifications
You must be signed in to change notification settings - Fork 5
/
clang-101f37a.patch
66 lines (59 loc) · 2.71 KB
/
clang-101f37a.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 3ecc87432..fa09e89a1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1967,6 +1967,9 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
!CodeGenOpts.SanitizeCfiCanonicalJumpTables)
CreateFunctionTypeMetadataForIcall(FD, F);
+ if (FD->hasAttr<AnnotateAttr>())
+ AddGlobalAnnotations(FD, F);
+
if (getLangOpts().OpenMP && FD->hasAttr<OMPDeclareSimdDeclAttr>())
getOpenMPRuntime().emitDeclareSimdFunction(FD, F);
@@ -2266,9 +2269,25 @@ void CodeGenModule::EmitVTablesOpportunistically() {
}
void CodeGenModule::EmitGlobalAnnotations() {
- if (Annotations.empty())
+ if (NeededAnnotations.empty())
return;
+ std::vector<llvm::Constant*> Annotations;
+
+ for (AnnotationMap::const_iterator it = NeededAnnotations.begin(),
+ end = NeededAnnotations.end(); it != end; ++it) {
+ llvm::Value* V = it->second;
+ if (!V)
+ continue;
+ llvm::GlobalValue* GV = cast<llvm::GlobalValue>(V);
+ const ValueDecl* D = it->first;
+ // Get the struct elements for these annotations.
+ for (specific_attr_iterator<AnnotateAttr>
+ ai = D->specific_attr_begin<AnnotateAttr>(),
+ ae = D->specific_attr_end<AnnotateAttr>(); ai != ae; ++ai)
+ Annotations.push_back(EmitAnnotateAttr(GV, *ai, D->getLocation()));
+ }
+
// Create a new global variable for the ConstantStruct in the Module.
llvm::Constant *Array = llvm::ConstantArray::get(llvm::ArrayType::get(
Annotations[0]->getType(), Annotations.size()), Annotations);
@@ -2337,9 +2356,7 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
void CodeGenModule::AddGlobalAnnotations(const ValueDecl *D,
llvm::GlobalValue *GV) {
assert(D->hasAttr<AnnotateAttr>() && "no annotate attribute");
- // Get the struct elements for these annotations.
- for (const auto *I : D->specific_attrs<AnnotateAttr>())
- Annotations.push_back(EmitAnnotateAttr(GV, I, D->getLocation()));
+ NeededAnnotations[D] = GV;
}
bool CodeGenModule::isInSanitizerBlacklist(SanitizerMask Kind,
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index 19085b582..35ac184d8 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -408,7 +408,8 @@ private:
CPUSpecificManglings;
/// Global annotations.
- std::vector<llvm::Constant*> Annotations;
+ typedef std::map<const ValueDecl*, llvm::WeakVH> AnnotationMap;
+ AnnotationMap NeededAnnotations;
/// Map used to get unique annotation strings.
llvm::StringMap<llvm::Constant*> AnnotationStrings;