Skip to content

Commit fc467b0

Browse files
committed
Emit compiler version to the ObjC message trace file
1 parent 0ffc76a commit fc467b0

File tree

3 files changed

+66
-60
lines changed

3 files changed

+66
-60
lines changed

clang/include/clang/AST/ObjCMethodReferenceInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ObjCMethodDecl;
2424

2525
struct ObjCMethodReferenceInfo {
2626
static constexpr unsigned FormatVersion = 1;
27+
std::string ToolName, ToolVersion;
2728
std::string Target, TargetVariant;
2829

2930
/// Paths to the files in which ObjC methods are referenced.

clang/lib/AST/ASTContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include "clang/Basic/Specifiers.h"
6868
#include "clang/Basic/TargetCXXABI.h"
6969
#include "clang/Basic/TargetInfo.h"
70+
#include "clang/Basic/Version.h"
7071
#include "clang/Basic/XRayLists.h"
7172
#include "llvm/ADT/APFixedPoint.h"
7273
#include "llvm/ADT/APInt.h"
@@ -9296,6 +9297,7 @@ void clang::serializeObjCMethodReferencesAsJson(
92969297
const clang::ObjCMethodReferenceInfo &Info, llvm::raw_ostream &OS) {
92979298
llvm::json::OStream Out(OS, /*IndentSize=*/4);
92989299
Out.object([&] {
9300+
Out.attribute(Info.ToolName, Info.ToolVersion);
92999301
Out.attribute("format-version", Info.FormatVersion);
93009302
Out.attribute("target", Info.Target);
93019303
if (!Info.TargetVariant.empty())
@@ -9361,6 +9363,8 @@ void ASTContext::writeObjCMsgSendUsages(const std::string &Filename) {
93619363
SourceMgr.getFileEntryRefForID(SourceMgr.getMainFileID());
93629364
SmallString<256> MainFile(FE->getName());
93639365
SourceMgr.getFileManager().makeAbsolutePath(MainFile);
9366+
Info.ToolName = "clang-compiler-version";
9367+
Info.ToolVersion = getClangFullVersion();
93649368
Info.Target = getTargetInfo().getTriple().str();
93659369
if (auto *VariantTriple = getTargetInfo().getDarwinTargetVariantTriple())
93669370
Info.TargetVariant = VariantTriple->str();

clang/test/AST/objc-method-tracing.mm

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,64 @@
11
// RUN: env CLANG_COMPILER_OBJC_MESSAGE_TRACE_PATH=%t.txt %clang_cc1 -fsyntax-only -triple arm64-apple-macosx15.0.0 -I %S/Inputs %s
22
// RUN: cat %t.txt | FileCheck %s
33

4+
#include "objc-method-tracing.h"
5+
6+
@interface B(Cat1)
7+
-(void)m2;
8+
@end
9+
10+
@interface B()
11+
-(void)m6;
12+
@end
13+
14+
@implementation B
15+
-(void)m7:(int)i arg1:(float)f {
16+
}
17+
@end
18+
19+
@implementation B(Cat1)
20+
-(void)m8 {
21+
}
22+
@end
23+
24+
void test0(A *a) {
25+
[a m0];
26+
}
27+
28+
void test1(B *b) {
29+
[b m0];
30+
}
31+
32+
void test2(B *b) {
33+
[B m1];
34+
}
35+
36+
void test3(B *b) {
37+
[b m2];
38+
}
39+
40+
void test4(C *c) {
41+
[c m4];
42+
}
43+
44+
void test5(id<P0> p0) {
45+
[p0 m5];
46+
}
47+
48+
void test6(B *b) {
49+
[b m6];
50+
}
51+
52+
void test7(B *b) {
53+
[b m7:123 arg1:4.5f];
54+
}
55+
56+
void test8(B *b) {
57+
[b m8];
58+
}
59+
460
// CHECK: {
61+
// CHECK-NEXT: "clang-compiler-version": "clang version
562
// CHECK-NEXT: "format-version": 1,
663
// CHECK-NEXT: "target": "arm64-apple-macosx15.0.0",
764
// CHECK-NEXT: "references": [
@@ -27,7 +84,7 @@
2784
// CHECK-NEXT: "interface_type": "B",
2885
// CHECK-NEXT: "category_type": "Cat1",
2986
// CHECK-NEXT: "instance_method": "-[B(Cat1) m2]",
30-
// CHECK-NEXT: "declared_at": "[[SOURCE_FILE:.*]]:12:1",
87+
// CHECK-NEXT: "declared_at": "[[SOURCE_FILE:.*]]:7:1",
3188
// CHECK-NEXT: "referenced_at_file_id": 1
3289
// CHECK-NEXT: },
3390
// CHECK-NEXT: {
@@ -46,20 +103,20 @@
46103
// CHECK-NEXT: "interface_type": "B",
47104
// CHECK-NEXT: "category_type": "",
48105
// CHECK-NEXT: "instance_method": "-[B() m6]",
49-
// CHECK-NEXT: "declared_at": "[[SOURCE_FILE]]:16:1",
106+
// CHECK-NEXT: "declared_at": "[[SOURCE_FILE]]:11:1",
50107
// CHECK-NEXT: "referenced_at_file_id": 1
51108
// CHECK-NEXT: },
52109
// CHECK-NEXT: {
53110
// CHECK-NEXT: "implementation_type": "B",
54111
// CHECK-NEXT: "instance_method": "-[B m7:arg1:]",
55-
// CHECK-NEXT: "declared_at": "[[SOURCE_FILE]]:20:1",
112+
// CHECK-NEXT: "declared_at": "[[SOURCE_FILE]]:15:1",
56113
// CHECK-NEXT: "referenced_at_file_id": 1
57114
// CHECK-NEXT: },
58115
// CHECK-NEXT: {
59116
// CHECK-NEXT: "interface_type": "B",
60117
// CHECK-NEXT: "category_implementation_type": "Cat1",
61118
// CHECK-NEXT: "instance_method": "-[B(Cat1) m8]",
62-
// CHECK-NEXT: "declared_at": "[[SOURCE_FILE]]:25:1",
119+
// CHECK-NEXT: "declared_at": "[[SOURCE_FILE]]:20:1",
63120
// CHECK-NEXT: "referenced_at_file_id": 1
64121
// CHECK-NEXT: }
65122
// CHECK-NEXT: ],
@@ -70,59 +127,3 @@
70127
// CHECK-NEXT: }
71128
// CHECK-NEXT: ]
72129
// CHECK-NEXT: }
73-
74-
#include "objc-method-tracing.h"
75-
76-
@interface B(Cat1)
77-
-(void)m2;
78-
@end
79-
80-
@interface B()
81-
-(void)m6;
82-
@end
83-
84-
@implementation B
85-
-(void)m7:(int)i arg1:(float)f {
86-
}
87-
@end
88-
89-
@implementation B(Cat1)
90-
-(void)m8 {
91-
}
92-
@end
93-
94-
void test0(A *a) {
95-
[a m0];
96-
}
97-
98-
void test1(B *b) {
99-
[b m0];
100-
}
101-
102-
void test2(B *b) {
103-
[B m1];
104-
}
105-
106-
void test3(B *b) {
107-
[b m2];
108-
}
109-
110-
void test4(C *c) {
111-
[c m4];
112-
}
113-
114-
void test5(id<P0> p0) {
115-
[p0 m5];
116-
}
117-
118-
void test6(B *b) {
119-
[b m6];
120-
}
121-
122-
void test7(B *b) {
123-
[b m7:123 arg1:4.5f];
124-
}
125-
126-
void test8(B *b) {
127-
[b m8];
128-
}

0 commit comments

Comments
 (0)