[clang] [clang][Tooling] Add special symbol mappings for C, starting with size_t (PR #85784)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 19 05:36:25 PDT 2024
https://github.com/kadircet created https://github.com/llvm/llvm-project/pull/85784
None
>From 8b12e22a01058bcfdcf211b1f64d192d7c5f8463 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya <kadircet at google.com>
Date: Tue, 19 Mar 2024 13:33:35 +0100
Subject: [PATCH] [clang][Tooling] Add special symbol mappings for C, starting
with size_t
---
.../Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc | 8 ++++++++
.../Tooling/Inclusions/Stdlib/StandardLibrary.cpp | 3 ++-
clang/unittests/Tooling/StandardLibraryTest.cpp | 12 ++++++++++++
3 files changed, 22 insertions(+), 1 deletion(-)
create mode 100644 clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc
new file mode 100644
index 00000000000000..1d9c294d207970
--- /dev/null
+++ b/clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc
@@ -0,0 +1,8 @@
+//===-- StdSpecialSymbolMap.inc -----------------------------------*- C -*-===//
+//
+// This is a hand-curated list for C symbols that cannot be parsed/extracted
+// via the include-mapping tool (gen_std.py).
+//
+//===----------------------------------------------------------------------===//
+
+SYMBOL(size_t, None, <stddef.h>)
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index adf1b230ff0318..386094fc2992e1 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -55,11 +55,12 @@ static const SymbolHeaderMapping *getMappingPerLang(Lang L) {
}
static int countSymbols(Lang Language) {
- ArrayRef<const char*> Symbols;
+ ArrayRef<const char *> Symbols;
#define SYMBOL(Name, NS, Header) #NS #Name,
switch (Language) {
case Lang::C: {
static constexpr const char *CSymbols[] = {
+#include "CSpecialSymbolMap.inc"
#include "CSymbolMap.inc"
};
Symbols = CSymbols;
diff --git a/clang/unittests/Tooling/StandardLibraryTest.cpp b/clang/unittests/Tooling/StandardLibraryTest.cpp
index edca31649accfa..d93b7d1af82d37 100644
--- a/clang/unittests/Tooling/StandardLibraryTest.cpp
+++ b/clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -185,6 +185,18 @@ TEST(StdlibTest, RecognizerForC99) {
stdlib::Symbol::named("", "uint8_t", stdlib::Lang::C));
}
+TEST(StdlibTest, SpecialCMappings) {
+ TestInputs Input("typedef char size_t;");
+ Input.Language = TestLanguage::Lang_C99;
+ TestAST AST(Input);
+
+ auto &SizeT = lookup(AST, "size_t");
+ stdlib::Recognizer Recognizer;
+ auto ActualSym = Recognizer(&SizeT);
+ EXPECT_EQ(ActualSym, stdlib::Symbol::named("", "size_t", stdlib::Lang::C));
+ EXPECT_EQ(ActualSym->header()->name(), "<stddef.h>");
+}
+
} // namespace
} // namespace tooling
} // namespace clang
More information about the cfe-commits
mailing list