AntonBikineev updated this revision to Diff 212882. AntonBikineev added a comment.
Roman, -ast-dump shows the correct result, because the correct address space is encoded in qualifiers and is passed to Context.getAddrSpaceQualType(...) later in this function. This is why this bug is not observable from the AST. But if you try accessing real Attr* from TypeSourceInfo, you'll see this mismatch. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D65589/new/ https://reviews.llvm.org/D65589 Files: clang/lib/Sema/SemaType.cpp clang/unittests/AST/ASTTraverserTest.cpp Index: clang/unittests/AST/ASTTraverserTest.cpp =================================================================== --- clang/unittests/AST/ASTTraverserTest.cpp +++ clang/unittests/AST/ASTTraverserTest.cpp @@ -139,6 +139,8 @@ { }; +void parmvardecl_attr(struct A __attribute__((address_space(19)))*); + )cpp"); const FunctionDecl *Func = getFunctionNode(AST.get(), "func"); @@ -220,5 +222,16 @@ R"cpp( TemplateArgument )cpp"); + + Func = getFunctionNode(AST.get(), "parmvardecl_attr"); + + const auto *Parm = Func->getParamDecl(0); + const auto TL = Parm->getTypeSourceInfo()->getTypeLoc(); + ASSERT_TRUE(TL.getType()->isPointerType()); + + const auto ATL = TL.getNextTypeLoc().getAs<AttributedTypeLoc>(); + const auto *AS = cast<AddressSpaceAttr>(ATL.getAttr()); + EXPECT_EQ(toTargetAddressSpace(static_cast<LangAS>(AS->getAddressSpace())), + 19u); } } // namespace clang Index: clang/lib/Sema/SemaType.cpp =================================================================== --- clang/lib/Sema/SemaType.cpp +++ clang/lib/Sema/SemaType.cpp @@ -5978,9 +5978,9 @@ } ASTContext &Ctx = S.Context; - auto *ASAttr = ::new (Ctx) AddressSpaceAttr( - Attr.getRange(), Ctx, Attr.getAttributeSpellingListIndex(), - static_cast<unsigned>(ASIdx)); + auto *ASAttr = ::new (Ctx) + AddressSpaceAttr(Attr.getRange(), Ctx, static_cast<unsigned>(ASIdx), + Attr.getAttributeSpellingListIndex()); // If the expression is not value dependent (not templated), then we can // apply the address space qualifiers just to the equivalent type.
Index: clang/unittests/AST/ASTTraverserTest.cpp =================================================================== --- clang/unittests/AST/ASTTraverserTest.cpp +++ clang/unittests/AST/ASTTraverserTest.cpp @@ -139,6 +139,8 @@ { }; +void parmvardecl_attr(struct A __attribute__((address_space(19)))*); + )cpp"); const FunctionDecl *Func = getFunctionNode(AST.get(), "func"); @@ -220,5 +222,16 @@ R"cpp( TemplateArgument )cpp"); + + Func = getFunctionNode(AST.get(), "parmvardecl_attr"); + + const auto *Parm = Func->getParamDecl(0); + const auto TL = Parm->getTypeSourceInfo()->getTypeLoc(); + ASSERT_TRUE(TL.getType()->isPointerType()); + + const auto ATL = TL.getNextTypeLoc().getAs<AttributedTypeLoc>(); + const auto *AS = cast<AddressSpaceAttr>(ATL.getAttr()); + EXPECT_EQ(toTargetAddressSpace(static_cast<LangAS>(AS->getAddressSpace())), + 19u); } } // namespace clang Index: clang/lib/Sema/SemaType.cpp =================================================================== --- clang/lib/Sema/SemaType.cpp +++ clang/lib/Sema/SemaType.cpp @@ -5978,9 +5978,9 @@ } ASTContext &Ctx = S.Context; - auto *ASAttr = ::new (Ctx) AddressSpaceAttr( - Attr.getRange(), Ctx, Attr.getAttributeSpellingListIndex(), - static_cast<unsigned>(ASIdx)); + auto *ASAttr = ::new (Ctx) + AddressSpaceAttr(Attr.getRange(), Ctx, static_cast<unsigned>(ASIdx), + Attr.getAttributeSpellingListIndex()); // If the expression is not value dependent (not templated), then we can // apply the address space qualifiers just to the equivalent type.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits