<div dir="ltr"><div dir="ltr">On Wed, Sep 1, 2021 at 12:58 PM James Y Knight via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>The first warning looks valid, although it doesn't happen at runtime.</div><div><ol style="box-sizing:border-box;padding:0px 10px;font-size:12px;vertical-align:baseline;color:rgb(51,51,51);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif;margin:0px"><li style="box-sizing:border-box;padding:0px;vertical-align:baseline;list-style-type:decimal;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;color:rgb(172,172,172)"><div style="box-sizing:border-box;padding:0px 8px;vertical-align:top;color:rgb(0,0,0);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;white-space:pre-wrap">In constructor ‘llvm::MachineModuleInfo::MachineModuleInfo(const llvm::LLVMTargetMachine*)’,
</div></li><li style="box-sizing:border-box;padding:0px;vertical-align:baseline;list-style-type:decimal;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;color:rgb(172,172,172)"><div style="box-sizing:border-box;padding:0px 8px;vertical-align:top;color:rgb(0,0,0);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;white-space:pre-wrap">    inlined from ‘llvm::MachineModuleInfoWrapperPass::MachineModuleInfoWrapperPass(const llvm::LLVMTargetMachine*)’ at /llvm/lib/CodeGen/MachineModuleInfo.cpp:357:26,
</div></li><li style="box-sizing:border-box;padding:0px;vertical-align:baseline;list-style-type:decimal;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;color:rgb(172,172,172)"><div style="box-sizing:border-box;padding:0px 8px;vertical-align:top;color:rgb(0,0,0);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;white-space:pre-wrap">    inlined from ‘llvm::Pass* llvm::callDefaultCtor() [with PassName = llvm::MachineModuleInfoWrapperPass]’ at /llvm/include/llvm/PassSupport.h:80:76:
</div></li><li style="box-sizing:border-box;padding:0px;vertical-align:baseline;list-style-type:decimal;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;color:rgb(172,172,172)"><div style="box-sizing:border-box;padding:0px 8px;vertical-align:top;color:rgb(0,0,0);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;white-space:pre-wrap">/llvm/lib/CodeGen/MachineModuleInfo.cpp:240:51: warning: ‘this’ pointer is null [-Wnonnull]
</div></li><li style="box-sizing:border-box;padding:0px;vertical-align:baseline;list-style-type:decimal;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;color:rgb(172,172,172)"><div style="box-sizing:border-box;padding:0px 8px;vertical-align:top;color:rgb(0,0,0);border-left:1px solid rgb(221,221,221);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;white-space:pre-wrap">  240 |   Context.setObjectFileInfo(TM->getObjFileLowering());
</div></li><li style="box-sizing:border-box;padding:0px;vertical-align:baseline;list-style-type:decimal;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;color:rgb(172,172,172)"></li></ol></div><div>I believe it should be a simple matter of deleting the zero-arg constructor. I'll try that and push it.</div><div><br></div><div>I note that the GCC warning points to an odd place, though -- it probably should be pointing to the construction TM(*TM), which initializes a reference with null, which is already UB.<br></div><div>





<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(44,146,144)"><span style="font-variant-ligatures:no-common-ligatures">MachineModuleInfo</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">::</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(74,0,255)">MachineModuleInfo</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(194,0,255)">const</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(45,150,30)">LLVMTargetMachine</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> *</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(193,101,28)">TM</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><span>    </span>: TM(*TM), ....</span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></p></div><div dir="auto">However, the rest of the warnings come from:</div><div dir="auto">  decltype(static_cast<const TypeParam *>(nullptr)->rbegin())>::value<br></div><div>which I think is a false-positive in GCC's warning.</div></div></blockquote><div><br>Oh, yeah, if it's in an unevaluated context - agreed, that's a false positive. (though we could probably also just make that code nicer to read by using std::declval<const TypeParam&>().rbegin(), I think?<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>TTBOMK, calling a method on nullptr in an unevaluated context (e.g. decltype, non-vla-sizeof, etc) is not UB, and therefore should not emit a warning.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 1, 2021, 2:44 PM Luke Benes via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br>
<br>
In gcc-11, -Wnonnull considers the implicit this argument of every C++ nonstatic member function to have been implicitly declared with attribute nonnull and triggers warnings for calls where the pointer is null. [1] <br>
<br>
Should clang also do this? This change helped webkit identify and fix some issues. [2][3][4][5] <br>
<br>
Building clang trunk with gcc-11 produces 13 new warnings related to this enhancement. They are in MachineModuleInfo.cpp and RangeAdapterTest.cpp.[6] Do these look like valid issues? <br>
<br>
-Luke<br>
<br>
<br>
[1] <a href="https://gcc.gnu.org/gcc-11/changes.html%5C" rel="noreferrer noreferrer" target="_blank">https://gcc.gnu.org/gcc-11/changes.html\</a><br>
[2] <a href="https://bugs.webkit.org/show_bug.cgi?id=224838" rel="noreferrer noreferrer" target="_blank">https://bugs.webkit.org/show_bug.cgi?id=224838</a><br>
[3] <a href="https://bugs.webkit.org/show_bug.cgi?id=224826" rel="noreferrer noreferrer" target="_blank">https://bugs.webkit.org/show_bug.cgi?id=224826</a><br>
[4] <a href="https://trac.webkit.org/changeset/276343/webkit" rel="noreferrer noreferrer" target="_blank">https://trac.webkit.org/changeset/276343/webkit</a><br>
[5] <a href="https://bugs.webkit.org/show_bug.cgi?id=224452" rel="noreferrer noreferrer" target="_blank">https://bugs.webkit.org/show_bug.cgi?id=224452</a><br>
[6] <a href="https://pastebin.com/EJTZphGm" rel="noreferrer noreferrer" target="_blank">https://pastebin.com/EJTZphGm</a><br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" rel="noreferrer" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>