-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[Clang] Permit implicit conversion from integral to boolean vectors #158369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 6 | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -emit-llvm -o - | FileCheck %s | ||
|
||
using v1i = int [[clang::ext_vector_type(1)]]; | ||
using v1b = bool [[clang::ext_vector_type(1)]]; | ||
using v8i = int [[clang::ext_vector_type(8)]]; | ||
using v8b = bool [[clang::ext_vector_type(8)]]; | ||
using v16i = short [[clang::ext_vector_type(16)]]; | ||
using v16b = bool [[clang::ext_vector_type(16)]]; | ||
using v32i = char [[clang::ext_vector_type(32)]]; | ||
using v32b = bool [[clang::ext_vector_type(32)]]; | ||
|
||
// CHECK-LABEL: define dso_local noundef i8 @_Z3fooDv1_i( | ||
// CHECK-SAME: i32 noundef [[V_COERCE:%.*]]) #[[ATTR0:[0-9]+]] { | ||
// CHECK-NEXT: [[ENTRY:.*:]] | ||
// CHECK-NEXT: [[RETVAL:%.*]] = alloca <1 x i1>, align 1 | ||
// CHECK-NEXT: [[V:%.*]] = alloca <1 x i32>, align 4 | ||
// CHECK-NEXT: [[V_ADDR:%.*]] = alloca <1 x i32>, align 4 | ||
// CHECK-NEXT: store i32 [[V_COERCE]], ptr [[V]], align 4 | ||
// CHECK-NEXT: [[V1:%.*]] = load <1 x i32>, ptr [[V]], align 4 | ||
// CHECK-NEXT: store <1 x i32> [[V1]], ptr [[V_ADDR]], align 4 | ||
// CHECK-NEXT: [[TMP0:%.*]] = load <1 x i32>, ptr [[V_ADDR]], align 4 | ||
// CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne <1 x i32> [[TMP0]], zeroinitializer | ||
// CHECK-NEXT: store <1 x i1> [[TOBOOL]], ptr [[RETVAL]], align 1 | ||
// CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr [[RETVAL]], align 1 | ||
// CHECK-NEXT: ret i8 [[TMP1]] | ||
// | ||
v1b foo(v1i v) { return v; } | ||
// CHECK-LABEL: define dso_local noundef i8 @_Z3fooDv8_i( | ||
// CHECK-SAME: ptr noundef byval(<8 x i32>) align 32 [[TMP0:%.*]]) #[[ATTR0]] { | ||
// CHECK-NEXT: [[ENTRY:.*:]] | ||
// CHECK-NEXT: [[RETVAL:%.*]] = alloca <8 x i1>, align 1 | ||
// CHECK-NEXT: [[V_ADDR:%.*]] = alloca <8 x i32>, align 32 | ||
// CHECK-NEXT: [[V:%.*]] = load <8 x i32>, ptr [[TMP0]], align 32 | ||
// CHECK-NEXT: store <8 x i32> [[V]], ptr [[V_ADDR]], align 32 | ||
// CHECK-NEXT: [[TMP1:%.*]] = load <8 x i32>, ptr [[V_ADDR]], align 32 | ||
// CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne <8 x i32> [[TMP1]], zeroinitializer | ||
// CHECK-NEXT: store <8 x i1> [[TOBOOL]], ptr [[RETVAL]], align 1 | ||
// CHECK-NEXT: [[TMP2:%.*]] = load i8, ptr [[RETVAL]], align 1 | ||
// CHECK-NEXT: ret i8 [[TMP2]] | ||
// | ||
v8b foo(v8i v) { return v; } | ||
// CHECK-LABEL: define dso_local noundef i16 @_Z3fooDv16_s( | ||
// CHECK-SAME: ptr noundef byval(<16 x i16>) align 32 [[TMP0:%.*]]) #[[ATTR0]] { | ||
// CHECK-NEXT: [[ENTRY:.*:]] | ||
// CHECK-NEXT: [[RETVAL:%.*]] = alloca <16 x i1>, align 2 | ||
// CHECK-NEXT: [[V_ADDR:%.*]] = alloca <16 x i16>, align 32 | ||
// CHECK-NEXT: [[V:%.*]] = load <16 x i16>, ptr [[TMP0]], align 32 | ||
// CHECK-NEXT: store <16 x i16> [[V]], ptr [[V_ADDR]], align 32 | ||
// CHECK-NEXT: [[TMP1:%.*]] = load <16 x i16>, ptr [[V_ADDR]], align 32 | ||
// CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne <16 x i16> [[TMP1]], zeroinitializer | ||
// CHECK-NEXT: store <16 x i1> [[TOBOOL]], ptr [[RETVAL]], align 2 | ||
// CHECK-NEXT: [[TMP2:%.*]] = load i16, ptr [[RETVAL]], align 2 | ||
// CHECK-NEXT: ret i16 [[TMP2]] | ||
// | ||
v16b foo(v16i v) { return v; } | ||
// CHECK-LABEL: define dso_local noundef i32 @_Z3fooDv32_c( | ||
// CHECK-SAME: ptr noundef byval(<32 x i8>) align 32 [[TMP0:%.*]]) #[[ATTR0]] { | ||
// CHECK-NEXT: [[ENTRY:.*:]] | ||
// CHECK-NEXT: [[RETVAL:%.*]] = alloca <32 x i1>, align 4 | ||
// CHECK-NEXT: [[V_ADDR:%.*]] = alloca <32 x i8>, align 32 | ||
// CHECK-NEXT: [[V:%.*]] = load <32 x i8>, ptr [[TMP0]], align 32 | ||
// CHECK-NEXT: store <32 x i8> [[V]], ptr [[V_ADDR]], align 32 | ||
// CHECK-NEXT: [[TMP1:%.*]] = load <32 x i8>, ptr [[V_ADDR]], align 32 | ||
// CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne <32 x i8> [[TMP1]], zeroinitializer | ||
// CHECK-NEXT: store <32 x i1> [[TOBOOL]], ptr [[RETVAL]], align 4 | ||
// CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[RETVAL]], align 4 | ||
// CHECK-NEXT: ret i32 [[TMP2]] | ||
// | ||
v32b foo(v32i v) { return v; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// RUN: %clang_cc1 -triple x86_64 -fsyntax-only -verify %s | ||
|
||
typedef _Bool bool; | ||
|
||
typedef __attribute__((ext_vector_type(8))) int v8i; | ||
typedef __attribute__((ext_vector_type(8))) bool v8b; | ||
typedef __attribute__((ext_vector_type(4))) float v4f; | ||
typedef __attribute__((ext_vector_type(4))) bool v4b; | ||
|
||
void foo(v8b); | ||
|
||
v8b integral(v8i v) { | ||
v8b m1 = __builtin_convertvector(v, __attribute__((ext_vector_type(8))) int); | ||
v8b m2 = __builtin_convertvector(v, __attribute__((ext_vector_type(8))) unsigned); | ||
v8b m3 = __builtin_convertvector(v, __attribute__((ext_vector_type(8))) long); | ||
v8b m4 = __builtin_convertvector(v, __attribute__((ext_vector_type(8))) unsigned long); | ||
v8b m5 = __builtin_convertvector(v, __attribute__((ext_vector_type(8))) char); | ||
v8b m6 = __builtin_convertvector(v, __attribute__((ext_vector_type(8))) unsigned char); | ||
foo(v); | ||
return v; | ||
} | ||
|
||
v4b non_integral(v4f vf) { | ||
return vf; // expected-error{{returning 'v4f' (vector of 4 'float' values) from a function with incompatible result type 'v4b' (vector of 4 'bool' values}} | ||
} | ||
|
||
v4b size_mismatch(v8i v) { | ||
return v; // expected-error{{returning 'v8i' (vector of 8 'int' values) from a function with incompatible result type 'v4b' (vector of 4 'bool' values)}} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %clang_cc1 -triple x86_64 -fsyntax-only -verify %s | ||
|
||
using v8i = int [[clang::ext_vector_type(8)]]; | ||
using v8b = bool [[clang::ext_vector_type(8)]]; | ||
using v4f = float [[clang::ext_vector_type(4)]]; | ||
using v4b = bool [[clang::ext_vector_type(4)]]; | ||
|
||
void foo(v8b); | ||
|
||
v8b integral(v8i v) { | ||
v8b m1 = __builtin_convertvector(v, int [[clang::ext_vector_type(8)]]); | ||
v8b m2 = __builtin_convertvector(v, unsigned [[clang::ext_vector_type(8)]]); | ||
v8b m3 = __builtin_convertvector(v, long [[clang::ext_vector_type(8)]]); | ||
v8b m4 = __builtin_convertvector(v, unsigned long [[clang::ext_vector_type(8)]]); | ||
v8b m5 = __builtin_convertvector(v, char [[clang::ext_vector_type(8)]]); | ||
v8b m6 = __builtin_convertvector(v, unsigned char [[clang::ext_vector_type(8)]]); | ||
foo(v); | ||
return v; | ||
} | ||
|
||
v4b non_integral(v4f vf) { | ||
return vf; // expected-error{{cannot initialize return object of type 'v4b' (vector of 4 'bool' values) with an lvalue of type 'v4f' (vector of 4 'float' values)}} | ||
} | ||
|
||
v4b size_mismatch(v8i v) { | ||
return v; // expected-error{{cannot initialize return object of type 'v4b' (vector of 4 'bool' values) with an lvalue of type 'v8i' (vector of 8 'int' values)}} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would good to show that these are still narrowing conversions in C++. I did not see any tests that cover this anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I only did assignment, as shown in the changes. I suppose I need to cover the narrowing / initialization case? Unsure where those checks are off the top of my head.