Search code examples
parsingcompilationcompiler-constructionclangsemantic-analysis

Compiler: is implicit type conversion considered in parsing or semantic analysis?


In my understanding implicit conversion is done in semantic analysis, but clang AST command clang -Xclang -ast-dump -fsyntax-only file.cpp produces type conversion information in AST, like these two:

...
`- ImplicitCastExpr 0x7fdc27050558 <col:14> 'int' <LValueToRValue>
...

...
ImplicitCastExpr 0x7f878884c2d0 <col:19> 'unsigned int' <IntegralCast>
...

hence the question.


Solution

  • Implicit type conversion usually occurs in the semantic analysis(more specifically type checking) of a compiler but some can happen in the parsing to make a simpler AST (converting literals to their values directly and so on).

    If you look specifcally at the command option you used we see that it means

    -fsyntax-only Run the preprocessor, parser and type checking stages.

    https://clang.llvm.org/docs/CommandGuide/clang.html

    so we see that we expect type information(which requires implicit conversion) to be outputted.

    NOTE: I may be unclear, but type checking is just a stage of semantic analysis.