<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Things like the existence of extra artificial entries do seem appropriate for putting under "tuning" control.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I suppose I should ping/refresh the tuning patch…  been letting it slide due to a particularly snarky merge and needing to get the depfile thing sorted out
 for an imminent release.  I'll be back on it Real Soon Now.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> cfe-commits-bounces@cs.uiuc.edu [mailto:cfe-commits-bounces@cs.uiuc.edu]
<b>On Behalf Of </b>Eric Christopher<br>
<b>Sent:</b> Wednesday, April 29, 2015 10:04 AM<br>
<b>To:</b> Adrian Prantl; David Blaikie<br>
<b>Cc:</b> llvm cfe<br>
<b>Subject:</b> Re: r236059 - Debug Info: Represent local anonymous unions as anonymous unions<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Wed, Apr 29, 2015 at 9:58 AM Eric Christopher <<a href="mailto:echristo@gmail.com">echristo@gmail.com</a>> wrote:<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">On Wed, Apr 29, 2015 at 8:20 AM Adrian Prantl <<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
> On Apr 28, 2015, at 6:26 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Tue, Apr 28, 2015 at 4:01 PM, Adrian Prantl <<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>> wrote:<br>
> Author: adrian<br>
> Date: Tue Apr 28 18:01:24 2015<br>
> New Revision: 236059<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=236059&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=236059&view=rev</a><br>
> Log:<br>
> Debug Info: Represent local anonymous unions as anonymous unions<br>
> in the debug info. This patch deletes a hack that emits the members<br>
> of local anonymous unions as local variables.<br>
><br>
> Besides being morally wrong, the existing representation using local<br>
> variables breaks internal assumptions about the local variables' storage<br>
> size.<br>
><br>
> Compiling<br>
><br>
> ```<br>
>    void fn1() {<br>
>      union {<br>
>        int i;<br>
>        char c;<br>
>      };<br>
>      i = c;<br>
>    }<br>
><br>
> ```<br>
><br>
> with -g -O3 -verify will cause the verifier to fail after SROA splits<br>
> the 32-bit storage for the "local variable" c into two pieces because the<br>
> second piece is clearly outside the 8-bit range that is expected for a<br>
> variable of type char. Given the choice I'd rather fix the debug<br>
> representation than weaken the verifier.<br>
><br>
> Debuggers generally already know how to deal with anonymous unions when<br>
> they are members of C++ record types, but they may have problems finding<br>
> the local anonymous struct members in the expression evaluator.<br>
><br>
> Seems we're not so lucky: <a href="http://lab.llvm.org:8011/builders/clang-x86_64-ubuntu-gdb-75/builds/21650/steps/gdb-75-check/logs/gdb.cp__anon-union.exp" target="_blank">
http://lab.llvm.org:8011/builders/clang-x86_64-ubuntu-gdb-75/builds/21650/steps/gdb-75-check/logs/gdb.cp__anon-union.exp</a><br>
><br>
> Could you revert & I'll look into getting you a reduced test case/demonstration of the issue? (can you run GDB 7.5? Perhaps a simple test case would demonstrate the issue if you're lucky, otherwise I can reduce one from the failing test case)<br>
<br>
I reverted the commit in r236110. I probably won’t need a reduction — my guess from the log is that gdb expects a local variable to be present.<br>
<br>
My suggestion is to emit local artificial shadow variables and then weaken the Verifier to not verify artificial variables. In a next step, we could use the new debugger tuning target feature to make the artificial local variables and the weakened verifier
 a gdb-specific behavior, file a bug against gdb, and eventually remove it altogether.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">FWIW I don't want to use the "tuning" parameters to also affect correctness.<o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">OK. Dave and I debated this a little in person, here's a proposal:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">by default it will have the gdb specific behavior, but if you're tuning for lldb (or any other debugger I guess?) it won't be there.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thoughts?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-eric<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-eric<o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">-- adrian<br>
<br>
><br>
><br>
> rdar://problem/20730771<br>
><br>
> Modified:<br>
>     cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
>     cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=236059&r1=236058&r2=236059&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=236059&r1=236058&r2=236059&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Apr 28 18:01:24 2015<br>
> @@ -2835,31 +2835,6 @@ void CGDebugInfo::EmitDeclare(const VarD<br>
>        return;<br>
>      } else if (isa<VariableArrayType>(VD->getType()))<br>
>        Expr.push_back(llvm::dwarf::DW_OP_deref);<br>
> -  } else if (const RecordType *RT = dyn_cast<RecordType>(VD->getType())) {<br>
> -    // If VD is an anonymous union then Storage represents value for<br>
> -    // all union fields.<br>
> -    const RecordDecl *RD = cast<RecordDecl>(RT->getDecl());<br>
> -    if (RD->isUnion() && RD->isAnonymousStructOrUnion()) {<br>
> -      for (const auto *Field : RD->fields()) {<br>
> -        llvm::MDType *FieldTy = getOrCreateType(Field->getType(), Unit);<br>
> -        StringRef FieldName = Field->getName();<br>
> -<br>
> -        // Ignore unnamed fields. Do not ignore unnamed records.<br>
> -        if (FieldName.empty() && !isa<RecordType>(Field->getType()))<br>
> -          continue;<br>
> -<br>
> -        // Use VarDecl's Tag, Scope and Line number.<br>
> -        auto *D = DBuilder.createLocalVariable(<br>
> -            Tag, Scope, FieldName, Unit, Line, FieldTy,<br>
> -            CGM.getLangOpts().Optimize, Flags, ArgNo);<br>
> -<br>
> -        // Insert an llvm.dbg.declare into the current block.<br>
> -        DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),<br>
> -                               llvm::DebugLoc::get(Line, Column, Scope),<br>
> -                               Builder.GetInsertBlock());<br>
> -      }<br>
> -      return;<br>
> -    }<br>
>    }<br>
><br>
>    // Create the descriptor for the variable.<br>
><br>
> Modified: cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp?rev=236059&r1=236058&r2=236059&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp?rev=236059&r1=236058&r2=236059&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp (original)<br>
> +++ cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp Tue Apr 28 18:01:24 2015<br>
> @@ -21,8 +21,26 @@ int test_it() {<br>
>    return (c == 1);<br>
>  }<br>
><br>
> +// This is not necessary (and actually harmful because it breaks IR assumptions)<br>
> +// for local variables.<br>
> +void foo() {<br>
> +  union {<br>
> +    int i;<br>
> +    char c;<br>
> +  };<br>
> +  i = 8;<br>
> +}<br>
> +<br>
>  // CHECK: [[FILE:.*]] = !MDFile(filename: "{{.*}}debug-info-anon-union-vars.cpp",<br>
>  // CHECK: !MDGlobalVariable(name: "c",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true<br>
>  // CHECK: !MDGlobalVariable(name: "d",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true<br>
>  // CHECK: !MDGlobalVariable(name: "a",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true<br>
>  // CHECK: !MDGlobalVariable(name: "b",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true<br>
> +// CHECK: !MDLocalVariable(<br>
> +// CHECK-NOT: name:<br>
> +// CHECK: type: ![[UNION:[0-9]+]]<br>
> +// CHECK: ![[UNION]] = !MDCompositeType(tag: DW_TAG_union_type,<br>
> +// CHECK-NOT: name:<br>
> +// CHECK: elements<br>
> +// CHECK: !MDDerivedType(tag: DW_TAG_member, name: "i", scope: ![[UNION]],<br>
> +// CHECK: !MDDerivedType(tag: DW_TAG_member, name: "c", scope: ![[UNION]],<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">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>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">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><o:p></o:p></p>
</blockquote>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>