[cfe-commits] r152775 - /cfe/trunk/lib/AST/ExprConstant.cpp

Richard Smith richard at metafoo.co.uk
Mon Apr 9 18:52:39 PDT 2012


On Mon, Apr 9, 2012 at 5:22 PM, Eli Friedman <eli.friedman at gmail.com> wrote:

> On Wed, Mar 14, 2012 at 9:53 PM, Richard Smith
> <richard-llvm at metafoo.co.uk> wrote:
> > Author: rsmith
> > Date: Wed Mar 14 23:53:45 2012
> > New Revision: 152775
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=152775&view=rev
> > Log:
> > Unrevert r152761 (reverted in r152772) with a fix for the issue which was
> > breaking bootstrap. No test yet: it's quite hard to tickle the failure
> case.
> > The specific testcase for this wouldn't be useful for testing anything
> more
> > general than a reintroduction of this precise bug in any case.
> >
> > Modified:
> >    cfe/trunk/lib/AST/ExprConstant.cpp
> >
> > Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=152775&r1=152774&r2=152775&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> > +++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Mar 14 23:53:45 2012
> > @@ -480,9 +480,19 @@
> >       return OptionalDiagnostic();
> >     }
> >
> > +    OptionalDiagnostic Diag(const Expr *E, diag::kind DiagId
> > +                              =
> diag::note_invalid_subexpr_in_const_expr,
> > +                            unsigned ExtraNotes = 0) {
> > +      if (EvalStatus.Diag)
> > +        return Diag(E->getExprLoc(), DiagId, ExtraNotes);
> > +      HasActiveDiagnostic = false;
> > +      return OptionalDiagnostic();
> > +    }
> > +
> >     /// Diagnose that the evaluation does not produce a C++11 core
> constant
> >     /// expression.
> > -    OptionalDiagnostic CCEDiag(SourceLocation Loc, diag::kind DiagId
> > +    template<typename LocArg>
> > +    OptionalDiagnostic CCEDiag(LocArg Loc, diag::kind DiagId
> >                                  =
> diag::note_invalid_subexpr_in_const_expr,
> >                                unsigned ExtraNotes = 0) {
> >       // Don't override a previous diagnostic.
> > @@ -556,7 +566,7 @@
> >   if (Invalid)
> >     return false;
> >   if (isOnePastTheEnd()) {
> > -    Info.CCEDiag(E->getExprLoc(),
> diag::note_constexpr_past_end_subobject)
> > +    Info.CCEDiag(E, diag::note_constexpr_past_end_subobject)
> >       << CSK;
> >     setInvalid();
> >     return false;
> > @@ -567,11 +577,11 @@
> >  void SubobjectDesignator::diagnosePointerArithmetic(EvalInfo &Info,
> >                                                     const Expr *E,
> uint64_t N) {
> >   if (MostDerivedPathLength == Entries.size() && MostDerivedArraySize)
> > -    Info.CCEDiag(E->getExprLoc(), diag::note_constexpr_array_index)
> > +    Info.CCEDiag(E, diag::note_constexpr_array_index)
> >       << static_cast<int>(N) << /*array*/ 0
> >       << static_cast<unsigned>(MostDerivedArraySize);
> >   else
> > -    Info.CCEDiag(E->getExprLoc(), diag::note_constexpr_array_index)
> > +    Info.CCEDiag(E, diag::note_constexpr_array_index)
> >       << static_cast<int>(N) << /*non-array*/ 1;
> >   setInvalid();
> >  }
> > @@ -730,7 +740,7 @@
> >       if (Designator.Invalid)
> >         return false;
> >       if (!Base) {
> > -        Info.CCEDiag(E->getExprLoc(),
> diag::note_constexpr_null_subobject)
> > +        Info.CCEDiag(E, diag::note_constexpr_null_subobject)
> >           << CSK;
> >         Designator.setInvalid();
> >         return false;
> > @@ -741,27 +751,30 @@
> >     // Check this LValue refers to an object. If not, set the designator
> to be
> >     // invalid and emit a diagnostic.
> >     bool checkSubobject(EvalInfo &Info, const Expr *E,
> CheckSubobjectKind CSK) {
> > +      // Outside C++11, do not build a designator referring to a
> subobject of
> > +      // any object: we won't use such a designator for anything.
> > +      if (!Info.getLangOpts().CPlusPlus0x)
> > +        Designator.setInvalid();
>
> The comment here isn't completely correct: this check affects whether
> we accept the expression "FOOBAR"[3] as a constant expression in C.
> And I've just run into code C that started using that construct. :(
> Any suggestions?


If we just want to support folding this specific case, I think it should be
sufficient to disable this check if Base is a StringLiteral.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120409/b3c42518/attachment.html>


More information about the cfe-commits mailing list