[PATCH] D155816: [Tooling/Inclusion] Make the Recognizer work for C99 code.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 20 05:05:14 PDT 2023


hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang.

C99 is the the earliest C version provided by the language opt.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155816

Files:
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/unittests/Tooling/StandardLibraryTest.cpp


Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===================================================================
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -174,6 +174,17 @@
   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
Index: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
===================================================================
--- clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -247,13 +247,12 @@
 
 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155816.542434.patch
Type: text/x-patch
Size: 1463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230720/9ecb17ff/attachment.bin>


More information about the cfe-commits mailing list