This repository was archived by the owner on Nov 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path0002-MSVC-Compatibility.patch
55 lines (54 loc) · 2.71 KB
/
0002-MSVC-Compatibility.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
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index ea96bb12bec6..da4e787bb994 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -151,7 +151,7 @@ class Preprocessor {
llvm::BumpPtrAllocator BP;
/// Identifiers for builtin macros and other builtins.
- IdentifierInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__
+ IdentifierInfo *Ident__LINE__, *Ident__FILE__, *Ident__FUNCTION__; // __LINE__, __FILE__, __FUNCTION__(FIX MSVC Compatibility)
IdentifierInfo *Ident__DATE__, *Ident__TIME__; // __DATE__, __TIME__
IdentifierInfo *Ident__INCLUDE_LEVEL__; // __INCLUDE_LEVEL__
IdentifierInfo *Ident__BASE_FILE__; // __BASE_FILE__
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index cfee7a3c2513..ab3bbddb711c 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -336,7 +336,13 @@ static IdentifierInfo *RegisterBuiltinMacro(Preprocessor &PP, const char *Name){
/// RegisterBuiltinMacros - Register builtin macros, such as __LINE__ with the
/// identifier table.
void Preprocessor::RegisterBuiltinMacros() {
+ //[MSVC Compatibility]
+#ifdef _WIN32
+ Ident__FUNCTION__ = RegisterBuiltinMacro(*this, "__FUNCTION__");
Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");
+#else
+ Ident__FUNCTION__ = Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");
+#endif
Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__");
Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__");
Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
@@ -1506,7 +1512,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
OS << (PLoc.isValid()? PLoc.getLine() : 1);
Tok.setKind(tok::numeric_constant);
} else if (II == Ident__FILE__ || II == Ident__BASE_FILE__ ||
- II == Ident__FILE_NAME__) {
+ II == Ident__FILE_NAME__ || II == Ident__FUNCTION__) {
// C99 6.10.8: "__FILE__: The presumed name of the current source file (a
// character string literal)". This can be affected by #line.
PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
@@ -1539,6 +1545,14 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
FN += PLoc.getFilename();
} else {
FN += PLoc.getFilename();
+ //[MSVC Compalibility] Use file name and line to replace '__FUNCTION__'
+#ifdef _WIN32
+ if (II == Ident__FUNCTION__) {
+ FN += "(";
+ FN += Twine(PLoc.getLine()).str();
+ FN += ")";
+ }
+#endif
}
getLangOpts().remapPathPrefix(FN);
Lexer::Stringify(FN);