[clang] [clang][Tooling] Add special symbol mappings for C, starting with size_t (PR #85784)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 19 05:36:58 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: kadir çetinkaya (kadircet)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/85784.diff
3 Files Affected:
- (added) clang/lib/Tooling/Inclusions/Stdlib/CSpecialSymbolMap.inc (+8)
- (modified) clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp (+2-1)
- (modified) clang/unittests/Tooling/StandardLibraryTest.cpp (+12)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/85784
More information about the cfe-commits
mailing list