Skip to content

Commit 844f018

Browse files
cotizmodem
authored andcommitted
[flang] Version information in flang/f18
Fixed some version information in flang/f18: - fixed the behavior of the -v switch: this flag enables verbosity with used with arguments, but just displays the version when used alone (related to this bug: https://bugs.llvm.org/show_bug.cgi?id=46017) - added __FLANG, __FLANG_MAJOR__, __FLANG_MINOR__ and __FLANG_PATCHLEVEL__ (similar to their __F18* counterparts) for compatibility purpose Reviewed By: sscalpone, AlexisPerry, richard.barton.arm, tskeith Differential Revision: https://reviews.llvm.org/D84334 (cherry picked from commit 89a9db4)
1 parent 6338655 commit 844f018

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

flang/test/Driver/version_test.f90

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
! Check that lit configuration works by checking the compiler version
22

3-
! RUN: %f18 -V 2>&1 | FileCheck -check-prefix=VERSION %s
43
! VERSION-NOT:{{![[:space:]]}}
54
! VERSION:{{[[:space:]]}}
6-
! VERSION-SAME:f18 compiler (under development)
5+
! VERSION-SAME:f18 compiler (under development), version {{[1-9][0-9]*.[0-9]*.[0-9]*}}
76
! VERSION-EMPTY:
7+
8+
! RUN: %f18 -V 2>&1 | FileCheck -check-prefix=VERSION %s
9+
! RUN: %f18 -v 2>&1 | FileCheck -check-prefix=VERSION %s
10+
! RUN: %f18 --version 2>&1 | FileCheck -check-prefix=VERSION %s
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
! Check that the macros that give the verion number are set properly
2+
3+
!CHECK: flang_major = {{[1-9][0-9]*$}}
4+
!CHECK: flang_minor = {{[0-9]+$}}
5+
!CHECK: flang_patchlevel = {{[0-9]+$}}
6+
!RUN: %f18 -E %s | FileCheck --ignore-case %s
7+
8+
9+
integer, parameter :: flang_major = __flang_major__
10+
integer, parameter :: flang_minor = __flang_minor__
11+
integer, parameter :: flang_patchlevel = __flang_patchlevel__
12+

flang/tools/f18/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ file(COPY ${CMAKE_BINARY_DIR}/tools/flang/bin/flang DESTINATION ${CMAKE_BINARY_D
6464
# The flang script to be installed needs a different path to the headers.
6565
set(FLANG_INTRINSIC_MODULES_DIR ${CMAKE_INSTALL_PREFIX}/include/flang)
6666
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flang.sh.in ${FLANG_BINARY_DIR}/bin/flang-install.sh @ONLY)
67+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/f18_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/f18_version.h @ONLY)
6768

6869
install(PROGRAMS ${FLANG_BINARY_DIR}/bin/flang-install.sh DESTINATION bin RENAME flang PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE)

flang/tools/f18/f18.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include <unistd.h>
3939
#include <vector>
4040

41+
#include "f18_version.h"
42+
4143
static std::list<std::string> argList(int argc, char *const argv[]) {
4244
std::list<std::string> result;
4345
for (int j = 0; j < argc; ++j) {
@@ -390,6 +392,13 @@ void Link(std::vector<std::string> &liblist, std::vector<std::string> &objects,
390392
}
391393
}
392394

395+
int printVersion() {
396+
llvm::errs() << "\nf18 compiler (under development), version "
397+
<< __FLANG_MAJOR__ << "." << __FLANG_MINOR__ << "."
398+
<< __FLANG_PATCHLEVEL__ << "\n";
399+
return exitStatus;
400+
}
401+
393402
int main(int argc, char *const argv[]) {
394403

395404
atexit(CleanUpAtExit);
@@ -411,6 +420,11 @@ int main(int argc, char *const argv[]) {
411420
options.predefinitions.emplace_back("__F18_MAJOR__", "1");
412421
options.predefinitions.emplace_back("__F18_MINOR__", "1");
413422
options.predefinitions.emplace_back("__F18_PATCHLEVEL__", "1");
423+
options.predefinitions.emplace_back("__flang__", __FLANG__);
424+
options.predefinitions.emplace_back("__flang_major__", __FLANG_MAJOR__);
425+
options.predefinitions.emplace_back("__flang_minor__", __FLANG_MINOR__);
426+
options.predefinitions.emplace_back(
427+
"__flang_patchlevel__", __FLANG_PATCHLEVEL__);
414428
#if __x86_64__
415429
options.predefinitions.emplace_back("__x86_64__", "1");
416430
#endif
@@ -651,13 +665,16 @@ int main(int argc, char *const argv[]) {
651665
<< "Unrecognised options are passed through to the external compiler\n"
652666
<< "set by F18_FC (see defaults).\n";
653667
return exitStatus;
654-
} else if (arg == "-V") {
655-
llvm::errs() << "\nf18 compiler (under development)\n";
656-
return exitStatus;
668+
} else if (arg == "-V" || arg == "--version") {
669+
return printVersion();
657670
} else {
658671
driver.F18_FCArgs.push_back(arg);
659672
if (arg == "-v") {
660-
driver.verbose = true;
673+
if (args.size() > 1) {
674+
driver.verbose = true;
675+
} else {
676+
return printVersion();
677+
}
661678
} else if (arg == "-I") {
662679
driver.F18_FCArgs.push_back(args.front());
663680
driver.searchDirectories.push_back(args.front());

flang/tools/f18/f18_version.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef _F18_H_
2+
#define _F18_H_
3+
4+
#define __FLANG__ "1"
5+
#define __FLANG_MAJOR__ "@LLVM_VERSION_MAJOR@"
6+
#define __FLANG_MINOR__ "@LLVM_VERSION_MINOR@"
7+
#define __FLANG_PATCHLEVEL__ "@LLVM_VERSION_PATCH@"
8+
9+
#endif // _F18_H_

0 commit comments

Comments
 (0)