<div dir="ltr"><div dir="ltr"><div dir="ltr">Hi John:<div><br></div><div>I found this investigating the cast assert noted here: <a href="http://lists.llvm.org/pipermail/cfe-dev/2019-March/061685.html">http://lists.llvm.org/pipermail/cfe-dev/2019-March/061685.html</a></div><div><br></div><div>I subsequently did quick grep and found a number of cases in clang+llvm (didn't find any in other projects) .  I'm happy to fix these in mass, i.e., s/cast/dyn_cast/, but as you mentioned, some might require additional refactoring, e.g., removal of the conditional.  </div><div><br></div><div>In any case, here's what I've found -- perhaps a new llvm clang-tidy checker would be useful:</div><div><br></div><div><div>$ find ./clang ./llvm -type f \( -name "*.h" -o -name "*.cpp" \) -exec grep -Hn "if *(auto.* *= *cast *<" \{\} \;</div><div>./clang/lib/Sema/SemaOpenMP.cpp:10904:      else if (auto *DRD = cast<OMPDeclareReductionDecl>(D))</div><div>./clang/lib/CodeGen/CGExprConstant.cpp:1701:  if (auto destPtrTy = cast<llvm::PointerType>(destTy)) {</div><div>./clang/lib/CodeGen/MicrosoftCXXABI.cpp:738:      if (auto *Fn = cast<llvm::Function>(Throw.getCallee()))</div><div>./clang/lib/AST/ASTImporter.cpp:8463:  if (auto *FromDC = cast<DeclContext>(From)) {</div><div>./clang/lib/AST/DeclBase.cpp:1182:    if (auto *Def = cast<ObjCInterfaceDecl>(this)->getDefinition())</div><div>./clang/lib/AST/DeclBase.cpp:1187:    if (auto *Def = cast<ObjCProtocolDecl>(this)->getDefinition())</div><div>./llvm/tools/llvm-objdump/llvm-objdump.cpp:802:  if (auto *Elf64BEObj = cast<ELF64BEObjectFile>(Obj))</div><div>./llvm/tools/llvm-objdump/llvm-objdump.cpp:846:  else if (auto *Elf64BEObj = cast<ELF64BEObjectFile>(Obj))</div><div>./llvm/lib/Target/X86/AsmParser/X86Operand.h:102:        if (auto Imm = cast<MCConstantExpr>(Val)->getValue())</div><div>./llvm/lib/Transforms/IPO/CalledValuePropagation.cpp:139:      } else if (auto *F = cast<Function>(Key.getPointer()))</div><div>./llvm/lib/Transforms/Coroutines/CoroEarly.cpp:183:        if (auto *CII = cast<CoroIdInst>(&I)) {</div></div><div><br></div><div>thanks...</div><div>don</div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 18, 2019 at 12:07 PM John McCall <<a href="mailto:jmccall@apple.com" target="_blank">jmccall@apple.com</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">On 18 Mar 2019, at 14:39, Don Hinton wrote:<br>
> It looks like this change introduced a small bug;  Specifically, the<br>
> following cast test:<br>
><br>
> -      if (auto PT = dyn_cast<llvm::PointerType>(DestTy)) {<br>
> ...<br>
> +  // If we're producing a pointer, this is easy.<br>
> +  if (auto destPtrTy = cast<llvm::PointerType>(destTy)) {<br>
><br>
> Since the cast can fail, shouldn't you prefer dyn_cast<>(), which can<br>
> return nullptr, over cast<>(), which will assert?<br>
<br>
Yes, although if it hasn't caused a problem in the last year and a half, <br>
maybe we should just change the code to be non-conditional.<br>
<br>
John.<br>
</blockquote></div>