Skip to content

Commit

Permalink
Fix test failures when in classic Flang mode
Browse files Browse the repository at this point in the history
Add a new lit feature tag "classic_flang" to select which tests can or cannot be
run when the driver is built for classic Flang. Handle LLVM_ENABLE_CLASSIC_FLANG
in llvm/cmake/modules/HandleLLVMOptions.cmake instead of clang/CMakeLists.txt so
that macro works in both clang and llvm.
  • Loading branch information
bryanpkc committed Nov 22, 2021
1 parent 8403c83 commit 486741e
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clang/test/Driver/autocomplete.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
// FVECLIBALL-NEXT: libmvec
// FVECLIBALL-NEXT: MASSV
// FVECLIBALL-NEXT: none
// FVECLIBALL-NEXT: SVML
// FVECLIBALL: SVML
// RUN: %clang --autocomplete=-fshow-overloads= | FileCheck %s -check-prefix=FSOVERALL
// FSOVERALL: all
// FSOVERALL-NEXT: best
Expand Down
28 changes: 28 additions & 0 deletions clang/test/Driver/flang/classic_flang.f95
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
! Check that the driver can invoke flang1 and flang2 to compile Fortran with
! --driver-mode=flang (default when the file extension is .f95).

! REQUIRES: classic_flang

! RUN: %clang -target x86_64-unknown-linux-gnu -integrated-as -c %s -### 2>&1 \
! RUN: | FileCheck --check-prefix=CHECK-OBJECT %s
! CHECK-OBJECT: flang1
! CHECK-OBJECT: flang2
! CHECK-OBJECT-SAME: "-asm" [[LLFILE:.*.ll]]
! CHECK-OBJECT-NOT: cc1as
! CHECK-OBJECT: clang
! CHECK-OBJECT-SAME: -cc1
! CHECK-OBJECT-SAME: "-o" "classic_flang.o"
! CHECK-OBJECT-SAME: "-x" "ir"
! CHECK-OBJECT-SAME: [[LLFILE]]

! RUN: %clang -target x86_64-unknown-linux-gnu -integrated-as -S %s -### 2>&1 \
! RUN: | FileCheck --check-prefix=CHECK-ASM %s
! CHECK-ASM: flang1
! CHECK-ASM: flang2
! CHECK-ASM-SAME: "-asm" [[LLFILE:.*.ll]]
! CHECK-ASM-NOT: cc1as
! CHECK-ASM: clang
! CHECK-ASM-SAME: -cc1
! CHECK-ASM-SAME: "-o" "classic_flang.s"
! CHECK-ASM-SAME: "-x" "ir"
! CHECK-ASM-SAME: [[LLFILE]]
2 changes: 2 additions & 0 deletions clang/test/Driver/flang/flang.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
! Check that flang -fc1 is invoked when in --driver-mode=flang.

! UNSUPPORTED: classic_flang

! This is a copy of flang_ucase.F90 because the driver has logic in it which
! differentiates between F90 and f90 files. Flang will not treat these files
! differently.
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/flang/flang_ucase.F90
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
! Check that flang -fc1 is invoked when in --driver-mode=flang.

! UNSUPPORTED: classic_flang

! This is a copy of flang.f90 because the driver has logic in it which
! differentiates between F90 and f90 files. Flang will not treat these files
! differently.
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/flang/multiple-inputs-mixed.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
! Check that flang can handle mixed C and fortran inputs.

! UNSUPPORTED: classic_flang

! RUN: %clang --driver-mode=flang -### -fsyntax-only %S/Inputs/one.f90 %S/Inputs/other.c 2>&1 | FileCheck --check-prefixes=CHECK-SYNTAX-ONLY %s
! CHECK-SYNTAX-ONLY-LABEL: "{{[^"]*}}flang-new{{[^"/]*}}" "-fc1"
! CHECK-SYNTAX-ONLY: "{{[^"]*}}/Inputs/one.f90"
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/flang/multiple-inputs.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
! Check that flang driver can handle multiple inputs at once.

! UNSUPPORTED: classic_flang

! RUN: %clang --driver-mode=flang -### -fsyntax-only %S/Inputs/one.f90 %S/Inputs/two.f90 2>&1 | FileCheck --check-prefixes=CHECK-SYNTAX-ONLY %s
! CHECK-SYNTAX-ONLY-LABEL: "{{[^"]*}}flang-new" "-fc1"
! CHECK-SYNTAX-ONLY: "{{[^"]*}}/Inputs/one.f90"
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/fortran.f95
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
! Check that the clang driver can invoke gcc to compile Fortran when in
! --driver-mode=clang. This is legacy behaviour - see also --driver-mode=flang.

! UNSUPPORTED: classic_flang

! RUN: %clang -target x86_64-unknown-linux-gnu -integrated-as -c %s -### 2>&1 \
! RUN: | FileCheck --check-prefix=CHECK-OBJECT %s
! CHECK-OBJECT: gcc
Expand Down
4 changes: 3 additions & 1 deletion clang/test/Driver/gfortran.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
! Test that Clang can forward all of the flags which are documented as
! being supported by gfortran to GCC when falling back to GCC for
! a fortran input file.
!

! UNSUPPORTED: classic_flang

! RUN: %clang -no-canonical-prefixes -target i386-linux -### %s -o %t 2>&1 \
! RUN: -Aquestion=answer \
! RUN: -A-question=answer \
Expand Down
4 changes: 4 additions & 0 deletions clang/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,7 @@ def calculate_arch_features(arch_string):
# Add a vendor-specific feature.
if config.clang_vendor_uti:
config.available_features.add('clang-vendor=' + config.clang_vendor_uti)

if config.use_classic_flang:
config.available_features.add("classic_flang")

1 change: 1 addition & 0 deletions clang/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ config.use_z3_solver = lit_config.params.get('USE_Z3_SOLVER', "@USE_Z3_SOLVER@")
config.has_plugins = @LLVM_ENABLE_PLUGINS@
config.clang_vendor_uti = "@CLANG_VENDOR_UTI@"
config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
config.use_classic_flang = @LLVM_ENABLE_CLASSIC_FLANG@

# Support substitution of the tools and libs dirs with user parameters. This is
# used when we can't determine the tool dir at configuration time.
Expand Down
8 changes: 8 additions & 0 deletions llvm/cmake/modules/HandleLLVMOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ if( LLVM_ENABLE_ASSERTIONS )
endif()
endif()

option(LLVM_ENABLE_CLASSIC_FLANG "Build support for classic Flang instead of the new built-in Flang" OFF)
if(LLVM_ENABLE_CLASSIC_FLANG)
set(LLVM_ENABLE_CLASSIC_FLANG 1)
add_definitions( -DENABLE_CLASSIC_FLANG )
else()
set(LLVM_ENABLE_CLASSIC_FLANG 0)
endif()

if(LLVM_ENABLE_EXPENSIVE_CHECKS)
add_definitions(-DEXPENSIVE_CHECKS)

Expand Down
16 changes: 16 additions & 0 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4955,6 +4955,7 @@ bool LLParser::parseDITemplateValueParameter(MDNode *&Result, bool IsDistinct) {
/// isDefinition: true, templateParams: !3,
/// declaration: !4, align: 8)
bool LLParser::parseDIGlobalVariable(MDNode *&Result, bool IsDistinct) {
#ifdef ENABLE_CLASSIC_FLANG
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
OPTIONAL(name, MDStringField, (/* AllowEmpty */ true)); \
OPTIONAL(scope, MDField, ); \
Expand All @@ -4968,6 +4969,21 @@ bool LLParser::parseDIGlobalVariable(MDNode *&Result, bool IsDistinct) {
OPTIONAL(declaration, MDField, ); \
OPTIONAL(flags, DIFlagField, ); \
OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX));
#else
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
REQUIRED(name, MDStringField, (/* AllowEmpty */ false)); \
OPTIONAL(scope, MDField, ); \
OPTIONAL(linkageName, MDStringField, ); \
OPTIONAL(file, MDField, ); \
OPTIONAL(line, LineField, ); \
OPTIONAL(type, MDField, ); \
OPTIONAL(isLocal, MDBoolField, ); \
OPTIONAL(isDefinition, MDBoolField, (true)); \
OPTIONAL(templateParams, MDField, ); \
OPTIONAL(declaration, MDField, ); \
OPTIONAL(flags, DIFlagField, ); \
OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX));
#endif
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS

Expand Down
1 change: 1 addition & 0 deletions llvm/test/Assembler/invalid-diglobalvariable-empty-name.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
; UNSUPPORTED: classic_flang

; CHECK: <stdin>:[[@LINE+1]]:30: error: 'name' cannot be empty
!0 = !DIGlobalVariable(name: "")
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
; UNSUPPORTED: classic_flang

; CHECK: <stdin>:[[@LINE+1]]:24: error: missing required field 'name'
!0 = !DIGlobalVariable()
3 changes: 3 additions & 0 deletions llvm/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,6 @@ def have_ld64_plugin_support():

if config.expensive_checks:
config.available_features.add('expensive_checks')

if config.use_classic_flang:
config.available_features.add("classic_flang")
1 change: 1 addition & 0 deletions llvm/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ config.linked_bye_extension = @LLVM_BYE_LINK_INTO_TOOLS@
config.have_tf_aot = @LLVM_HAVE_TF_AOT@
config.have_tf_api = @LLVM_HAVE_TF_API@
config.expensive_checks = @LLVM_ENABLE_EXPENSIVE_CHECKS@
config.use_classic_flang = @LLVM_ENABLE_CLASSIC_FLANG@

# Support substitution of the tools_dir with user parameters. This is
# used when we can't determine the tool dir at configuration time.
Expand Down

0 comments on commit 486741e

Please sign in to comment.