summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-22 23:57:57 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-22 23:57:57 +0000
commitbf04231a7254b2423e4d801b3ee7b409f4ef985e (patch)
tree06aadc2e1bc292a01d98b429c951afbd8b878be1 /clang
parent58b59f9522a0aafd4c2efe0781a9c88f005b7e00 (diff)
downloadbcm5719-llvm-bf04231a7254b2423e4d801b3ee7b409f4ef985e.tar.gz
bcm5719-llvm-bf04231a7254b2423e4d801b3ee7b409f4ef985e.zip
Don't allow reinterpret_cast to reference of vector element and property expression. Thanks goes to Eli Friedman!
llvm-svn: 130036
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td4
-rw-r--r--clang/lib/Sema/SemaCXXCast.cpp15
-rw-r--r--clang/test/SemaCXX/reinterpret-cast.cpp5
3 files changed, 18 insertions, 6 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6e130b17972..910536ab7a6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2879,8 +2879,8 @@ def err_bad_cxx_cast_member_pointer_size : Error<
"cannot %select{||reinterpret_cast||C-style cast|}0 from member pointer "
"type %1 to member pointer type %2 of different size">;
def err_bad_static_cast_incomplete : Error<"%0 is an incomplete type">;
-def err_bad_reinterpret_cast_bitfield : Error<
- "reinterpret_cast of a bit-field to %2 needs its address which is not allowed">;
+def err_bad_reinterpret_cast_reference : Error<
+ "reinterpret_cast of a %0 to %1 needs its address which is not allowed">;
// These messages don't adhere to the pattern.
// FIXME: Display the path somehow better.
diff --git a/clang/lib/Sema/SemaCXXCast.cpp b/clang/lib/Sema/SemaCXXCast.cpp
index 29475539d71..743fdd25665 100644
--- a/clang/lib/Sema/SemaCXXCast.cpp
+++ b/clang/lib/Sema/SemaCXXCast.cpp
@@ -1327,9 +1327,18 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr,
// same effect as the conversion *reinterpret_cast<T*>(&x) with the
// built-in & and * operators.
- // Cannot get address of a bitfield.
- if (SrcExpr.get()->getObjectKind() == OK_BitField) {
- msg = diag::err_bad_reinterpret_cast_bitfield;
+ const char *inappropriate = 0;
+ switch (SrcExpr.get()->getObjectKind()) {
+ default: break;
+ case OK_BitField: inappropriate = "bit-field"; break;
+ case OK_VectorComponent: inappropriate = "vector element"; break;
+ case OK_ObjCProperty: inappropriate = "property expression"; break;
+ }
+ if (inappropriate) {
+ Self.Diag(OpRange.getBegin(), diag::err_bad_reinterpret_cast_reference)
+ << inappropriate << DestType
+ << OpRange << SrcExpr.get()->getSourceRange();
+ msg = 0; SrcExpr = ExprError();
return TC_NotApplicable;
}
diff --git a/clang/test/SemaCXX/reinterpret-cast.cpp b/clang/test/SemaCXX/reinterpret-cast.cpp
index 2ec45b37cde..f5262496c4b 100644
--- a/clang/test/SemaCXX/reinterpret-cast.cpp
+++ b/clang/test/SemaCXX/reinterpret-cast.cpp
@@ -111,5 +111,8 @@ void const_arrays() {
namespace PR9564 {
struct a { int a : 10; }; a x;
- int *y = &reinterpret_cast<int&>(x.a); // expected-error {{reinterpret_cast of a bit-field to 'int &' needs its address which is not allowed}}
+ int *y = &reinterpret_cast<int&>(x.a); // expected-error {{not allowed}}
+
+ __attribute((ext_vector_type(4))) typedef float v4;
+ float& w(v4 &a) { return reinterpret_cast<float&>(a[1]); } // expected-error {{not allowed}}
}
OpenPOWER on IntegriCloud