[clang] eadb4cf - Revert (2) "[AST] Add RParen loc for decltype AutoTypeloc."
Florian Hahn via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 12 02:09:50 PST 2022
Author: Florian Hahn
Date: 2022-01-12T10:09:37Z
New Revision: eadb4cfeeff55678eac0c9225f095567e1564424
URL: https://github.com/llvm/llvm-project/commit/eadb4cfeeff55678eac0c9225f095567e1564424
DIFF: https://github.com/llvm/llvm-project/commit/eadb4cfeeff55678eac0c9225f095567e1564424.diff
LOG: Revert (2) "[AST] Add RParen loc for decltype AutoTypeloc."
This reverts commit 41fbdfa4d5601cccbcdc0ded8ef35190d502f7f3.
The commit breaks stage 2 builds with debug info, e.g.
https://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/5088/console
Clang crashes with the following assertion when building
llvm-project/llvm/lib/Support/Timer.cpp
/usr/local/bin/sccache /Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/host-compiler/bin/clang++ -DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Support -I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support -Iinclude -I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/include -fno-stack-protector -fno-common -Wno-profile-instr-unprofiled -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -fmodules -fmodules-cache-path=/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/clang-build/Build/module.cache -fcxx-modules -Xclang -fmodules-local-submodule-visibility -gmodules -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -flto=thin -O2 -g -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -std=c++14 -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -MF lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o.d -o lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -c /Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support/Timer.cpp
Assertion failed: (((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow"), function getLocWithOffset, file /Users/buildslave/jenkins/workspace/clang-stage1-RA/llvm-project/clang/include/clang/Basic/SourceLocation.h, line 135.
Added:
Modified:
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
clang/include/clang/AST/TypeLoc.h
clang/lib/AST/TypeLoc.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/AST/ast-dump-template-decls-json.cpp
clang/test/AST/ast-dump-template-decls.cpp
clang/unittests/AST/SourceLocationTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index 2b9907d162664..d5c9fa7de811e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -285,12 +285,15 @@ SourceRange UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
return {};
}
- // If the return type is a constrained 'auto', we need to include the token
- // after the concept. Unfortunately, the source range of an AutoTypeLoc, if it
- // is constrained, does not include the 'auto'.
- // FIXME: fix the AutoTypeLoc location in clang.
+ // If the return type is a constrained 'auto' or 'decltype(auto)', we need to
+ // include the tokens after the concept. Unfortunately, the source range of an
+ // AutoTypeLoc, if it is constrained, does not include the 'auto' or
+ // 'decltype(auto)'. If the return type is a plain 'decltype(...)', the
+ // source range only contains the first 'decltype' token.
auto ATL = ReturnLoc.getAs<AutoTypeLoc>();
- if (ATL && ATL.isConstrained() && !ATL.isDecltypeAuto()) {
+ if ((ATL && (ATL.isConstrained() ||
+ ATL.getAutoKeyword() == AutoTypeKeyword::DecltypeAuto)) ||
+ ReturnLoc.getAs<DecltypeTypeLoc>()) {
SourceLocation End =
expandIfMacroId(ReturnLoc.getSourceRange().getEnd(), SM);
SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
index 914564e9ae218..3776e1c3505d1 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -96,7 +96,9 @@ bool ExpandAutoType::prepare(const Selection& Inputs) {
if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
if (auto *TypeNode = Node->ASTNode.get<TypeLoc>()) {
if (const AutoTypeLoc Result = TypeNode->getAs<AutoTypeLoc>()) {
- if (!isStructuredBindingType(Node) &&
+ // Code in apply() does handle 'decltype(auto)' yet.
+ if (!Result.getTypePtr()->isDecltypeAuto() &&
+ !isStructuredBindingType(Node) &&
!isDeducedAsLambda(Node, Result.getBeginLoc()) &&
!isTemplateParam(Node))
CachedLocation = Result;
diff --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 0f4464122c8fb..7e19f07a2215e 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -391,8 +391,6 @@ TEST(SelectionTest, CommonAncestor) {
)cpp",
"DeclRefExpr"},
{"[[decltype^(1)]] b;", "DecltypeTypeLoc"}, // Not the VarDecl.
- // decltype(auto) is an AutoTypeLoc!
- {"[[de^cltype(a^uto)]] a = 1;", "AutoTypeLoc"},
// Objective-C nullability attributes.
{
diff --git a/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
index 6d9d4362be7af..96574a67b5a46 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -71,8 +71,7 @@ TEST_F(ExpandAutoTypeTest, Test) {
apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
"void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
- EXPECT_EQ(apply("dec^ltype(auto) x = 10;"), "int x = 10;");
- EXPECT_EQ(apply("decltype(au^to) x = 10;"), "int x = 10;");
+ EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
// expanding types in structured bindings is syntactically invalid.
EXPECT_UNAVAILABLE("const ^auto &[x,y] = (int[]){1,2};");
diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h
index 9c7ab4e8ddb7b..9a43d34a9ec38 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -2081,9 +2081,6 @@ struct AutoTypeLocInfo : TypeSpecLocInfo {
NamedDecl *FoundDecl;
SourceLocation LAngleLoc;
SourceLocation RAngleLoc;
-
- // For decltype(auto).
- SourceLocation RParenLoc;
};
class AutoTypeLoc
@@ -2096,10 +2093,6 @@ class AutoTypeLoc
return getTypePtr()->getKeyword();
}
- bool isDecltypeAuto() const { return getTypePtr()->isDecltypeAuto(); }
- SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
- void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
-
bool isConstrained() const {
return getTypePtr()->isConstrained();
}
@@ -2180,13 +2173,16 @@ class AutoTypeLoc
}
SourceRange getLocalSourceRange() const {
- return {isConstrained()
- ? (getNestedNameSpecifierLoc()
- ? getNestedNameSpecifierLoc().getBeginLoc()
- : (getTemplateKWLoc().isValid() ? getTemplateKWLoc()
- : getConceptNameLoc()))
- : getNameLoc(),
- isDecltypeAuto() ? getRParenLoc() : getNameLoc()};
+ return{
+ isConstrained()
+ ? (getNestedNameSpecifierLoc()
+ ? getNestedNameSpecifierLoc().getBeginLoc()
+ : (getTemplateKWLoc().isValid()
+ ? getTemplateKWLoc()
+ : getConceptNameLoc()))
+ : getNameLoc(),
+ getNameLoc()
+ };
}
void copy(AutoTypeLoc Loc) {
diff --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp
index 13aa54c48f66c..c3ed08d5a8b3e 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -622,7 +622,6 @@ void AutoTypeLoc::initializeLocal(ASTContext &Context, SourceLocation Loc) {
setFoundDecl(nullptr);
setRAngleLoc(Loc);
setLAngleLoc(Loc);
- setRParenLoc(Loc);
TemplateSpecializationTypeLoc::initializeArgLocs(Context, getNumArgs(),
getTypePtr()->getArgs(),
getArgInfos(), Loc);
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index cff8c76183f6a..e1074f78c062d 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3576,7 +3576,6 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
}
}
ConsumedEnd = Tok.getLocation();
- DS.setTypeofParensRange(Tracker.getRange());
// Even if something went wrong above, continue as if we've seen
// `decltype(auto)`.
isInvalid = DS.SetTypeSpecType(TST_decltype_auto, Loc, PrevSpec,
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 959f4903b0306..f0bbbcf59c751 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -22,7 +22,6 @@
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeLocVisitor.h"
#include "clang/Basic/PartialDiagnostic.h"
-#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/DeclSpec.h"
@@ -6042,8 +6041,6 @@ namespace {
DS.getTypeSpecType() == TST_auto_type ||
DS.getTypeSpecType() == TST_unspecified);
TL.setNameLoc(DS.getTypeSpecTypeLoc());
- if (DS.getTypeSpecType() == TST_decltype_auto)
- TL.setRParenLoc(DS.getTypeofParensRange().getEnd());
if (!DS.isConstrainedAuto())
return;
TemplateIdAnnotation *TemplateId = DS.getRepAsTemplateId();
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 9056f00978c8f..b8ec5b2722a95 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -6652,8 +6652,6 @@ void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) {
TL.setArgLocInfo(i, Reader.readTemplateArgumentLocInfo(
TL.getTypePtr()->getArg(i).getKind()));
}
- if (Reader.readBool())
- TL.setRParenLoc(readSourceLocation());
}
void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc(
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index c2bee93b077e6..40772bb7dd7f5 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -452,9 +452,6 @@ void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) {
Record.AddTemplateArgumentLocInfo(TL.getTypePtr()->getArg(I).getKind(),
TL.getArgLocInfo(I));
}
- Record.push_back(TL.isDecltypeAuto());
- if (TL.isDecltypeAuto())
- Record.AddSourceLocation(TL.getRParenLoc());
}
void TypeLocWriter::VisitDeducedTemplateSpecializationTypeLoc(
diff --git a/clang/test/AST/ast-dump-template-decls-json.cpp b/clang/test/AST/ast-dump-template-decls-json.cpp
index 5fc466bd9908a..fc1b883f5dacc 100644
--- a/clang/test/AST/ast-dump-template-decls-json.cpp
+++ b/clang/test/AST/ast-dump-template-decls-json.cpp
@@ -2130,9 +2130,9 @@ void i();
// CHECK-NEXT: "tokLen": 8
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
-// CHECK-NEXT: "offset": 718,
-// CHECK-NEXT: "col": 24,
-// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: "offset": 705,
+// CHECK-NEXT: "col": 11,
+// CHECK-NEXT: "tokLen": 8
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
diff --git a/clang/test/AST/ast-dump-template-decls.cpp b/clang/test/AST/ast-dump-template-decls.cpp
index 51ec673ab8f3a..e58731ae6d51d 100644
--- a/clang/test/AST/ast-dump-template-decls.cpp
+++ b/clang/test/AST/ast-dump-template-decls.cpp
@@ -90,7 +90,7 @@ struct T {};
template <decltype(auto)>
// CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:11> col:8 U
-// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:24> col:25 'decltype(auto)' depth 0 index 0
+// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11> col:25 'decltype(auto)' depth 0 index 0
struct U {};
template <typename Ty>
diff --git a/clang/unittests/AST/SourceLocationTest.cpp b/clang/unittests/AST/SourceLocationTest.cpp
index a798f6b2225ba..832d3751362f6 100644
--- a/clang/unittests/AST/SourceLocationTest.cpp
+++ b/clang/unittests/AST/SourceLocationTest.cpp
@@ -242,13 +242,6 @@ TEST(TypeLoc, DecltypeTypeLocRange) {
verify(Target2->getSourceRange(), Code.range("full2"));
}
-TEST(TypeLoc, AutoTypeLocRange) {
- RangeVerifier<TypeLoc> Verifier;
- Verifier.expectRange(1, 1, 1, 14);
- EXPECT_TRUE(Verifier.match("decltype(auto) a = 1;", typeLoc(loc(autoType())),
- Lang_CXX14));
-}
-
TEST(TypeLoc, LongDoubleRange) {
RangeVerifier<TypeLoc> Verifier;
Verifier.expectRange(1, 1, 1, 6);
More information about the cfe-commits
mailing list