David Pagan 88f1ec9a70
[clang][OpenMP] Parse/Sema for OpenMP 6.0 declare_target 'local' clause (#186281)
Parse and perform semantic checks for declare_target 'local' clause.
When compiling for device offloading, generate a warning that 'local' is
not yet fully supported. On the host, 'local' is/will be a no-op, so no
warning is generated.

NOTE: The minimal CodeGen changes allow 'local' to flow through as
equivalent to the 'enter' clause after warning is generated.

Testing:
  - Updated messages and ast tests for declare target/declare_target
  - ninja check-all.
2026-03-16 19:36:25 -07:00

115 lines
6.4 KiB
C++

// RUN: %clang_cc1 -verify -fopenmp -ast-dump %s | FileCheck %s -implicit-check-not=openmp_structured_block
// RUN: %clang_cc1 -verify -fopenmp-simd -ast-dump %s | FileCheck %s -implicit-check-not=openmp_structured_block
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=60 -ast-dump %s | FileCheck %s --check-prefix=OMP60
// expected-no-diagnostics
int ga, gb;
#pragma omp threadprivate(ga, gb)
// CHECK: |-OMPThreadPrivateDecl {{.+}} <col:1> col:1
// CHECK-NEXT: | |-DeclRefExpr {{.+}} <col:27> 'int' lvalue Var {{.+}} 'ga' 'int'
// CHECK-NEXT: | `-DeclRefExpr {{.+}} <col:31> 'int' lvalue Var {{.+}} 'gb' 'int'
#pragma omp declare reduction(+ : int, char : omp_out *= omp_in)
#pragma omp declare reduction(fun : float : omp_out += omp_in) initializer(omp_priv = omp_orig + 15)
// CHECK: |-OMPDeclareReductionDecl {{.+}} <line:[[@LINE-4]]:35> col:35 operator+ 'int' combiner 0x{{.+}}
// CHECK-NEXT: | |-CompoundAssignOperator {{.+}} <col:47, col:58> 'int' lvalue '*=' ComputeLHSTy='int' ComputeResultTy='int'
// CHECK-NEXT: | | |-DeclRefExpr {{.+}} <col:47> 'int' lvalue Var {{.+}} 'omp_out' 'int'
// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} <col:58> 'int' <LValueToRValue>
// CHECK-NEXT: | | `-DeclRefExpr {{.+}} <col:58> 'int' lvalue Var {{.+}} 'omp_in' 'int'
// CHECK-NEXT: | |-VarDecl {{.+}} <col:35> col:35 implicit used omp_in 'int'
// CHECK-NEXT: | `-VarDecl {{.+}} <col:35> col:35 implicit used omp_out 'int'
// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}} <col:40> col:40 operator+ 'char' combiner 0x{{.+}}
// CHECK-NEXT: | |-CompoundAssignOperator {{.+}} <col:47, col:58> 'char' lvalue '*=' ComputeLHSTy='int' ComputeResultTy='int'
// CHECK-NEXT: | | |-DeclRefExpr {{.+}} <col:47> 'char' lvalue Var {{.+}} 'omp_out' 'char'
// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} <col:58> 'int' <IntegralCast>
// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} <col:58> 'char' <LValueToRValue>
// CHECK-NEXT: | | `-DeclRefExpr {{.+}} <col:58> 'char' lvalue Var {{.+}} 'omp_in' 'char'
// CHECK-NEXT: | |-VarDecl {{.+}} <col:40> col:40 implicit used omp_in 'char'
// CHECK-NEXT: | `-VarDecl {{.+}} <col:40> col:40 implicit used omp_out 'char'
// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}} <line:[[@LINE-17]]:37> col:37 fun 'float' combiner 0x{{.+}} initializer 0x{{.+}}
// CHECK-NEXT: | |-CompoundAssignOperator {{.+}} <col:45, col:56> 'float' lvalue '+=' ComputeLHSTy='float' ComputeResultTy='float'
// CHECK-NEXT: | | |-DeclRefExpr {{.+}} <col:45> 'float' lvalue Var {{.+}} 'omp_out' 'float'
// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} <col:56> 'float' <LValueToRValue>
// CHECK-NEXT: | | `-DeclRefExpr {{.+}} <col:56> 'float' lvalue Var {{.+}} 'omp_in' 'float'
// CHECK-NEXT: | |-BinaryOperator {{.+}} <col:87, col:98> 'float' '+'
// CHECK-NEXT: | | |-ImplicitCastExpr {{.+}} <col:87> 'float' <LValueToRValue>
// CHECK-NEXT: | | | `-DeclRefExpr {{.+}} <col:87> 'float' lvalue Var {{.+}} 'omp_orig' 'float'
// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} <col:98> 'float' <IntegralToFloating>
// CHECK-NEXT: | | `-IntegerLiteral {{.+}} <col:98> 'int' 15
struct S {
int a, b;
S() {
#pragma omp parallel for default(none) private(a) shared(b) schedule(static, a)
for (int i = 0; i < 0; ++i)
++a;
}
};
// CHECK: | `-OMPParallelForDirective {{.+}} {{<line:.+:1, col:80>|<col:1, col:80>}}
// CHECK-NEXT: | |-OMPDefaultClause {{.+}} <col:26, col:38>
// CHECK-NEXT: | |-OMPPrivateClause {{.+}} <col:40, col:49>
// CHECK-NEXT: | | `-DeclRefExpr {{.+}} <col:48> 'int' lvalue OMPCapturedExpr {{.+}} 'a' 'int &'
// CHECK-NEXT: | |-OMPSharedClause {{.+}} <col:51, col:59>
// CHECK-NEXT: | | `-MemberExpr {{.+}} <col:58> 'int' lvalue ->b
// CHECK-NEXT: | | `-CXXThisExpr {{.+}} <col:58> 'S *' implicit this
// CHECK-NEXT: | |-OMPScheduleClause {{.+}} <col:61, col:79>
// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} <col:78> 'int' <LValueToRValue>
// CHECK-NEXT: | | `-DeclRefExpr {{.+}} <col:78> 'int' lvalue OMPCapturedExpr {{.+}} '.capture_expr.' 'int'
// CHECK-NEXT: | `-CapturedStmt {{.+}} <line:[[@LINE-15]]:5, line:[[@LINE-14]]:9>
// CHECK-NEXT: | |-CapturedDecl {{.+}} <<invalid sloc>> <invalid sloc> nothrow
// CHECK-NEXT: | | |-ForStmt {{.+}} <line:[[@LINE-17]]:5, line:[[@LINE-16]]:9>
// CHECK: | | | `-UnaryOperator {{.+}} <line:[[@LINE-17]]:7, col:9> 'int' lvalue prefix '++'
// CHECK-NEXT: | | | `-DeclRefExpr {{.+}} <col:9> 'int' lvalue OMPCapturedExpr {{.+}} 'a' 'int &'
#pragma omp declare simd
#pragma omp declare simd inbranch
void foo();
// CHECK: |-FunctionDecl {{.+}} <line:[[@LINE-2]]:1, col:10> col:6 foo 'void ()'
// CHECK-NEXT: |-OMPDeclareSimdDeclAttr {{.+}} <line:[[@LINE-4]]:1, col:34> Implicit BS_Inbranch
// CHECK: `-OMPDeclareSimdDeclAttr {{.+}} <line:[[@LINE-6]]:1, col:25> Implicit BS_Undefined
// Beginning in OpenMP 5.2, this form began generating a warning that it
// is deprecated and to use the 'begin declare target' form instead.
#if _OPENMP <= 202011
#pragma omp declare target
#else
#pragma omp begin declare target
#endif // _OPENMP
int bar() {
int f;
return f;
}
#pragma omp end declare target
// CHECK: `-FunctionDecl {{.+}} <line:[[@LINE-6]]:1, line:[[@LINE-3]]:1> line:[[@LINE-6]]:5 bar 'int ()'
// CHECK-NEXT: |-CompoundStmt {{.+}} <col:11, line:[[@LINE-4]]:1>
// CHECK-NEXT: | |-DeclStmt {{.+}} <line:[[@LINE-7]]:3, col:8>
// CHECK-NEXT: | | `-VarDecl {{.+}} <col:3, col:7> col:7 used f 'int'
// CHECK-NEXT: | `-ReturnStmt {{.+}} <line:[[@LINE-8]]:3, col:10>
// CHECK-NEXT: | `-ImplicitCastExpr {{.+}} <col:10> 'int' <LValueToRValue>
// CHECK-NEXT: | `-DeclRefExpr {{.+}} <col:10> 'int' lvalue Var {{.+}} 'f' 'int'
// CHECK-NEXT: `-OMPDeclareTargetDeclAttr {{.+}} Implicit MT_To DT_Any 1
#if _OPENMP >= 202411
int v_enter;
#pragma omp declare target enter(v_enter) device_type(nohost)
int v_link;
#pragma omp declare target link(v_link) device_type(host)
int v_local;
#pragma omp declare target local(v_local)
#endif
// OMP60: FunctionDecl {{.+}} bar 'int ()'
// OMP60: `-OMPDeclareTargetDeclAttr {{.+}} Implicit MT_Enter DT_Any 1
// OMP60: VarDecl {{.+}} v_enter 'int'
// OMP60-NEXT: `-OMPDeclareTargetDeclAttr {{.+}} Implicit MT_Enter DT_NoHost 4294967295
// OMP60: VarDecl {{.+}} v_link 'int'
// OMP60-NEXT: `-OMPDeclareTargetDeclAttr {{.+}} Implicit MT_Link DT_Host 4294967295
// OMP60: VarDecl {{.+}} v_local 'int'
// OMP60-NEXT: `-OMPDeclareTargetDeclAttr {{.+}} Implicit MT_Local DT_Any 4294967295