<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 26 October 2017 at 20:22, Bharathi Seshadri via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I'm trying to understand where __builtin_constant_p is folded in the<br>
front-end. It appears to be handled differently when placed in an if<br>
condition or in a conditional expression.<br>
<br>
In the example below, I see that it is folded in<br>
CodeGenFunction::<wbr>EmitBuiltinExpr() in CGBuiltin.cpp<br>
int x = __builtin_constant_p(100);<br>
<br>
But for cases like the ones below, it appears to be folded much<br>
earlier and it doesn't reach EmitBuiltinExpr().<br>
<br>
int x = __builtin_constant_p(100)? 10: 20;<br>
<br>
if (__builtin_constant_p(100)) { ... }<br>
<br>
Any pointers on what functions to look up for the above case would be<br>
very helpful.<br></blockquote><div><br></div><div>In some cases, Clang tries to constant-evaluate expressions rather than emitting them directly. (C and C++ require this to be done in some cases for variable initializers, particularly for globals, and Clang also tries it when it emits some conditional branches, to avoid even emitting trivially-unreachable code when the branch condition is constant). The constant expression evaluation lives in lib/AST/ExprConstant.cpp, and knows how to evaluate many of Clang's builtins (but not all of them).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks,<br>
Bharathi<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div>