[PATCH] D94516: [flang][driver] Add standard predefinitions
Faris via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 18 03:46:22 PST 2021
FarisRehman updated this revision to Diff 317321.
FarisRehman marked 3 inline comments as done.
FarisRehman added a comment.
Remove target-specific predefinition
Remove a target-specific predefinition (__x86_64__), addressing review comments by @awarzynski and @sameeranjoshi
Summary of changes:
- Remove predefinition __x86_64__
- Add __flang__ to predefinitions regression test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D94516/new/
https://reviews.llvm.org/D94516
Files:
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Flang-Driver/compiler-defined-macros.f90
Index: flang/test/Flang-Driver/compiler-defined-macros.f90
===================================================================
--- /dev/null
+++ flang/test/Flang-Driver/compiler-defined-macros.f90
@@ -0,0 +1,26 @@
+! Check that the driver supports the standard predefinitions that f18 does.
+
+! REQUIRES: new-flang-driver
+
+!--------------------------
+! FLANG DRIVER (flang-new)
+!--------------------------
+! RUN: %flang-new -E %s 2>&1 | FileCheck %s --ignore-case
+
+!-----------------------------------------
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-----------------------------------------
+! RUN: %flang-new -fc1 -E %s 2>&1 | FileCheck %s --ignore-case
+
+!-----------------
+! EXPECTED OUTPUT
+!-----------------
+! CHECK: flang = 1
+! CHECK: flang_major = {{[1-9][0-9]*$}}
+! CHECK: flang_minor = {{[0-9]+$}}
+! CHECK: flang_patchlevel = {{[0-9]+$}}
+
+integer, parameter :: flang = __flang__
+integer, parameter :: flang_major = __flang_major__
+integer, parameter :: flang_minor = __flang_minor__
+integer, parameter :: flang_patchlevel = __flang_patchlevel__
Index: flang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -8,6 +8,7 @@
#include "flang/Frontend/CompilerInvocation.h"
#include "flang/Frontend/PreprocessorOptions.h"
+#include "flang/Version.inc"
#include "clang/Basic/AllDiagnostics.h"
#include "clang/Basic/DiagnosticDriver.h"
#include "clang/Basic/DiagnosticOptions.h"
@@ -258,6 +259,18 @@
std::vector<std::string> searchDirectories{"."s};
fortranOptions.searchDirectories = searchDirectories;
fortranOptions.isFixedForm = false;
+
+ // Populate the macro list with version numbers and other predefinitions.
+ // TODO: When expanding this list of standard predefinitions, consider
+ // creating a dedicated API for this. Also at some point we will need to
+ // differentiate between different targets.
+ fortranOptions.predefinitions.emplace_back("__flang__", "1");
+ fortranOptions.predefinitions.emplace_back(
+ "__flang_major__", FLANG_VERSION_MAJOR_STRING);
+ fortranOptions.predefinitions.emplace_back(
+ "__flang_minor__", FLANG_VERSION_MINOR_STRING);
+ fortranOptions.predefinitions.emplace_back(
+ "__flang_patchlevel__", FLANG_VERSION_PATCHLEVEL_STRING);
}
void CompilerInvocation::setFortranOpts() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94516.317321.patch
Type: text/x-patch
Size: 2438 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210118/c4283343/attachment.bin>
More information about the llvm-commits
mailing list