[clang] e93cbd1 - [Tooling/Inclusion] Make the Recognizer work for C99 code.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 25 06:48:36 PDT 2023
Author: Haojian Wu
Date: 2023-07-25T15:48:21+02:00
New Revision: e93cbd18c11281465246060d6c2a9ea1deae3360
URL: https://github.com/llvm/llvm-project/commit/e93cbd18c11281465246060d6c2a9ea1deae3360
DIFF: https://github.com/llvm/llvm-project/commit/e93cbd18c11281465246060d6c2a9ea1deae3360.diff
LOG: [Tooling/Inclusion] Make the Recognizer work for C99 code.
C99 is the the earliest C version provided by the language opt.
Differential Revision: https://reviews.llvm.org/D155816
Added:
Modified:
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
clang/unittests/Tooling/StandardLibraryTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index cfcb955831ad22..664f3b76f66128 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -247,13 +247,12 @@ NSSymbolMap *Recognizer::namespaceSymbols(const DeclContext *DC, Lang L) {
std::optional<Symbol> Recognizer::operator()(const Decl *D) {
Lang L;
- if (D->getLangOpts().CPlusPlus) {
+ if (D->getLangOpts().CPlusPlus)
L = Lang::CXX;
- } else if (D->getLangOpts().C11) {
+ else if (D->getLangOpts().C99)
L = Lang::C;
- } else {
+ else
return std::nullopt; // not a supported language.
- }
// If D is std::vector::iterator, `vector` is the outer symbol to look up.
// We keep all the candidate DCs as some may turn out to be anon enums.
diff --git a/clang/unittests/Tooling/StandardLibraryTest.cpp b/clang/unittests/Tooling/StandardLibraryTest.cpp
index 6d90bbdf3b6eb4..edca31649accfa 100644
--- a/clang/unittests/Tooling/StandardLibraryTest.cpp
+++ b/clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -174,6 +174,17 @@ TEST(StdlibTest, Recognizer) {
EXPECT_EQ(Recognizer(Sec), std::nullopt);
}
+TEST(StdlibTest, RecognizerForC99) {
+ TestInputs Input("typedef char uint8_t;");
+ Input.Language = TestLanguage::Lang_C99;
+ TestAST AST(Input);
+
+ auto &Uint8T = lookup(AST, "uint8_t");
+ stdlib::Recognizer Recognizer;
+ EXPECT_EQ(Recognizer(&Uint8T),
+ stdlib::Symbol::named("", "uint8_t", stdlib::Lang::C));
+}
+
} // namespace
} // namespace tooling
} // namespace clang
More information about the cfe-commits
mailing list