|
| 1 | +// REQUIRES: amdgpu-registered-target |
| 2 | + |
| 3 | +// Regression test for issue #199563: -ast-print on |
| 4 | +// __builtin_amdgcn_is_invocable / __builtin_amdgcn_processor_is used to |
| 5 | +// crash because the expansion produced an IntegerLiteral typed _Bool/bool. |
| 6 | + |
| 7 | +// C (C11 and C23): IntegerLiteral 'int' implicit-cast to _Bool. |
| 8 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx942 -std=c11 \ |
| 9 | +// RUN: -ast-print %s | FileCheck --check-prefix=INT-TRUE %s |
| 10 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx900 -std=c11 \ |
| 11 | +// RUN: -ast-print %s | FileCheck --check-prefix=INT-FALSE %s |
| 12 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx942 -std=c11 \ |
| 13 | +// RUN: -ast-dump %s | FileCheck --check-prefix=INT-DUMP %s |
| 14 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx942 -std=c23 \ |
| 15 | +// RUN: -ast-print %s | FileCheck --check-prefix=INT-TRUE %s |
| 16 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx900 -std=c23 \ |
| 17 | +// RUN: -ast-print %s | FileCheck --check-prefix=INT-FALSE %s |
| 18 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx942 -std=c23 \ |
| 19 | +// RUN: -ast-dump %s | FileCheck --check-prefix=INT-DUMP %s |
| 20 | + |
| 21 | +// C++ / HIP device: CXXBoolLiteralExpr 'bool'. |
| 22 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx942 -x c++ \ |
| 23 | +// RUN: -std=c++17 -ast-print %s | FileCheck --check-prefix=BOOL-TRUE %s |
| 24 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx900 -x c++ \ |
| 25 | +// RUN: -std=c++17 -ast-print %s | FileCheck --check-prefix=BOOL-FALSE %s |
| 26 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx942 -x c++ \ |
| 27 | +// RUN: -std=c++17 -ast-dump %s | FileCheck --check-prefix=BOOL-DUMP %s |
| 28 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx942 -x hip \ |
| 29 | +// RUN: -fcuda-is-device -ast-print %s \ |
| 30 | +// RUN: | FileCheck --check-prefix=BOOL-TRUE %s |
| 31 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx900 -x hip \ |
| 32 | +// RUN: -fcuda-is-device -ast-print %s \ |
| 33 | +// RUN: | FileCheck --check-prefix=BOOL-FALSE %s |
| 34 | +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx942 -x hip \ |
| 35 | +// RUN: -fcuda-is-device -ast-dump %s \ |
| 36 | +// RUN: | FileCheck --check-prefix=BOOL-DUMP %s |
| 37 | + |
| 38 | +#if defined(__HIP__) || defined(__CUDA__) |
| 39 | +#define __device__ __attribute__((device)) |
| 40 | +#else |
| 41 | +#define __device__ |
| 42 | +#endif |
| 43 | + |
| 44 | +__device__ void use_is_invocable(void) { |
| 45 | + if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_flat_atomic_fadd_f32)) |
| 46 | + (void)0; |
| 47 | +} |
| 48 | + |
| 49 | +__device__ void use_processor_is(void) { |
| 50 | + if (__builtin_amdgcn_processor_is("gfx942")) |
| 51 | + (void)0; |
| 52 | +} |
| 53 | + |
| 54 | +// INT-TRUE-LABEL: use_is_invocable |
| 55 | +// INT-TRUE: if (1) |
| 56 | +// INT-TRUE-LABEL: use_processor_is |
| 57 | +// INT-TRUE: if (1) |
| 58 | + |
| 59 | +// INT-FALSE-LABEL: use_is_invocable |
| 60 | +// INT-FALSE: if (0) |
| 61 | +// INT-FALSE-LABEL: use_processor_is |
| 62 | +// INT-FALSE: if (0) |
| 63 | + |
| 64 | +// BOOL-TRUE-LABEL: use_is_invocable |
| 65 | +// BOOL-TRUE: if (true) |
| 66 | +// BOOL-TRUE-LABEL: use_processor_is |
| 67 | +// BOOL-TRUE: if (true) |
| 68 | + |
| 69 | +// BOOL-FALSE-LABEL: use_is_invocable |
| 70 | +// BOOL-FALSE: if (false) |
| 71 | +// BOOL-FALSE-LABEL: use_processor_is |
| 72 | +// BOOL-FALSE: if (false) |
| 73 | + |
| 74 | +// INT-DUMP-LABEL: FunctionDecl {{.*}} use_is_invocable |
| 75 | +// INT-DUMP: IfStmt |
| 76 | +// INT-DUMP-NEXT: ImplicitCastExpr {{.*}} {{'_Bool'|'bool'}} <IntegralToBoolean> |
| 77 | +// INT-DUMP-NEXT: IntegerLiteral {{.*}} 'int' 1 |
| 78 | +// INT-DUMP-LABEL: FunctionDecl {{.*}} use_processor_is |
| 79 | +// INT-DUMP: IfStmt |
| 80 | +// INT-DUMP-NEXT: ImplicitCastExpr {{.*}} {{'_Bool'|'bool'}} <IntegralToBoolean> |
| 81 | +// INT-DUMP-NEXT: IntegerLiteral {{.*}} 'int' 1 |
| 82 | + |
| 83 | +// BOOL-DUMP-LABEL: FunctionDecl {{.*}} use_is_invocable |
| 84 | +// BOOL-DUMP: IfStmt |
| 85 | +// BOOL-DUMP-NEXT: CXXBoolLiteralExpr {{.*}} 'bool' true |
| 86 | +// BOOL-DUMP-LABEL: FunctionDecl {{.*}} use_processor_is |
| 87 | +// BOOL-DUMP: IfStmt |
| 88 | +// BOOL-DUMP-NEXT: CXXBoolLiteralExpr {{.*}} 'bool' true |
0 commit comments