]> granicus.if.org Git - clang/commit
Surpress ImplicitCastExprs for compound assignment expressions. For compound assignments,
authorSteve Naroff <snaroff@apple.com>
Fri, 24 Aug 2007 19:07:16 +0000 (19:07 +0000)
committerSteve Naroff <snaroff@apple.com>
Fri, 24 Aug 2007 19:07:16 +0000 (19:07 +0000)
commit9f5fa9bfc37c3e15895cd777e42f3dd8a7ec7a9d
tree59e0b9d3b05ae5cf1ca3b1ac35055f0483a41755
parent77ed8e4edf6ed78c53fb20ec3210aff2a59c9d87
Surpress ImplicitCastExprs for compound assignment expressions. For compound assignments,
it is o.k. for the LHS and RHS to have different types. Converting the type can cause
errors like the one Chris noticed (below).

This change required a fair number of diffs (since there is a lot of shared code
between single and compound assignments). This makes the API's look a bit uglier,
however I couldn't think of a better way to do it (without duplicating code).

Fix the following (incorrect) error:

int A;
long long B;

void foo() {
  A /= B;
}

$ clang ~/scalar.c -emit-llvm
/Users/sabre/scalar.c:6:5: error: expression is not assignable
  A /= B;
  ~ ^

Now it works properly...

[dylan:~/llvm/tools/clang] admin% cat compound.c
int A;
long long B;

void foo() {
  A /= B;
}
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang compound.c -parse-ast-dump
Read top-level variable decl: 'A'
Read top-level variable decl: 'B'

void foo()
(CompoundStmt 0x2605c40
  (BinaryOperator 0x2605c20 'int' '/=' ComputeTy='long long'
    (DeclRefExpr 0x2605be0 'int' Decl='A' 0x2605a80)
    (DeclRefExpr 0x2605c00 'long long' Decl='B' 0x2605ab0)))

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41364 91177308-0d34-0410-b5e6-96231b3b80d8
Sema/Sema.h
Sema/SemaExpr.cpp
include/clang/AST/StmtNodes.def