Re: Show C's Integer Promotions and Usual Arithmetic Conversions.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Ralph Corderoy:

> Is there a way to get gcc to show C's `integer promotions' and
> `usual arithmetic conversions' that it has applied to an expression?
> Even if it needs a bit of untangling from the main thing it's
> trying to show.  I was wondering if one of the many `-d' developer
> options or `dump' options would show that stage.

GCC doesn't provide this functionality.  Clang can do this (using
Andrew's example):

$ clang -fsyntax-only -Xclang -ast-dump /tmp/t.c
TranslationUnitDecl 0x5619d2124348 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x5619d2124be0 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
| `-BuiltinType 0x5619d21248e0 '__int128'
|-TypedefDecl 0x5619d2124c48 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
| `-BuiltinType 0x5619d2124900 'unsigned __int128'
|-TypedefDecl 0x5619d2124f08 <<invalid sloc>> <invalid sloc> implicit __NSConstantString 'struct __NSConstantString_tag'
| `-RecordType 0x5619d2124d20 'struct __NSConstantString_tag'
|   `-Record 0x5619d2124c98 '__NSConstantString_tag'
|-TypedefDecl 0x5619d2124fa0 <<invalid sloc>> <invalid sloc> implicit __builtin_ms_va_list 'char *'
| `-PointerType 0x5619d2124f60 'char *'
|   `-BuiltinType 0x5619d21243e0 'char'
|-TypedefDecl 0x5619d215e628 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list 'struct __va_list_tag [1]'
| `-ConstantArrayType 0x5619d215e5d0 'struct __va_list_tag [1]' 1 
|   `-RecordType 0x5619d215e450 'struct __va_list_tag'
|     `-Record 0x5619d215e3c0 '__va_list_tag'
`-FunctionDecl 0x5619d215e758 </tmp/t.c:1:1, line:7:1> line:1:10 mod_m 'unsigned int (unsigned int)'
  |-ParmVarDecl 0x5619d215e690 <col:16, col:25> col:25 used n 'unsigned int'
  `-CompoundStmt 0x5619d215ec38 <col:28, line:7:1>
    |-DeclStmt 0x5619d215e970 <line:2:3, col:28>
    | `-VarDecl 0x5619d215e858 <col:3, col:22> col:12 used tmp 'unsigned int' cinit
    |   `-ImplicitCastExpr 0x5619d215e958 <col:18, col:22> 'unsigned int' <IntegralCast>
    |     `-BinaryOperator 0x5619d215e930 <col:18, col:22> 'long' '%'
    |       |-ImplicitCastExpr 0x5619d215e918 <col:18> 'long' <IntegralCast>
    |       | `-ImplicitCastExpr 0x5619d215e900 <col:18> 'unsigned int' <LValueToRValue>
    |       |   `-DeclRefExpr 0x5619d215e8b8 <col:18> 'unsigned int' lvalue ParmVar 0x5619d215e690 'n' 'unsigned int'
    |       `-IntegerLiteral 0x5619d215e8e0 <col:22> 'long' 65536
    |-CompoundAssignOperator 0x5619d215ea50 <line:3:3, col:14> 'unsigned int' '-=' ComputeLHSTy='double' ComputeResultTy='double'
    | |-DeclRefExpr 0x5619d215e988 <col:3> 'unsigned int' lvalue Var 0x5619d215e858 'tmp' 'unsigned int'
    | `-BinaryOperator 0x5619d215ea28 <col:10, col:14> 'double' '/'
    |   |-ImplicitCastExpr 0x5619d215ea10 <col:10> 'double' <IntegralToFloating>
    |   | `-ImplicitCastExpr 0x5619d215e9f8 <col:10> 'unsigned int' <LValueToRValue>
    |   |   `-DeclRefExpr 0x5619d215e9b0 <col:10> 'unsigned int' lvalue ParmVar 0x5619d215e690 'n' 'unsigned int'
    |   `-FloatingLiteral 0x5619d215e9d8 <col:14> 'double' 6.553600e+04
    |-IfStmt 0x5619d215eba8 <line:4:3, line:5:12>
    | |-<<<NULL>>>
    | |-<<<NULL>>>
    | |-BinaryOperator 0x5619d215eb00 <line:4:7, col:14> 'int' '>='
    | | |-ImplicitCastExpr 0x5619d215ead0 <col:7> 'unsigned int' <LValueToRValue>
    | | | `-DeclRefExpr 0x5619d215ea88 <col:7> 'unsigned int' lvalue Var 0x5619d215e858 'tmp' 'unsigned int'
    | | `-ImplicitCastExpr 0x5619d215eae8 <col:14> 'unsigned int' <IntegralCast>
    | |   `-IntegerLiteral 0x5619d215eab0 <col:14> 'int' 65537
    | |-CompoundAssignOperator 0x5619d215eb70 <line:5:5, col:12> 'unsigned int' '+=' ComputeLHSTy='long' ComputeResultTy='long'
    | | |-DeclRefExpr 0x5619d215eb28 <col:5> 'unsigned int' lvalue Var 0x5619d215e858 'tmp' 'unsigned int'
    | | `-IntegerLiteral 0x5619d215eb50 <col:12> 'long' 65537
    | `-<<<NULL>>>
    `-ReturnStmt 0x5619d215ec20 <line:6:3, col:10>
      `-ImplicitCastExpr 0x5619d215ec08 <col:10> 'unsigned int' <LValueToRValue>
        `-DeclRefExpr 0x5619d215ebe0 <col:10> 'unsigned int' lvalue Var 0x5619d215e858 'tmp' 'unsigned int'

Thanks,
Florian



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux