Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit conversions for compound assignments. #8

Open
rsaill opened this issue Apr 12, 2023 · 0 comments
Open

Implicit conversions for compound assignments. #8

rsaill opened this issue Apr 12, 2023 · 0 comments

Comments

@rsaill
Copy link

rsaill commented Apr 12, 2023

If I dump Clang's AST for the following program
(using clang -Xclang -ast-dump -fsyntax-only compound.c)

void foo(void){
  short s1 = 42;
  short s2 = 2;
  s1 <<= s2;
  return s1;
}

I can see the following information:

|-CompoundAssignOperator 0x125a308 <line:4:3, col:10> 'short' '<<=' ComputeLHSTy='int' ComputeResultTy='int'
    | |-DeclRefExpr 0x125a268 <col:3> 'short' lvalue Var 0x125a0e0 's1' 'short'
    | `-ImplicitCastExpr 0x125a2f0 <col:10> 'int' <IntegralCast>
    |   `-ImplicitCastExpr 0x125a2d8 <col:10> 'short' <LValueToRValue>
    |     `-DeclRefExpr 0x125a288 <col:10> 'short' lvalue Var 0x125a1b0 's2' 'short'

The ComputeLHSTy and ComputeResultTy parts tell me that when performing s1 <<= s2, s1 is implicitly converted to int before the shift
and the result is an int, so it should be re-converted to short before updating s1.

It would be nice to be able to extract this information from clangml'AST as well (at least when option 'Clang.Ast.Options.ignore_implicit_cast' is false).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant