<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi All,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> I have SrcType and DestType used in explicit cast, and I'd like to check if the type conversion is valid in CastOperation::CheckCStyleCast [1]. The code snippet below (just get the idea, the code is not runable),</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> Builtin *Src = dyn_cast<BuiltinType>(SrcExpr.get()->getType());</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> Builtin *Dest = dyn_cast<BuiltinType>(DestType);</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> if (Src.getKind() == Dest.getKind()) {</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> // do something</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> } else {</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> // do something else</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> }</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">The problem is the SrcType and DestType might be typedef. For example,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> typedef foo FOO;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> FOO b = (FOO)(a);</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Src and Dest might be nullptr due to the fail dyn_cast, and I will get segfault while calling getKind() upon them.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I am not familiar with Clang, so is there a better way that I can get the underlying type if SrcType and DestType</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">are typedef?</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Thanks. </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">[1] <a href="https://clang.llvm.org/doxygen/SemaCast_8cpp_source.html">https://clang.llvm.org/doxygen/SemaCast_8cpp_source.html</a></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Regards,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">chenwj</div><div class="gmail_signature"><br>--<br>Wei-Ren Chen (陳韋任)<br>Homepage: <a href="https://people.cs.nctu.edu.tw/~chenwj" target="_blank">https://people.cs.nctu.edu.tw/~chenwj</a></div>
</div>