[PATCH] D50278: [Sema] Fix for crash on conditional operation with address_space pointer
Leonard Chan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 6 09:22:02 PDT 2018
leonardchan updated this revision to Diff 159315.
leonardchan added reviewers: ebevhan, rjmccall.
leonardchan removed a subscriber: ebevhan.
leonardchan added a comment.
- Changed diff such that an error is dumped instead. The code shouldn't compile in the first place since it involves conversion between pointers from different address_spaces.
Repository:
rC Clang
https://reviews.llvm.org/D50278
Files:
lib/Sema/SemaExpr.cpp
test/Sema/address_spaces.c
test/Sema/conditional-expr.c
Index: test/Sema/conditional-expr.c
===================================================================
--- test/Sema/conditional-expr.c
+++ test/Sema/conditional-expr.c
@@ -74,9 +74,12 @@
int __attribute__((address_space(2))) *adr2;
int __attribute__((address_space(3))) *adr3;
test0 ? adr2 : adr3; // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}}
+ // expected-error at -1{{converting '__attribute__((address_space(2))) int *' to type 'void *' changes address space of pointer}}
+ // expected-error at -2{{converting '__attribute__((address_space(3))) int *' to type 'void *' changes address space of pointer}}
// Make sure address-space mask ends up in the result type
(test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}}
+ // expected-error at -1{{converting '__attribute__((address_space(2))) int *' to type 'void *' changes address space of pointer}}
}
int Postgresql() {
Index: test/Sema/address_spaces.c
===================================================================
--- test/Sema/address_spaces.c
+++ test/Sema/address_spaces.c
@@ -72,4 +72,6 @@
// Clang extension doesn't forbid operations on pointers to different address spaces.
char* cmp(_AS1 char *x, _AS2 char *y) {
return x < y ? x : y; // expected-warning {{pointer type mismatch ('__attribute__((address_space(1))) char *' and '__attribute__((address_space(2))) char *')}}
+ // expected-error at -1{{converting '__attribute__((address_space(1))) char *' to type 'void *' changes address space of pointer}}
+ // expected-error at -2{{converting '__attribute__((address_space(2))) char *' to type 'void *' changes address space of pointer}}
}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -6527,6 +6527,21 @@
S.Diag(Loc, diag::ext_typecheck_cond_incompatible_pointers)
<< LHSTy << RHSTy << LHS.get()->getSourceRange()
<< RHS.get()->getSourceRange();
+
+ // If the addresse spacesare different, we do not allow a bitcast.
+ if (!S.getLangOpts().OpenCL) {
+ if (LAddrSpace != ResultAddrSpace) {
+ S.Diag(Loc, diag::err_typecheck_incompatible_address_space)
+ << LHSTy << incompatTy << Sema::AA_Converting
+ << LHS.get()->getSourceRange();
+ }
+ if (RAddrSpace != ResultAddrSpace) {
+ S.Diag(Loc, diag::err_typecheck_incompatible_address_space)
+ << RHSTy << incompatTy << Sema::AA_Converting
+ << RHS.get()->getSourceRange();
+ }
+ }
+
return incompatTy;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50278.159315.patch
Type: text/x-patch
Size: 2834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180806/739a00fa/attachment.bin>
More information about the cfe-commits
mailing list