summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMon P Wang <wangmp@apple.com>2008-09-04 08:38:01 +0000
committerMon P Wang <wangmp@apple.com>2008-09-04 08:38:01 +0000
commit74b3207e67a23ef1b15fcaa344e0fa6b950c4967 (patch)
tree0eae31f98cb98d96b74755da6aa863151041baf7
parent4f948bd87a006b9849e1fc40941dfdf1c1c896e2 (diff)
downloadbcm5719-llvm-74b3207e67a23ef1b15fcaa344e0fa6b950c4967.tar.gz
bcm5719-llvm-74b3207e67a23ef1b15fcaa344e0fa6b950c4967.zip
Generate error if we try to implicit cast between different address
spaces llvm-svn: 55765
-rw-r--r--clang/include/clang/Basic/DiagnosticKinds.def2
-rw-r--r--clang/lib/Sema/Sema.cpp25
2 files changed, 22 insertions, 5 deletions
diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def
index e6cc8ef772c..2fe462a9a0c 100644
--- a/clang/include/clang/Basic/DiagnosticKinds.def
+++ b/clang/include/clang/Basic/DiagnosticKinds.def
@@ -670,6 +670,8 @@ DIAG(err_attribute_address_space_not_int, ERROR,
"address space attribute requires an integer constant")
DIAG(err_attribute_address_multiple_qualifiers, ERROR,
"multiple address spaces specified for type")
+DIAG(err_implicit_pointer_address_space_cast, ERROR,
+ "illegal implicit cast between two pointers with different address spaces")
DIAG(err_as_qualified_auto_decl, ERROR,
"automatic variable qualified with an address space")
DIAG(err_attribute_annotate_no_string, ERROR,
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 65f1d6812b6..b288c627872 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -114,14 +114,29 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
/// If there is already an implicit cast, merge into the existing one.
-void Sema::ImpCastExprToType(Expr *&Expr, QualType Type) {
- if (Context.getCanonicalType(Expr->getType()) ==
- Context.getCanonicalType(Type)) return;
+void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty) {
+ QualType ExprTy = Context.getCanonicalType(Expr->getType());
+ QualType TypeTy = Context.getCanonicalType(Ty);
+
+ if (ExprTy == TypeTy)
+ return;
+
+ if (Expr->getType().getTypePtr()->isPointerType() &&
+ Ty.getTypePtr()->isPointerType()) {
+ QualType ExprBaseType =
+ cast<PointerType>(ExprTy.getUnqualifiedType())->getPointeeType();
+ QualType BaseType =
+ cast<PointerType>(TypeTy.getUnqualifiedType())->getPointeeType();
+ if (ExprBaseType.getAddressSpace() != BaseType.getAddressSpace()) {
+ Diag(Expr->getExprLoc(), diag::err_implicit_pointer_address_space_cast,
+ Expr->getSourceRange());
+ }
+ }
if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr))
- ImpCast->setType(Type);
+ ImpCast->setType(Ty);
else
- Expr = new ImplicitCastExpr(Type, Expr);
+ Expr = new ImplicitCastExpr(Ty, Expr);
}
void Sema::DeleteExpr(ExprTy *E) {
OpenPOWER on IntegriCloud