Skip to content

Commit 756c205

Browse files
authored
[clang][Tooling] Add special symbol mappings for C, starting with size_t (#85784)
1 parent 9848fa4 commit 756c205

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===-- StdSpecialSymbolMap.inc -----------------------------------*- C -*-===//
2+
//
3+
// This is a hand-curated list for C symbols that cannot be parsed/extracted
4+
// via the include-mapping tool (gen_std.py).
5+
//
6+
//===----------------------------------------------------------------------===//
7+
8+
SYMBOL(size_t, None, <stddef.h>)
9+
SYMBOL(size_t, None, <stdio.h>)
10+
SYMBOL(size_t, None, <stdlib.h>)
11+
SYMBOL(size_t, None, <string.h>)
12+
SYMBOL(size_t, None, <time.h>)
13+
SYMBOL(size_t, None, <uchar.h>)
14+
SYMBOL(size_t, None, <wchar.h>)

clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ static const SymbolHeaderMapping *getMappingPerLang(Lang L) {
5555
}
5656

5757
static int countSymbols(Lang Language) {
58-
ArrayRef<const char*> Symbols;
58+
ArrayRef<const char *> Symbols;
5959
#define SYMBOL(Name, NS, Header) #NS #Name,
6060
switch (Language) {
6161
case Lang::C: {
6262
static constexpr const char *CSymbols[] = {
63+
#include "CSpecialSymbolMap.inc"
6364
#include "CSymbolMap.inc"
6465
};
6566
Symbols = CSymbols;
@@ -147,6 +148,7 @@ static int initialize(Lang Language) {
147148
switch (Language) {
148149
case Lang::C: {
149150
static constexpr Symbol CSymbols[] = {
151+
#include "CSpecialSymbolMap.inc"
150152
#include "CSymbolMap.inc"
151153
};
152154
for (const Symbol &S : CSymbols)

clang/unittests/Tooling/StandardLibraryTest.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ TEST(StdlibTest, RecognizerForC99) {
185185
stdlib::Symbol::named("", "uint8_t", stdlib::Lang::C));
186186
}
187187

188+
TEST(StdlibTest, SpecialCMappings) {
189+
TestInputs Input("typedef char size_t;");
190+
Input.Language = TestLanguage::Lang_C99;
191+
TestAST AST(Input);
192+
193+
auto &SizeT = lookup(AST, "size_t");
194+
stdlib::Recognizer Recognizer;
195+
auto ActualSym = Recognizer(&SizeT);
196+
assert(ActualSym);
197+
EXPECT_EQ(ActualSym, stdlib::Symbol::named("", "size_t", stdlib::Lang::C));
198+
EXPECT_EQ(ActualSym->header()->name(), "<stddef.h>");
199+
}
200+
188201
} // namespace
189202
} // namespace tooling
190203
} // namespace clang

0 commit comments

Comments
 (0)