Skip to content

Commit 67960e5

Browse files
committed
[OpenACC] Ensure decl OpenACC constructs don't crash
I initially implemented codegen to be a 'no-op' for these declarations, which I thought was properly implemented. However, when they are a top-level decl, we have a separate switch. This patch makes sure they are properly emitted at top-level as a no-op, and adds a test for both top-level and not top-level.
1 parent 5685def commit 67960e5

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7300,6 +7300,13 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
73007300
getHLSLRuntime().addBuffer(cast<HLSLBufferDecl>(D));
73017301
break;
73027302

7303+
case Decl::OpenACCDeclare:
7304+
EmitOpenACCDeclare(cast<OpenACCDeclareDecl>(D));
7305+
break;
7306+
case Decl::OpenACCRoutine:
7307+
EmitOpenACCRoutine(cast<OpenACCRoutineDecl>(D));
7308+
break;
7309+
73037310
default:
73047311
// Make sure we handled everything we should, every other kind is a
73057312
// non-top-level decl. FIXME: Would be nice to have an isTopLevelDeclKind

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,9 +1574,11 @@ class CodeGenModule : public CodeGenTypeCache {
15741574
CodeGenFunction *CGF = nullptr);
15751575

15761576
// Emit code for the OpenACC Declare declaration.
1577-
void EmitOpenACCDeclare(const OpenACCDeclareDecl *D, CodeGenFunction *CGF);
1577+
void EmitOpenACCDeclare(const OpenACCDeclareDecl *D,
1578+
CodeGenFunction *CGF = nullptr);
15781579
// Emit code for the OpenACC Routine declaration.
1579-
void EmitOpenACCRoutine(const OpenACCRoutineDecl *D, CodeGenFunction *CGF);
1580+
void EmitOpenACCRoutine(const OpenACCRoutineDecl *D,
1581+
CodeGenFunction *CGF = nullptr);
15801582

15811583
/// Emit a code for requires directive.
15821584
/// \param D Requires declaration
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
2+
3+
// Check to ensure these are no-ops/don't really do anything.
4+
void name();
5+
6+
void foo() {
7+
#pragma acc declare
8+
// CHECK-NOT: declare
9+
#pragma acc routine(name) worker
10+
// CHECK-NOT: routine
11+
}
12+
#pragma acc declare
13+
// CHECK-NOT: declare
14+
#pragma acc routine(name) worker
15+
// CHECK-NOT: routine

0 commit comments

Comments
 (0)