mirror of
https://github.com/intel/llvm.git
synced 2026-02-02 01:30:24 +08:00
PR4013 and PR4105: pointer-like types can only be cast to/from integers
and other pointer-like types. llvm-svn: 70531
This commit is contained in:
@@ -1319,6 +1319,10 @@ def ext_typecheck_cast_nonscalar : Extension<
|
||||
def ext_typecheck_cast_to_union : Extension<"C99 forbids casts to union type">;
|
||||
def err_typecheck_cast_to_union_no_type : Error<
|
||||
"cast to union type from type %0 not present in union">;
|
||||
def err_cast_pointer_from_non_pointer_int : Error<
|
||||
"operand of type %0 cannot be cast to a pointer type">;
|
||||
def err_cast_pointer_to_non_pointer_int : Error<
|
||||
"pointer cannot be cast to type %0">;
|
||||
def err_typecheck_expect_scalar_operand : Error<
|
||||
"operand of type %0 where arithmetic or pointer type is required">;
|
||||
def err_typecheck_cond_incompatible_operands : Error<
|
||||
|
||||
@@ -2604,6 +2604,17 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr) {
|
||||
return true;
|
||||
} else if (getLangOptions().ObjC1 && isa<ObjCSuperExpr>(castExpr)) {
|
||||
return Diag(castExpr->getLocStart(), diag::err_illegal_super_cast) << TyR;
|
||||
} else if (!castType->isArithmeticType()) {
|
||||
QualType castExprType = castExpr->getType();
|
||||
if (!castExprType->isIntegralType() && castExprType->isArithmeticType())
|
||||
return Diag(castExpr->getLocStart(),
|
||||
diag::err_cast_pointer_from_non_pointer_int)
|
||||
<< castExprType << castExpr->getSourceRange();
|
||||
} else if (!castExpr->getType()->isArithmeticType()) {
|
||||
if (!castType->isIntegralType() && castType->isArithmeticType())
|
||||
return Diag(castExpr->getLocStart(),
|
||||
diag::err_cast_pointer_to_non_pointer_int)
|
||||
<< castType << castExpr->getSourceRange();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,10 @@ cpumask_t x;
|
||||
void foo() {
|
||||
(void)x;
|
||||
}
|
||||
void bar() {
|
||||
char* a;
|
||||
double b;
|
||||
b = (double)a; // expected-error {{pointer cannot be cast to type}}
|
||||
a = (char*)b; // expected-error {{cannot be cast to a pointer type}}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
static int f = 10;
|
||||
static int b = f; // expected-error {{initializer element is not a compile-time constant}}
|
||||
|
||||
float r = (float) &r; // expected-error {{initializer element is not a compile-time constant}}
|
||||
float r = (float) (intptr_t) &r; // expected-error {{initializer element is not a compile-time constant}}
|
||||
intptr_t s = (intptr_t) &s;
|
||||
_Bool t = &t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user