<div class="gmail_quote">On Fri, Sep 2, 2011 at 9:21 AM, Andrew Trick <span dir="ltr"><<a href="mailto:atrick@apple.com">atrick@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Richard,<br>
<br>
We're hitting a new DejaGNU failure that I'm guessing is caused by this checkin:<br>
g++.old-deja/g++.brendan/parse6.C<br>
<br>
I haven't seen how it fails yet, just hoping someone can fix or revert before I get around to it.<br></blockquote><div><br></div><div>FYI, I'm not in the office yet but Richard or I should be able to look at this today and fix it. Just so you don't stress / spend too much time on it. =D</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
-Andy<br>
<div class="HOEnZb"><div></div><div class="h5"><br>
On Sep 1, 2011, at 2:44 PM, Richard Trieu wrote:<br>
<br>
> Author: rtrieu<br>
> Date: Thu Sep  1 16:44:13 2011<br>
> New Revision: 138969<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=138969&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=138969&view=rev</a><br>
> Log:<br>
> Extend the self-reference warning to catch when a constructor references itself upon initialization, such as using itself within its own copy constructor.<br>
><br>
> struct S {};<br>
> S s(s);<br>
><br>
> Modified:<br>
>    cfe/trunk/include/clang/Sema/Sema.h<br>
>    cfe/trunk/lib/Sema/SemaDecl.cpp<br>
>    cfe/trunk/lib/Sema/SemaInit.cpp<br>
>    cfe/trunk/test/SemaCXX/uninitialized.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/Sema/Sema.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=138969&r1=138968&r2=138969&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=138969&r1=138968&r2=138969&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/include/clang/Sema/Sema.h (original)<br>
> +++ cfe/trunk/include/clang/Sema/Sema.h Thu Sep  1 16:44:13 2011<br>
> @@ -1035,6 +1035,7 @@<br>
>   bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,<br>
>                                SourceLocation EqualLoc);<br>
><br>
> +  void CheckSelfReference(Decl *OrigDecl, Expr *E);<br>
>   void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit,<br>
>                             bool TypeMayContainAuto);<br>
>   void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto);<br>
><br>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=138969&r1=138968&r2=138969&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=138969&r1=138968&r2=138969&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Sep  1 16:44:13 2011<br>
> @@ -5407,41 +5407,88 @@<br>
>       : public EvaluatedExprVisitor<SelfReferenceChecker> {<br>
>     Sema &S;<br>
>     Decl *OrigDecl;<br>
> +    bool isRecordType;<br>
> +    bool isPODType;<br>
><br>
>   public:<br>
>     typedef EvaluatedExprVisitor<SelfReferenceChecker> Inherited;<br>
><br>
>     SelfReferenceChecker(Sema &S, Decl *OrigDecl) : Inherited(S.Context),<br>
> -                                                    S(S), OrigDecl(OrigDecl) { }<br>
> +                                                    S(S), OrigDecl(OrigDecl) {<br>
> +      isPODType = false;<br>
> +      isRecordType = false;<br>
> +      if (ValueDecl *VD = dyn_cast<ValueDecl>(OrigDecl)) {<br>
> +        isPODType = VD->getType().isPODType(S.Context);<br>
> +        isRecordType = VD->getType()->isRecordType();<br>
> +      }<br>
> +    }<br>
><br>
>     void VisitExpr(Expr *E) {<br>
>       if (isa<ObjCMessageExpr>(*E)) return;<br>
> +      if (isRecordType) {<br>
> +        Expr *expr = E;<br>
> +        if (MemberExpr *ME = dyn_cast<MemberExpr>(E)) {<br>
> +          ValueDecl *VD = ME->getMemberDecl();<br>
> +          if (isa<EnumConstantDecl>(VD) || isa<VarDecl>(VD)) return;<br>
> +          expr = ME->getBase();<br>
> +        }<br>
> +        if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(expr)) {<br>
> +          HandleDeclRefExpr(DRE);<br>
> +          return;<br>
> +        }<br>
> +      }<br>
>       Inherited::VisitExpr(E);<br>
>     }<br>
><br>
> +    void VisitMemberExpr(MemberExpr *E) {<br>
> +      if (isa<FieldDecl>(E->getMemberDecl()))<br>
> +        if (DeclRefExpr *DRE<br>
> +              = dyn_cast<DeclRefExpr>(E->getBase()->IgnoreParenImpCasts())) {<br>
> +          HandleDeclRefExpr(DRE);<br>
> +          return;<br>
> +        }<br>
> +      Inherited::VisitMemberExpr(E);<br>
> +    }<br>
> +<br>
>     void VisitImplicitCastExpr(ImplicitCastExpr *E) {<br>
> -      CheckForSelfReference(E);<br>
> +      if ((!isRecordType &&E->getCastKind() == CK_LValueToRValue) ||<br>
> +          (isRecordType && E->getCastKind() == CK_NoOp)) {<br>
> +        Expr* SubExpr = E->getSubExpr()->IgnoreParenImpCasts();<br>
> +        if (MemberExpr *ME = dyn_cast<MemberExpr>(SubExpr))<br>
> +          SubExpr = ME->getBase()->IgnoreParenImpCasts();<br>
> +        if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {<br>
> +          HandleDeclRefExpr(DRE);<br>
> +          return;<br>
> +        }<br>
> +      }<br>
>       Inherited::VisitImplicitCastExpr(E);<br>
>     }<br>
><br>
> -    void CheckForSelfReference(ImplicitCastExpr *E) {<br>
> -      if (E->getCastKind() != CK_LValueToRValue) return;<br>
> -      Expr* SubExpr = E->getSubExpr()->IgnoreParenImpCasts();<br>
> -      DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(SubExpr);<br>
> -      if (!DRE) return;<br>
> -      Decl* ReferenceDecl = DRE->getDecl();<br>
> +    void VisitUnaryOperator(UnaryOperator *E) {<br>
> +      // For POD record types, addresses of its own members are well-defined.<br>
> +      if (isRecordType && isPODType) return;<br>
> +      Inherited::VisitUnaryOperator(E);<br>
> +    }<br>
> +<br>
> +    void HandleDeclRefExpr(DeclRefExpr *DRE) {<br>
> +      Decl* ReferenceDecl = DRE->getDecl();<br>
>       if (OrigDecl != ReferenceDecl) return;<br>
>       LookupResult Result(S, DRE->getNameInfo(), Sema::LookupOrdinaryName,<br>
>                           Sema::NotForRedeclaration);<br>
> -      S.DiagRuntimeBehavior(SubExpr->getLocStart(), SubExpr,<br>
> +      S.DiagRuntimeBehavior(DRE->getLocStart(), DRE,<br>
>                             S.PDiag(diag::warn_uninit_self_reference_in_init)<br>
> -                              << Result.getLookupName()<br>
> +                              << Result.getLookupName()<br>
>                               << OrigDecl->getLocation()<br>
> -                              << SubExpr->getSourceRange());<br>
> +                              << DRE->getSourceRange());<br>
>     }<br>
>   };<br>
> }<br>
><br>
> +/// CheckSelfReference - Warns if OrigDecl is used in expression E.<br>
> +void Sema::CheckSelfReference(Decl* OrigDecl, Expr *E) {<br>
> +  SelfReferenceChecker(*this, OrigDecl).VisitExpr(E);<br>
> +}<br>
> +<br>
> /// AddInitializerToDecl - Adds the initializer Init to the<br>
> /// declaration dcl. If DirectInit is true, this is C++ direct<br>
> /// initialization rather than copy initialization.<br>
> @@ -5457,10 +5504,10 @@<br>
>     // Variables declared within a function/method body are handled<br>
>     // by a dataflow analysis.<br>
>     if (!vd->hasLocalStorage() && !vd->isStaticLocal())<br>
> -      SelfReferenceChecker(*this, RealDecl).VisitExpr(Init);<br>
> +      CheckSelfReference(RealDecl, Init);<br>
>   }<br>
>   else {<br>
> -    SelfReferenceChecker(*this, RealDecl).VisitExpr(Init);<br>
> +    CheckSelfReference(RealDecl, Init);<br>
>   }<br>
><br>
>   if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(RealDecl)) {<br>
><br>
> Modified: cfe/trunk/lib/Sema/SemaInit.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=138969&r1=138968&r2=138969&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=138969&r1=138968&r2=138969&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/Sema/SemaInit.cpp (original)<br>
> +++ cfe/trunk/lib/Sema/SemaInit.cpp Thu Sep  1 16:44:13 2011<br>
> @@ -3078,6 +3078,14 @@<br>
>                                          Expr **Args, unsigned NumArgs,<br>
>                                          QualType DestType,<br>
>                                          InitializationSequence &Sequence) {<br>
> +  // Check constructor arguments for self reference.<br>
> +  if (DeclaratorDecl *DD = Entity.getDecl())<br>
> +    // Parameters arguments are occassionially constructed with itself,<br>
> +    // for instance, in recursive functions.  Skip them.<br>
> +    if (!isa<ParmVarDecl>(DD))<br>
> +      for (unsigned i = 0; i < NumArgs; ++i)<br>
> +        S.CheckSelfReference(DD, Args[i]);<br>
> +<br>
>   // Build the candidate set directly in the initialization sequence<br>
>   // structure, so that it will persist if we fail.<br>
>   OverloadCandidateSet &CandidateSet = Sequence.getFailedCandidateSet();<br>
><br>
> Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=138969&r1=138968&r2=138969&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=138969&r1=138968&r2=138969&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/test/SemaCXX/uninitialized.cpp (original)<br>
> +++ cfe/trunk/test/SemaCXX/uninitialized.cpp Thu Sep  1 16:44:13 2011<br>
> @@ -24,6 +24,78 @@<br>
> int j = far(j);<br>
> int k = __alignof__(k);<br>
><br>
> +<br>
> +// Test self-references with record types.<br>
> +class A {<br>
> +  // Non-POD class.<br>
> +  public:<br>
> +    enum count { ONE, TWO, THREE };<br>
> +    int num;<br>
> +    static int count;<br>
> +    int get() const { return num; }<br>
> +    void set(int x) { num = x; }<br>
> +    static int zero() { return 0; }<br>
> +<br>
> +    A() {}<br>
> +    A(A const &a) {}<br>
> +    A(int x) {}<br>
> +    A(int *x) {}<br>
> +    A(A *a) {}<br>
> +};<br>
> +<br>
> +A getA() { return A(); }<br>
> +A getA(int x) { return A(); }<br>
> +A getA(A* a) { return A(); }<br>
> +<br>
> +void setupA() {<br>
> +  A a1;<br>
> +  a1.set(a1.get());<br>
> +  A a2(a1.get());<br>
> +  A a3(a1);<br>
> +  A a4(&a4);<br>
> +  A a5(a5.zero());<br>
> +  A a6(a6.ONE);<br>
> +  A a7 = getA();<br>
> +  A a8 = getA(a8.TWO);<br>
> +  A a9 = getA(&a9);<br>
> +  A a10(a10.count);<br>
> +<br>
> +  A a11(a11);  // expected-warning {{variable 'a11' is uninitialized when used within its own initialization}}<br>
> +  A a12(a12.get());  // expected-warning {{variable 'a12' is uninitialized when used within its own initialization}}<br>
> +  A a13(a13.num);  // expected-warning {{variable 'a13' is uninitialized when used within its own initialization}}<br>
> +  A a14 = A(a14);  // expected-warning {{variable 'a14' is uninitialized when used within its own initialization}}<br>
> +  A a15 = getA(a15.num);  // expected-warning {{variable 'a15' is uninitialized when used within its own initialization}}<br>
> +  A a16(&a16.num);  // expected-warning {{variable 'a16' is uninitialized when used within its own initialization}}<br>
> +}<br>
> +<br>
> +struct B {<br>
> +  // POD struct.<br>
> +  int x;<br>
> +  int *y;<br>
> +};<br>
> +<br>
> +B getB() { return B(); };<br>
> +B getB(int x) { return B(); };<br>
> +B getB(int *x) { return B(); };<br>
> +B getB(B *b) { return B(); };<br>
> +<br>
> +void setupB() {<br>
> +  B b1;<br>
> +  B b2(b1);<br>
> +  B b3 = { 5, &b3.x };<br>
> +  B b4 = getB();<br>
> +  B b5 = getB(&b5);<br>
> +  B b6 = getB(&b6.x);<br>
> +<br>
> +  // Silence unused warning<br>
> +  (void) b2;<br>
> +  (void) b4;<br>
> +<br>
> +  B b7(b7);  // expected-warning {{variable 'b7' is uninitialized when used within its own initialization}}<br>
> +  B b8 = getB(b8.x);  // expected-warning {{variable 'b8' is uninitialized when used within its own initialization}}<br>
> +  B b9 = getB(b9.y);  // expected-warning {{variable 'b9' is uninitialized when used within its own initialization}}<br>
> +}<br>
> +<br>
> // Also test similar constructs in a field's initializer.<br>
> struct S {<br>
>   int x;<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br>