[cfe-commits] r44912 - in /cfe/trunk/Sema: Sema.h SemaExpr.cpp
Chris Lattner
sabre at nondot.org
Tue Dec 11 21:47:29 PST 2007
Author: lattner
Date: Tue Dec 11 23:47:28 2007
New Revision: 44912
URL: http://llvm.org/viewvc/llvm-project?rev=44912&view=rev
Log:
implement correct semantic analysis for shifts. For:
int test(int x, long long y) {
return x << y;
}
we now realize the type of the shift is int, not long long.
This fixes a fixme from june.
Modified:
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaExpr.cpp
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=44912&r1=44911&r2=44912&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Dec 11 23:47:28 2007
@@ -631,7 +631,7 @@
/// or a null QualType (indicating an error diagnostic was issued).
/// type checking binary operators (subroutines of ActOnBinOp).
- inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
+ inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44912&r1=44911&r2=44912&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Tue Dec 11 23:47:28 2007
@@ -1176,10 +1176,11 @@
return CheckAssignmentConstraints(lhsType, rhsType);
}
-inline void Sema::InvalidOperands(SourceLocation loc, Expr *&lex, Expr *&rex) {
+QualType Sema::InvalidOperands(SourceLocation loc, Expr *&lex, Expr *&rex) {
Diag(loc, diag::err_typecheck_invalid_operands,
lex->getType().getAsString(), rex->getType().getAsString(),
lex->getSourceRange(), rex->getSourceRange());
+ return QualType();
}
inline QualType Sema::CheckVectorOperands(SourceLocation loc, Expr *&lex,
@@ -1208,8 +1209,7 @@
if (lex->getType()->isArithmeticType() && rex->getType()->isArithmeticType())
return compType;
- InvalidOperands(loc, lex, rex);
- return QualType();
+ return InvalidOperands(loc, lex, rex);
}
inline QualType Sema::CheckRemainderOperands(
@@ -1221,8 +1221,7 @@
if (lex->getType()->isIntegerType() && rex->getType()->isIntegerType())
return compType;
- InvalidOperands(loc, lex, rex);
- return QualType();
+ return InvalidOperands(loc, lex, rex);
}
inline QualType Sema::CheckAdditionOperands( // C99 6.5.6
@@ -1241,8 +1240,7 @@
return lex->getType();
if (lex->getType()->isIntegerType() && rex->getType()->isPointerType())
return rex->getType();
- InvalidOperands(loc, lex, rex);
- return QualType();
+ return InvalidOperands(loc, lex, rex);
}
inline QualType Sema::CheckSubtractionOperands( // C99 6.5.6
@@ -1307,22 +1305,22 @@
}
}
- InvalidOperands(loc, lex, rex);
- return QualType();
+ return InvalidOperands(loc, lex, rex);
}
inline QualType Sema::CheckShiftOperands( // C99 6.5.7
- Expr *&lex, Expr *&rex, SourceLocation loc, bool isCompAssign)
-{
- // FIXME: Shifts don't perform usual arithmetic conversions. This is wrong
- // for int << longlong -> the result type should be int, not long long.
- QualType compType = UsualArithmeticConversions(lex, rex, isCompAssign);
+ Expr *&lex, Expr *&rex, SourceLocation loc, bool isCompAssign) {
+ // C99 6.5.7p2: Each of the operands shall have integer type.
+ if (!lex->getType()->isIntegerType() || !rex->getType()->isIntegerType())
+ return InvalidOperands(loc, lex, rex);
- // handle the common case first (both operands are arithmetic).
- if (lex->getType()->isIntegerType() && rex->getType()->isIntegerType())
- return compType;
- InvalidOperands(loc, lex, rex);
- return QualType();
+ // Shifts don't perform usual arithmetic conversions, they just do integer
+ // promotions on each operand. C99 6.5.7p3
+ UsualUnaryConversions(lex);
+ UsualUnaryConversions(rex);
+
+ // "The type of the result is that of the promoted left operand."
+ return lex->getType();
}
inline QualType Sema::CheckCompareOperands( // C99 6.5.8
@@ -1398,8 +1396,7 @@
promoteExprToType(lex, rType); // promote the integer to pointer
return Context.IntTy;
}
- InvalidOperands(loc, lex, rex);
- return QualType();
+ return InvalidOperands(loc, lex, rex);
}
inline QualType Sema::CheckBitwiseOperands(
@@ -1412,8 +1409,7 @@
if (lex->getType()->isIntegerType() && rex->getType()->isIntegerType())
return compType;
- InvalidOperands(loc, lex, rex);
- return QualType();
+ return InvalidOperands(loc, lex, rex);
}
inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14]
@@ -1424,8 +1420,7 @@
if (lex->getType()->isScalarType() || rex->getType()->isScalarType())
return Context.IntTy;
- InvalidOperands(loc, lex, rex);
- return QualType();
+ return InvalidOperands(loc, lex, rex);
}
inline QualType Sema::CheckAssignmentOperands( // C99 6.5.16.1
More information about the cfe-commits
mailing list