diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 4719a242035ed..fb3a132cae30e 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -1754,6 +1754,11 @@ void CompilerInvocation::setDefaultPredefinitions() { fortranOptions.predefinitions); } + if (frontendOptions.features.IsEnabled( + Fortran::common::LanguageFeature::CUDA)) { + fortranOptions.predefinitions.emplace_back("_CUDA", "1"); + } + llvm::Triple targetTriple{llvm::Triple(this->targetOpts.triple)}; if (targetTriple.isOSLinux()) { fortranOptions.predefinitions.emplace_back("__linux__", "1"); diff --git a/flang/lib/Parser/parsing.cpp b/flang/lib/Parser/parsing.cpp index ceea74766d7ea..8a8c6ef673a8c 100644 --- a/flang/lib/Parser/parsing.cpp +++ b/flang/lib/Parser/parsing.cpp @@ -96,9 +96,6 @@ const SourceFile *Parsing::Prescan(const std::string &path, Options options) { prescanner.AddCompilerDirectiveSentinel("$cuf"); prescanner.AddCompilerDirectiveSentinel("@cuf"); } - if (options.features.IsEnabled(LanguageFeature::CUDA)) { - preprocessor_.Define("_CUDA", "1"); - } ProvenanceRange range{allSources.AddIncludedFile( *sourceFile, ProvenanceRange{}, options.isModuleFile)}; prescanner.Prescan(range); diff --git a/flang/test/Parser/cuf-sanity-tree.CUF b/flang/test/Parser/cuf-sanity-tree.CUF index a8b2f93913ca9..83d7540b8dec5 100644 --- a/flang/test/Parser/cuf-sanity-tree.CUF +++ b/flang/test/Parser/cuf-sanity-tree.CUF @@ -1,4 +1,4 @@ -! RUN: %flang_fc1 -fdebug-dump-parse-tree %s 2>&1 | FileCheck %s +! RUN: %flang_fc1 -fdebug-dump-parse-tree -x cuda %s 2>&1 | FileCheck %s include "cuf-sanity-common" !CHECK: Program -> ProgramUnit -> SubroutineSubprogram !CHECK: | SubroutineStmt diff --git a/flang/test/Parser/cuf-sanity-unparse.CUF b/flang/test/Parser/cuf-sanity-unparse.CUF index 2e2df9ac6646a..ede98093c442d 100644 --- a/flang/test/Parser/cuf-sanity-unparse.CUF +++ b/flang/test/Parser/cuf-sanity-unparse.CUF @@ -1,4 +1,4 @@ -! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s +! RUN: %flang_fc1 -fdebug-unparse -x cuda %s 2>&1 | FileCheck %s include "cuf-sanity-common" !CHECK: SUBROUTINE atcuf !CHECK: END SUBROUTINE