Author: Owen Anderson
Date: 2025-04-20T00:01:53+12:00
New Revision: a15ef95de47620d580df21bdf35afeeb324e452d

URL: 
https://github.com/llvm/llvm-project/commit/a15ef95de47620d580df21bdf35afeeb324e452d
DIFF: 
https://github.com/llvm/llvm-project/commit/a15ef95de47620d580df21bdf35afeeb324e452d.diff

LOG: Revert "FunctionDecl::getFunctionTypeLoc: ignore function type attributes 
(#118420)"

This reverts commit 19c708c18963ac24822564824cb5401e71a49943 because it caused 
test failures on non-x86 targets.

Added: 
    

Modified: 
    clang-tools-extra/clangd/unittests/InlayHintTests.cpp
    clang/lib/AST/Decl.cpp
    clang/unittests/AST/AttrTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 030e499577706..77d78b8777fe3 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1577,21 +1577,19 @@ TEST(TypeHints, Aliased) {
 }
 
 TEST(TypeHints, CallingConvention) {
-  // Check that we don't crash for lambdas with an annotation
+  // Check that we don't crash for lambdas without a FunctionTypeLoc
   // https://github.com/clangd/clangd/issues/2223
-  Annotations Source(R"cpp(
+  std::string Code = R"cpp(
     void test() {
-      []($lambda[[)]]__cdecl {};
+      []() __cdecl {};
     }
-  )cpp");
-  TestTU TU = TestTU::withCode(Source.code());
+  )cpp";
+  TestTU TU = TestTU::withCode(Code);
   TU.ExtraArgs.push_back("--target=x86_64-w64-mingw32");
   TU.PredefineMacros = true; // for the __cdecl
   auto AST = TU.build();
 
-  EXPECT_THAT(
-      hintsOfKind(AST, InlayHintKind::Type),
-      ElementsAre(HintMatcher(ExpectedHint{"-> void", "lambda"}, Source)));
+  EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type), IsEmpty());
 }
 
 TEST(TypeHints, Decltype) {

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 1d9208f0e1c72..ad1cb01592e9b 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3910,25 +3910,8 @@ bool 
FunctionDecl::doesDeclarationForceExternallyVisibleDefinition() const {
 
 FunctionTypeLoc FunctionDecl::getFunctionTypeLoc() const {
   const TypeSourceInfo *TSI = getTypeSourceInfo();
-
-  if (!TSI)
-    return FunctionTypeLoc();
-
-  TypeLoc TL = TSI->getTypeLoc();
-  FunctionTypeLoc FTL;
-
-  while (!(FTL = TL.getAs<FunctionTypeLoc>())) {
-    if (const auto PTL = TL.getAs<ParenTypeLoc>())
-      TL = PTL.getInnerLoc();
-    else if (const auto ATL = TL.getAs<AttributedTypeLoc>())
-      TL = ATL.getEquivalentTypeLoc();
-    else if (const auto MQTL = TL.getAs<MacroQualifiedTypeLoc>())
-      TL = MQTL.getInnerLoc();
-    else
-      break;
-  }
-
-  return FTL;
+  return TSI ? TSI->getTypeLoc().IgnoreParens().getAs<FunctionTypeLoc>()
+             : FunctionTypeLoc();
 }
 
 SourceRange FunctionDecl::getReturnTypeSourceRange() const {

diff  --git a/clang/unittests/AST/AttrTest.cpp 
b/clang/unittests/AST/AttrTest.cpp
index 3be362895b77e..46c3f5729021e 100644
--- a/clang/unittests/AST/AttrTest.cpp
+++ b/clang/unittests/AST/AttrTest.cpp
@@ -86,23 +86,6 @@ TEST(Attr, AnnotateType) {
     struct S { int mem; };
     int [[clang::annotate_type("int")]]
     S::* [[clang::annotate_type("ptr_to_mem")]] ptr_to_member = &S::mem;
-
-    // Function Type Attributes
-    __attribute__((noreturn)) int f_noreturn();
-    __attribute__((preserve_most)) int f_cc_preserve_most();
-
-    #define PRESERVE_MOST __attribute__((preserve_most))
-    PRESERVE_MOST int f_macro_attribue();
-
-    int (__attribute__((preserve_most)) f_paren_attribute)();
-
-    int (
-      PRESERVE_MOST
-      (
-        __attribute__((warn_unused_result))
-        (f_w_paren_and_attr)
-      )
-    ) ();
   )cpp");
 
   {
@@ -170,67 +153,6 @@ TEST(Attr, AnnotateType) {
     EXPECT_EQ(IntTL.getType(), AST->getASTContext().IntTy);
   }
 
-  {
-    const FunctionDecl *Func = getFunctionNode(AST.get(), "f_noreturn");
-    const FunctionTypeLoc FTL = Func->getFunctionTypeLoc();
-    const FunctionType *FT = FTL.getTypePtr();
-
-    EXPECT_TRUE(FT->getNoReturnAttr());
-  }
-
-  {
-    const FunctionDecl *Func = getFunctionNode(AST.get(), 
"f_cc_preserve_most");
-    const FunctionTypeLoc FTL = Func->getFunctionTypeLoc();
-    const FunctionType *FT = FTL.getTypePtr();
-
-    EXPECT_TRUE(FT->getCallConv() == CC_PreserveMost);
-  }
-
-  {
-    for (auto should_have_func_type_loc : {
-             "f_macro_attribue",
-             "f_paren_attribute",
-             "f_w_paren_and_attr",
-         }) {
-      llvm::errs() << "O: " << should_have_func_type_loc << "\n";
-      const FunctionDecl *Func =
-          getFunctionNode(AST.get(), should_have_func_type_loc);
-
-      EXPECT_TRUE(Func->getFunctionTypeLoc());
-    }
-  }
-
-  // The following test verifies getFunctionTypeLoc returns a type
-  // which takes into account the attribute (instead of only the nake
-  // type).
-  //
-  // This is hard to do with C/C++ because it seems using a function
-  // type attribute with a C/C++ function declaration only results
-  // with either:
-  //
-  // 1. It does NOT produce any AttributedType (for example it only
-  //   sets one flag of the FunctionType's ExtInfo, e.g. NoReturn).
-  // 2. It produces an AttributedType with modified type and
-  //   equivalent type that are equal (for example, that's what
-  //   happens with Calling Convention attributes).
-  //
-  // Fortunately, ObjC has one specific function type attribute that
-  // creates an AttributedType with 
diff erent modified type and
-  // equivalent type.
-  auto AST_ObjC = buildASTFromCodeWithArgs(
-      R"objc(
-    __attribute__((ns_returns_retained)) id f();
-  )objc",
-      {"-fobjc-arc", "-fsyntax-only", "-fobjc-runtime=macosx-10.7"},
-      "input.mm");
-  {
-    const FunctionDecl *f = getFunctionNode(AST_ObjC.get(), "f");
-    const FunctionTypeLoc FTL = f->getFunctionTypeLoc();
-
-    const FunctionType *FT = FTL.getTypePtr();
-    EXPECT_TRUE(FT->getExtInfo().getProducesResult());
-  }
-
   // Test type annotation on an `__auto_type` type in C mode.
   AST = buildASTFromCodeWithArgs(R"c(
     __auto_type [[clang::annotate_type("auto")]] auto_var = 1;


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to