[cfe-commits] r130036 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaCXXCast.cpp test/SemaCXX/reinterpret-cast.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Apr 22 16:57:57 PDT 2011
Author: akirtzidis
Date: Fri Apr 22 18:57:57 2011
New Revision: 130036
URL: http://llvm.org/viewvc/llvm-project?rev=130036&view=rev
Log:
Don't allow reinterpret_cast to reference of vector element and property expression. Thanks goes to Eli Friedman!
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaCXXCast.cpp
cfe/trunk/test/SemaCXX/reinterpret-cast.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=130036&r1=130035&r2=130036&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr 22 18:57:57 2011
@@ -2879,8 +2879,8 @@
"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.
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=130036&r1=130035&r2=130036&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Fri Apr 22 18:57:57 2011
@@ -1327,9 +1327,18 @@
// 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;
}
Modified: cfe/trunk/test/SemaCXX/reinterpret-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/reinterpret-cast.cpp?rev=130036&r1=130035&r2=130036&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/reinterpret-cast.cpp (original)
+++ cfe/trunk/test/SemaCXX/reinterpret-cast.cpp Fri Apr 22 18:57:57 2011
@@ -111,5 +111,8 @@
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}}
}
More information about the cfe-commits
mailing list