This is an archive of the discontinued LLVM Phabricator instance.

Fix for assertion failure on PR46865
Needs RevisionPublic

Authored by Sunil_Srivastava on Aug 26 2020, 12:08 PM.

Details

Reviewers
rsmith
erichkeane
Summary

This is a proposed fix for the crash of PR46865.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2020, 12:08 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Sunil_Srivastava requested review of this revision.Aug 26 2020, 12:08 PM
wristow added inline comments.
clang/lib/AST/ExprConstant.cpp
3098

This looks like a more appropriate assertion-check to me. But it's out of my area of experience, so I don't feel qualified to give an authoritative "LGTM".

rsmith requested changes to this revision.Sep 27 2020, 9:19 PM

I think the assertion is correct: if we reach this point, then we have a DeclRefExpr that is not value-dependent and refers to a declaration whose initializer is value-dependent. That should never happen if the variable's type satisfies the requirements for use in a constant expression, which is what mightBeUsableInConstantExpressions checks.

The bug here appears to be that the dependency bits on a DeclRefExpr are computed too early when it refers to a templated variable -- before we instantiate the initializer -- and don't get "fixed" later when the initializer is instantiated. DoMarkVarDeclReferenced would be the right place to handle this -- after we trigger instantiation of the initializer, we should recompute the dependence bits on the DeclRefExpr, because they can depend on the initializer.

This revision now requires changes to proceed.Sep 27 2020, 9:19 PM