This is an archive of the discontinued LLVM Phabricator instance.

Bugfix in template instantiation.
ClosedPublic

Authored by ABataev on Oct 14 2014, 1:39 AM.

Details

Summary

Fix for clang crash when instantiating a template with qualified lookup for members in non-class types

Diff Detail

Event Timeline

ABataev updated this revision to Diff 14853.Oct 14 2014, 1:39 AM
ABataev retitled this revision from to Bugfix in template instantiation..
ABataev updated this object.
ABataev edited the test plan for this revision. (Show Details)
ABataev added reviewers: rsmith, hfinkel.
ABataev added a subscriber: Unknown Object (MLST).
majnemer added inline comments.
lib/Sema/SemaCXXScopeSpec.cpp
144 ↗(On Diff #14853)

No need to repeat TagType, we know what it is from the right hand side. I'd recommend:

if (const auto *Tag = NNS->getAsType()->getAs<TagType>())
lib/Sema/SemaExprMember.cpp
599 ↗(On Diff #14853)

This is unusual in clang's codebase, I'd recommend:

DC = SemaRef.computeDeclContext(SS, /*EnteringContext=*/false);
if (!DC) {

David, thanks. I'll fix this.

Best regards,

Alexey Bataev

Software Engineer
Intel Compiler Team

14.10.2014 12:59, David Majnemer пишет:

Comment at: lib/Sema/SemaCXXScopeSpec.cpp:144
@@ -143,4 +143,3 @@

case NestedNameSpecifier::TypeSpecWithTemplate: {
  • const TagType *Tag = NNS->getAsType()->getAs<TagType>();
  • assert(Tag && "Non-tag type in nested-name-specifier");
  • return Tag->getDecl();

+ if (const TagType *Tag = NNS->getAsType()->getAs<TagType>())

+ return Tag->getDecl();

No need to repeat TagType, we know what it is from the right hand side. I'd recommend:

if (const auto *Tag = NNS->getAsType()->getAs<TagType>())

Comment at: lib/Sema/SemaExprMember.cpp:599
@@ -598,2 +598,3 @@

// nested-name-specifier.
  • DC = SemaRef.computeDeclContext(SS, false);

+ if ((DC = SemaRef.computeDeclContext(SS, false)) == nullptr) {

+ SemaRef.Diag(SS.getBeginLoc(), diag::err_expected_class_or_namespace)

This is unusual in clang's codebase, I'd recommend:

DC = SemaRef.computeDeclContext(SS, /*EnteringContext=*/false);
if (!DC) {

http://reviews.llvm.org/D5769

ABataev updated this revision to Diff 14854.Oct 14 2014, 3:21 AM

Update after review.

rsmith edited edge metadata.Oct 14 2014, 6:06 PM

This is the wrong fix. The bug is that TreeTransform::RebuildCXXPseudoDestructorExpr is building a bogus CXXScopeSpec here:

// The scope type is now known to be a valid nested name specifier
// component. Tack it on to the end of the nested name specifier.
if (ScopeType)
  SS.Extend(SemaRef.Context, SourceLocation(),
            ScopeType->getTypeLoc(), CCLoc);

If ScopeType is not a class type, we should reject it at this point.

ABataev updated this revision to Diff 14915.Oct 15 2014, 2:05 AM
ABataev edited edge metadata.

Completely reworked patch after review.

rsmith accepted this revision.Oct 15 2014, 10:50 AM
rsmith edited edge metadata.

Please add tests for the case where the type before the ::~ instantiates as an enum type, in both C++98 and C++11.

Otherwise, this looks fine. Thanks!

This revision is now accepted and ready to land.Oct 15 2014, 10:50 AM
ABataev closed this revision.Oct 15 2014, 8:15 PM
ABataev updated this revision to Diff 14976.

Closed by commit rL219897 (authored by @ABataev).