[cfe-commits] r55765 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/Sema.cpp
Mon P Wang
wangmp at apple.com
Thu Sep 4 01:38:02 PDT 2008
Author: wangmp
Date: Thu Sep 4 03:38:01 2008
New Revision: 55765
URL: http://llvm.org/viewvc/llvm-project?rev=55765&view=rev
Log:
Generate error if we try to implicit cast between different address
spaces
Modified:
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/lib/Sema/Sema.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=55765&r1=55764&r2=55765&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Thu Sep 4 03:38:01 2008
@@ -670,6 +670,8 @@
"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,
Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=55765&r1=55764&r2=55765&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Thu Sep 4 03:38:01 2008
@@ -114,14 +114,29 @@
/// 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) {
More information about the cfe-commits
mailing list