├── .gitignore
├── CMakeLists.txt
├── LICENSE.TXT
├── PULL_REQUEST_TEMPLATE.md
├── README.txt
├── docs
├── CMakeLists.txt
├── CommandGuide
│ ├── fort.rst
│ └── index.rst
├── ReleaseNotes.rst
├── conf.py
├── doxygen-mainpage.dox
├── doxygen.cfg.in
└── index.rst
├── include
├── CMakeLists.txt
└── fort
│ ├── AST
│ ├── ASTConsumer.h
│ ├── ASTContext.h
│ ├── BuiltinTypeKinds.def
│ ├── CMakeLists.txt
│ ├── Decl.h
│ ├── DeclContextInternals.h
│ ├── DeclGroup.h
│ ├── DeclVisitor.h
│ ├── DeclarationName.h
│ ├── Expr.h
│ ├── ExprConstant.h
│ ├── ExprVisitor.h
│ ├── FormatItem.h
│ ├── FormatSpec.h
│ ├── IOSpec.h
│ ├── IntrinsicFunctions.def
│ ├── IntrinsicFunctions.h
│ ├── Rename.h
│ ├── Stmt.h
│ ├── StmtVisitor.h
│ ├── StorageSet.h
│ ├── Type.h
│ ├── TypeNodes.def
│ └── TypeVisitor.h
│ ├── Basic
│ ├── AllDiagnostics.h
│ ├── CMakeLists.txt
│ ├── CharInfo.h
│ ├── DeclNodes.td
│ ├── Diagnostic.h
│ ├── Diagnostic.td
│ ├── DiagnosticCommonKinds.td
│ ├── DiagnosticDriverKinds.td
│ ├── DiagnosticFrontendKinds.td
│ ├── DiagnosticGroups.td
│ ├── DiagnosticIDs.h
│ ├── DiagnosticLexKinds.td
│ ├── DiagnosticParseKinds.td
│ ├── DiagnosticSemaKinds.td
│ ├── ExprNodes.td
│ ├── IdentifierTable.h
│ ├── LLVM.h
│ ├── LangOptions.h
│ ├── MacroBuilder.h
│ ├── MakePtr.h
│ ├── SourceLocation.h
│ ├── Specifiers.h
│ ├── StmtNodes.td
│ ├── TargetInfo.h
│ ├── TargetOptions.h
│ ├── Token.h
│ ├── TokenKinds.def
│ ├── TokenKinds.h
│ ├── Version.h
│ ├── Version.inc.in
│ └── VersionTuple.h
│ ├── CMakeLists.txt
│ ├── CodeGen
│ ├── BackendUtil.h
│ ├── CodeGenAction.h
│ └── ModuleBuilder.h
│ ├── Config
│ └── config.h.cmake
│ ├── Driver
│ ├── CMakeLists.txt
│ ├── DriverDiagnostic.h
│ ├── Options.h
│ └── Options.td
│ ├── Frontend
│ ├── ASTConsumers.h
│ ├── ASTUnit.h
│ ├── CodeGenOptions.def
│ ├── CodeGenOptions.h
│ ├── CommandLineSourceLoc.h
│ ├── CompilerInstance.h
│ ├── CompilerInvocation.h
│ ├── FrontendAction.h
│ ├── FrontendDiagnostic.h
│ ├── FrontendOptions.h
│ ├── TextDiagnosticBuffer.h
│ ├── TextDiagnosticPrinter.h
│ └── VerifyDiagnosticConsumer.h
│ ├── Parse
│ ├── FixedForm.h
│ ├── LexDiagnostic.h
│ ├── Lexer.h
│ ├── ParseDiagnostic.h
│ └── Parser.h
│ └── Sema
│ ├── DeclSpec.h
│ ├── Ownership.h
│ ├── Scope.h
│ ├── Sema.h
│ ├── SemaDiagnostic.h
│ └── SemaInternal.h
├── lib
├── AST
│ ├── ASTContext.cpp
│ ├── ASTDumper.cpp
│ ├── CMakeLists.txt
│ ├── Decl.cpp
│ ├── DeclGroup.cpp
│ ├── DeclarationName.cpp
│ ├── Expr.cpp
│ ├── ExprArray.cpp
│ ├── ExprConstant.cpp
│ ├── FormatItem.cpp
│ ├── FormatSpec.cpp
│ ├── IOSpec.cpp
│ ├── IntrinsicFunctions.cpp
│ ├── Stmt.cpp
│ └── Type.cpp
├── Basic
│ ├── CMakeLists.txt
│ ├── CharInfo.cpp
│ ├── Diagnostic.cpp
│ ├── DiagnosticIDs.cpp
│ ├── IdentifierTable.cpp
│ ├── TargetInfo.cpp
│ ├── Targets.cpp
│ ├── Token.cpp
│ ├── TokenKinds.cpp
│ └── Version.cpp
├── CMakeLists.txt
├── CodeGen
│ ├── ABIInfo.h
│ ├── BackendUtil.cpp
│ ├── CGABI.cpp
│ ├── CGABI.h
│ ├── CGArray.cpp
│ ├── CGArray.h
│ ├── CGArrayIntrinsic.cpp
│ ├── CGBuilder.h
│ ├── CGCall.cpp
│ ├── CGCall.h
│ ├── CGDecl.cpp
│ ├── CGExpr.cpp
│ ├── CGExprAgg.cpp
│ ├── CGExprCharacter.cpp
│ ├── CGExprComplex.cpp
│ ├── CGExprScalar.cpp
│ ├── CGIOLibfort.cpp
│ ├── CGIORuntime.cpp
│ ├── CGIORuntime.h
│ ├── CGIntrinsic.cpp
│ ├── CGStmt.cpp
│ ├── CGSystemLibfort.cpp
│ ├── CGSystemRuntime.cpp
│ ├── CGSystemRuntime.h
│ ├── CGValue.h
│ ├── CMakeLists.txt
│ ├── CodeGenAction.cpp
│ ├── CodeGenFunction.cpp
│ ├── CodeGenFunction.h
│ ├── CodeGenModule.cpp
│ ├── CodeGenModule.h
│ ├── CodeGenTypes.cpp
│ ├── CodeGenTypes.h
│ ├── ModuleBuilder.cpp
│ ├── TargetInfo.cpp
│ └── TargetInfo.h
├── Driver
│ ├── CMakeLists.txt
│ └── DriverOptions.cpp
├── Frontend
│ ├── ASTConsumers.cpp
│ ├── CMakeLists.txt
│ ├── TextDiagnosticBuffer.cpp
│ ├── TextDiagnosticPrinter.cpp
│ └── VerifyDiagnosticConsumer.cpp
├── Parse
│ ├── CMakeLists.txt
│ ├── FixedForm.cpp
│ ├── Lexer.cpp
│ ├── ParseDecl.cpp
│ ├── ParseExec.cpp
│ ├── ParseExpr.cpp
│ ├── ParseFormat.cpp
│ ├── ParseSpecStmt.cpp
│ └── Parser.cpp
└── Sema
│ ├── CMakeLists.txt
│ ├── DeclSpec.cpp
│ ├── Scope.cpp
│ ├── Sema.cpp
│ ├── SemaArrayExpr.cpp
│ ├── SemaChecking.cpp
│ ├── SemaDataStmt.cpp
│ ├── SemaDecl.cpp
│ ├── SemaEquivalence.cpp
│ ├── SemaExecStmt.cpp
│ ├── SemaExpr.cpp
│ ├── SemaFormat.cpp
│ ├── SemaIO.cpp
│ ├── SemaIntrinsic.cpp
│ └── Spec.cpp
├── test
├── CMakeLists.txt
├── CodeGen
│ ├── Intrinsics
│ │ ├── bitops.f95
│ │ ├── inquiry.f95
│ │ └── maxminloc.f95
│ ├── array.f95
│ ├── arrayArgument.f95
│ ├── arrayAssignment.f95
│ ├── arrayConstructor.f95
│ ├── arrayOperations.f95
│ ├── arrayTempAndPacking.f95
│ ├── callableArguments.f95
│ ├── character.f95
│ ├── characterIntrinsic.f95
│ ├── common.f95
│ ├── complexArithmetic.f95
│ ├── complexIntrinsic.f95
│ ├── complexIntrinsicMath.f95
│ ├── computedGoto.f95
│ ├── core.f95
│ ├── data.f95
│ ├── defaultDouble8.f95
│ ├── defaultInt8.f95
│ ├── defaultReal8.f95
│ ├── do.f95
│ ├── dowhile.f95
│ ├── equivalence.f95
│ ├── exitCycle.f95
│ ├── goto.f95
│ ├── if.f95
│ ├── implicitConversion.f95
│ ├── init.f95
│ ├── intrinsicConversion.f95
│ ├── mainProgram.f95
│ ├── memory.f95
│ ├── module.f95
│ ├── save.f95
│ ├── scalarArithmetic.f95
│ ├── scalarIntrinsicMath.f95
│ ├── scalarIntrinsicTruncRound.f95
│ ├── scalarLogical.f95
│ ├── selectcase.f95
│ ├── statementFunctions.f95
│ ├── subprogram.f95
│ ├── systemIntrinsics.f95
│ ├── type.f95
│ ├── unformattedWrite.f95
│ ├── use.f95
│ ├── valueAssignment.f95
│ ├── where.f95
│ ├── x86LinuxAggregateABI.f95
│ └── x86_64LinuxAggregateABI.f95
├── Driver
│ ├── args.f95
│ └── lineLength.f95
├── Lexer
│ ├── constants.f95
│ ├── continuation.f95
│ ├── definedOperator.f95
│ ├── fixedForm.f
│ ├── fixedForm2.f
│ ├── fixedFormDefinedOperators.f
│ ├── fixedFormSquash.f
│ ├── fixedFormString.f
│ ├── include.f95
│ ├── includeFail.f95
│ ├── includedFile.inc
│ ├── numberConstants.f95
│ └── torture.f95
├── Parser
│ ├── array.f95
│ ├── arrayConstructor.f95
│ ├── assignedGoto.f
│ ├── assignedGoto.f95
│ ├── assignedGotoImplicitDecl.f95
│ ├── call.f95
│ ├── characterSubstring.f95
│ ├── common.f95
│ ├── complexConstants.f95
│ ├── computedGoto.f95
│ ├── continue.f95
│ ├── data.f95
│ ├── dimension.f95
│ ├── do.f95
│ ├── doImplicitDecl.f95
│ ├── doRecovery.f95
│ ├── double.f95
│ ├── dynamicAssociation.f95
│ ├── empty.f95
│ ├── end.f
│ ├── equivalence.f95
│ ├── exitCycle.f95
│ ├── expressions.f95
│ ├── external.f95
│ ├── fixedForm.f95
│ ├── fixedFormDo.f
│ ├── fixedFormExitCycle.f
│ ├── fixedFormFunction.f
│ ├── fixedFormLength.f
│ ├── fixedFormNamedConstructs.f
│ ├── fixedif.f
│ ├── format.f95
│ ├── freeForm.f
│ ├── freeFormLength.f95
│ ├── goto.f95
│ ├── hello_world.f95
│ ├── if.f95
│ ├── ifRecovery.f95
│ ├── implicit.f95
│ ├── implicitFunctions.f95
│ ├── implicitNone.f95
│ ├── intrinsic.f95
│ ├── minimal.f95
│ ├── minimalAmbiguous.f95
│ ├── module.f95
│ ├── namedConstructs.f95
│ ├── parameter.f95
│ ├── program.f95
│ ├── readWritePrint.f95
│ ├── recursive.f
│ ├── recursive.f95
│ ├── result.f
│ ├── result.f95
│ ├── return.f95
│ ├── save.f
│ ├── save.f95
│ ├── selectcase.f95
│ ├── statementFunctions.f95
│ ├── statementTermination.f95
│ ├── stop.f95
│ ├── subprogram.f
│ ├── subprogram.f95
│ ├── type.f95
│ ├── variables.f95
│ └── where.f95
├── Sema
│ ├── Intrinsics
│ │ ├── bitops.f95
│ │ ├── etime.f95
│ │ ├── inquiry.f95
│ │ └── numericInquiry.f95
│ ├── arithmeticExpressions.f95
│ ├── arrayAssignment.f95
│ ├── arrayConstructor.f95
│ ├── arrayIntrinsics.f95
│ ├── arrayOperations.f95
│ ├── arraySections.f95
│ ├── arraySpec.f95
│ ├── arraySubscript.f95
│ ├── assignedGoto.f95
│ ├── assignment.f95
│ ├── beginEndRecovery.f95
│ ├── call.f95
│ ├── callableArguments.f95
│ ├── characterExpressions.f95
│ ├── characterSpec.f95
│ ├── characterSubstring.f95
│ ├── common.f95
│ ├── computedGoto.f95
│ ├── data.f95
│ ├── declarationAttributes.f95
│ ├── dimension.f95
│ ├── do.f95
│ ├── double.f95
│ ├── dowhile.f95
│ ├── dynamicAssociation.f95
│ ├── equivalence.f95
│ ├── exitCycle.f95
│ ├── external.f95
│ ├── format.f95
│ ├── formatSpecifiers.f95
│ ├── goto.f95
│ ├── if.f95
│ ├── immutableDoVars.f95
│ ├── implicit.f95
│ ├── implicitArgumentInArraySpec.f95
│ ├── implicitDefault.f95
│ ├── implicitNone.f95
│ ├── init.f95
│ ├── intrinsic.f95
│ ├── intrinsicArrayOperations.f95
│ ├── intrinsicFunctions.f95
│ ├── logicalExpressions.f95
│ ├── mainProgram.f95
│ ├── namedConstructs.f95
│ ├── parameter.f95
│ ├── readWritePrint.f95
│ ├── recursive.f95
│ ├── relationalExpressions.f95
│ ├── result.f95
│ ├── return.f95
│ ├── returnVarDo.f95
│ ├── save.f95
│ ├── selectcase.f95
│ ├── statementFunctions.f95
│ ├── subprogram.f95
│ ├── type.f95
│ ├── typeKinds.f95
│ ├── use.f95
│ ├── variables.f95
│ └── where.f95
├── TestRunner.sh.in
├── lit.cfg.py
└── lit.site.cfg.py.in
├── tools
├── CMakeLists.txt
└── driver
│ ├── CMakeLists.txt
│ ├── Info.plist.in
│ └── Main.cpp
├── unittests
├── AST
│ ├── CMakeLists.txt
│ └── ExprEvaluator.cpp
└── CMakeLists.txt
└── utils
└── TableGen
├── CMakeLists.txt
├── FortASTNodesEmitter.cpp
├── FortDiagnosticsEmitter.cpp
├── TableGen.cpp
└── TableGenBackends.h
/.gitignore:
--------------------------------------------------------------------------------
1 | #==============================================================================#
2 | # This file specifies intentionally untracked files that git should ignore.
3 | # See: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html
4 | #
5 | # This file is intentionally different from the output of `git svn show-ignore`,
6 | # as most of those are useless.
7 | #==============================================================================#
8 |
9 | #==============================================================================#
10 | # File extensions to be ignored anywhere in the tree.
11 | #==============================================================================#
12 | # Temp files created by most text editors.
13 | *~
14 | # Merge files created by git.
15 | *.orig
16 | # Byte compiled python modules.
17 | *.pyc
18 | # vim swap files
19 | .*.swp
20 |
21 | #==============================================================================#
22 | # Explicit files to ignore (only matches one).
23 | #==============================================================================#
24 | cscope.files
25 | cscope.out
26 |
--------------------------------------------------------------------------------
/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Fixes #
2 |
--------------------------------------------------------------------------------
/docs/CommandGuide/fort.rst:
--------------------------------------------------------------------------------
1 | fort - the Fortran compiler
2 | ===========================
3 |
4 | SYNOPSIS
5 | --------
6 |
7 | :program:`fort` [*options*] *filename ...*
8 |
9 | DESCRIPTION
10 | -----------
11 |
12 | :program:`fort` is a Fortran compiler which encompasses preprocessing, parsing,
13 | optimization, code generation, assembly, and linking.
14 |
15 | BUGS
16 | ----
17 |
18 | To report bugs, please visit .
19 | Most bug reports should include the full output of the compiler, along with
20 | information to reproduce.
21 |
22 |
--------------------------------------------------------------------------------
/docs/CommandGuide/index.rst:
--------------------------------------------------------------------------------
1 | Fort "man" pages
2 | -----------------
3 |
4 | The following documents are command descriptions for all of the Fort tools.
5 | These pages describe how to use the Fort commands and what their options are.
6 | Note that these pages do not describe all of the options available for all
7 | tools. To get a complete listing, pass the ``--help`` (general options) or
8 | ``--help-hidden`` (general and debugging options) arguments to the tool you are
9 | interested in.
10 |
11 | Basic Commands
12 | ~~~~~~~~~~~~~~
13 |
14 | .. toctree::
15 | :maxdepth: 1
16 |
17 | fort
18 |
--------------------------------------------------------------------------------
/docs/ReleaseNotes.rst:
--------------------------------------------------------------------------------
1 | =======================================
2 | Fort 9.0.0 (In-Progress) Release Notes
3 | =======================================
4 |
5 | .. contents::
6 | :local:
7 | :depth: 2
8 |
9 | Written by the `Fort Team `_
10 |
11 | .. warning::
12 |
13 | These are in-progress notes for the upcoming Fort 9 release.
14 |
15 | What's New in Fort 9.0.0?
16 | ==========================
17 |
18 | Major New Features
19 | ------------------
20 |
21 | ...
22 |
23 |
--------------------------------------------------------------------------------
/docs/doxygen-mainpage.dox:
--------------------------------------------------------------------------------
1 | /// \mainpage fort
2 | ///
3 | /// \section main_intro Introduction
4 | /// Welcome to the fort project.
5 | ///
6 | /// This documentation describes the **internal** software that makes
7 | /// up fort, not the **external** use of fort. There are no instructions
8 | /// here on how to use fort, only the APIs that make up the software. For
9 | /// usage instructions, please see the programmer's guide or reference
10 | /// manual.
11 | ///
12 | /// \section main_caveat Caveat
13 | /// This documentation is generated directly from the source code with doxygen.
14 | /// Since fort is constantly under active development, what you're about to
15 | /// read is out of date!
16 |
--------------------------------------------------------------------------------
/docs/index.rst:
--------------------------------------------------------------------------------
1 | .. Fort documentation master file.
2 | You can adapt this file completely to your liking, but it should at least
3 | contain the root `toctree` directive.
4 |
5 | .. title:: Welcome to Fort's documentation!
6 |
7 | .. toctree::
8 | :maxdepth: 1
9 |
10 | ReleaseNotes
11 |
12 | Using Fort as a Compiler
13 | =========================
14 |
15 | .. toctree::
16 | :maxdepth: 1
17 |
18 | CommandGuide/index
19 |
20 | Indices and tables
21 | ==================
22 |
23 | * :ref:`genindex`
24 | * :ref:`modindex`
25 | * :ref:`search`
26 |
27 |
--------------------------------------------------------------------------------
/include/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_subdirectory(fort)
2 |
--------------------------------------------------------------------------------
/include/fort/AST/ASTConsumer.h:
--------------------------------------------------------------------------------
1 | //===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This file defines the ASTConsumer class.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #ifndef LLVM_FORT_AST_ASTCONSUMER_H
15 | #define LLVM_FORT_AST_ASTCONSUMER_H
16 |
17 | namespace fort {
18 | class ASTContext;
19 | class FunctionDecl;
20 |
21 | /// ASTConsumer - This is an abstract interface that should be implemented by
22 | /// clients that read ASTs. This abstraction layer allows the client to be
23 | /// independent of the AST producer (e.g. parser vs AST dump file reader, etc).
24 | class ASTConsumer {
25 | public:
26 | ASTConsumer() {}
27 |
28 | virtual ~ASTConsumer() {}
29 |
30 | /// Initialize - This is called to initialize the consumer, providing the
31 | /// ASTContext.
32 | virtual void Initialize(ASTContext &Context) {}
33 |
34 | /// HandleTranslationUnit - This method is called when the ASTs for entire
35 | /// translation unit have been parsed.
36 | virtual void HandleTranslationUnit(ASTContext &Ctx) {}
37 |
38 | /// PrintStats - If desired, print any statistics.
39 | virtual void PrintStats() {}
40 | };
41 |
42 | } // end namespace fort.
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/include/fort/AST/BuiltinTypeKinds.def:
--------------------------------------------------------------------------------
1 | //===-- BuiltinTypeKinds.def - Metadata about BuiltinType kinds -*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef INTEGER_KIND
11 | #define INTEGER_KIND(NAME, VALUE)
12 | #endif
13 |
14 | #ifndef FLOATING_POINT_KIND
15 | #define FLOATING_POINT_KIND(NAME, VALUE)
16 | #endif
17 |
18 | INTEGER_KIND(Int1, 1)
19 | INTEGER_KIND(Int2, 2)
20 | INTEGER_KIND(Int4, 4)
21 | INTEGER_KIND(Int8, 8)
22 |
23 | FLOATING_POINT_KIND(Real4, 4)
24 | FLOATING_POINT_KIND(Real8, 8)
25 | FLOATING_POINT_KIND(Real16, 16)
26 |
27 | #undef FLOATING_POINT_KIND
28 | #undef INTEGER_KIND
29 |
--------------------------------------------------------------------------------
/include/fort/AST/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | fort_tablegen(DeclNodes.inc -gen-fort-decl-nodes
2 | SOURCE ../Basic/DeclNodes.td
3 | TARGET FortDeclNodes)
4 |
5 | fort_tablegen(StmtNodes.inc -gen-fort-stmt-nodes
6 | SOURCE ../Basic/StmtNodes.td
7 | TARGET FortStmtNodes)
8 |
9 | fort_tablegen(ExprNodes.inc -gen-fort-expr-nodes
10 | SOURCE ../Basic/ExprNodes.td
11 | TARGET FortExprNodes)
12 |
--------------------------------------------------------------------------------
/include/fort/AST/ExprConstant.h:
--------------------------------------------------------------------------------
1 | //===--- ExprConstant.h - Expression Constant Evaluator -------------------===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef FORT_AST_EXPR_CONSTANT_H
11 | #define FORT_AST_EXPR_CONSTANT_H
12 |
13 | #include "fort/Basic/LLVM.h"
14 | #include "llvm/ADT/DenseMap.h"
15 |
16 | namespace fort {
17 |
18 | class Expr;
19 | class VarDecl;
20 | class ASTContext;
21 |
22 | /// ExprEvalScope - represents a scope which can be used
23 | /// to associate variables with values when evaluating expressions.
24 | class ExprEvalScope {
25 | llvm::SmallDenseMap InlinedVars;
26 |
27 | public:
28 | ExprEvalScope() {}
29 |
30 | std::pair get(const Expr *E) const;
31 | void Assign(const VarDecl *Var, int64_t Value);
32 | };
33 |
34 | } // namespace fort
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/include/fort/AST/Rename.h:
--------------------------------------------------------------------------------
1 | //===-- Rename.h - Renamed Objects ------------------------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | //
11 | //===----------------------------------------------------------------------===//
12 |
13 | #ifndef FORT_AST_RENAME_H__
14 | #define FORT_AST_RENAME_H__
15 |
16 | #include "llvm/ADT/StringRef.h"
17 | #include "llvm/Support/raw_stream.h"
18 |
19 | namespace fort {
20 |
21 | //===----------------------------------------------------------------------===//
22 | /// Rename - Used in a 'USE' statement to rename a module name to a local name.
23 | ///
24 | class Rename {
25 | llvm::StringRef LocalName;
26 | llvm::StringRef UseName;
27 |
28 | public:
29 | Rename(llvm::StringRef LN, llvm::StringRef UN) : LocalName(LN), UseName(UN) {}
30 |
31 | friend llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const Rename &RN) {
32 | return O << RN.LocalName << " => " << RN.UseName;
33 | }
34 | };
35 |
36 | } // namespace fort
37 |
38 | #endif // FORT_AST_RENAME_H__
39 |
--------------------------------------------------------------------------------
/include/fort/AST/TypeNodes.def:
--------------------------------------------------------------------------------
1 | //===-- TypeNodes.def - Metadata about Type AST nodes -----------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef TYPE
11 | #define TYPE(Name, Parent)
12 | #endif
13 |
14 | #ifndef BUILTIN_TYPE
15 | #define BUILTIN_TYPE(Name)
16 | #endif
17 |
18 | TYPE(Void, Type)
19 | TYPE(Builtin, Type)
20 | BUILTIN_TYPE(Integer)
21 | BUILTIN_TYPE(Real)
22 | BUILTIN_TYPE(Complex)
23 | BUILTIN_TYPE(Logical)
24 | TYPE(Character, Type)
25 | TYPE(Record, Type)
26 | TYPE(Pointer, Type)
27 | TYPE(Array, Type)
28 | TYPE(Function, Type)
29 |
30 | #ifdef LAST_TYPE
31 | LAST_TYPE(Array)
32 | #undef LAST_TYPE
33 | #endif
34 |
35 | #undef BUILTIN_TYPE
36 | #undef TYPE
37 |
--------------------------------------------------------------------------------
/include/fort/Basic/AllDiagnostics.h:
--------------------------------------------------------------------------------
1 | //===--- AllDiagnostics.h - Aggregate Diagnostic headers --------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | ///
10 | /// \file
11 | /// \brief Includes all the separate Diagnostic headers & some related helpers.
12 | ///
13 | //===----------------------------------------------------------------------===//
14 |
15 | #ifndef LLVM_FORT_ALL_DIAGNOSTICS_H
16 | #define LLVM_FORT_ALL_DIAGNOSTICS_H
17 |
18 | #include "fort/Driver/DriverDiagnostic.h"
19 | #include "fort/Frontend/FrontendDiagnostic.h"
20 | #include "fort/Parse/LexDiagnostic.h"
21 | #include "fort/Parse/ParseDiagnostic.h"
22 | #include "fort/Sema/SemaDiagnostic.h"
23 |
24 | namespace fort {
25 | template class StringSizerHelper {
26 | char FIELD_TOO_SMALL[SizeOfStr <= FieldType(~0U) ? 1 : -1];
27 |
28 | public:
29 | enum { Size = SizeOfStr };
30 | };
31 | } // end namespace fort
32 |
33 | #define STR_SIZE(str, fieldTy) \
34 | fort::StringSizerHelper::Size
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/include/fort/Basic/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | macro(fort_diag_gen component)
2 | fort_tablegen(Diagnostic${component}Kinds.inc
3 | -gen-fort-diags-defs -fort-component=${component}
4 | SOURCE Diagnostic.td
5 | TARGET FortDiagnostic${component})
6 | endmacro(fort_diag_gen)
7 |
8 |
9 | fort_diag_gen(Common)
10 | fort_diag_gen(Lex)
11 | fort_diag_gen(Parse)
12 | fort_diag_gen(Driver)
13 | fort_diag_gen(Frontend)
14 | fort_diag_gen(Sema)
15 | fort_tablegen(DiagnosticGroups.inc -gen-fort-diag-groups
16 | SOURCE Diagnostic.td
17 | TARGET FortDiagnosticGroups)
18 |
--------------------------------------------------------------------------------
/include/fort/Basic/DeclNodes.td:
--------------------------------------------------------------------------------
1 | //===-- DeclNodes.td - Declaration Nodes -------------------*- tablegen -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // Fortran declaration nodes.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | class AttrSubject;
15 |
16 | class Decl : AttrSubject {
17 | bit Abstract = abstract;
18 | }
19 |
20 | class DDecl : Decl {
21 | Decl Base = base;
22 | }
23 |
24 | class DeclContext { }
25 |
26 | def TranslationUnit : Decl, DeclContext;
27 | def Named : Decl<1>;
28 | def Type : DDecl;
29 | def Record : DDecl, DeclContext;
30 | def Value : DDecl;
31 | def EnumConstant : DDecl;
32 | def Declarator : DDecl;
33 | def MainProgram : DDecl, DeclContext;
34 | def Function : DDecl, DeclContext;
35 | def IntrinsicFunction : DDecl;
36 | def Module : DDecl, DeclContext;
37 | def Submodule : DDecl, DeclContext;
38 | def Field : DDecl;
39 | def Var : DDecl;
40 | def Self : DDecl;
41 | def Out : DDecl;
42 | def CommonBlock : DDecl;
43 | def FileScopeAsm : Decl;
44 |
--------------------------------------------------------------------------------
/include/fort/Basic/DiagnosticDriverKinds.td:
--------------------------------------------------------------------------------
1 | //==--- DiagnosticDriverKinds.td - driver diagnostics ---------------------===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | let Component = "Driver" in {
11 |
12 | def err_drv_unknown_argument : Error<"unknown argument: '%0'">;
13 | def err_drv_unknown_argument_with_suggestion
14 | : Error<"unknown argument '%0', did you mean '%1'?">;
15 | def err_line_length_value : Error<
16 | "'%0': invalid value '%1',"
17 | " should be a non-negative integer or 'none'">;
18 | def err_line_length_size : Error<
19 | "'%0' option: value '%1' is too big">;
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/include/fort/Basic/ExprNodes.td:
--------------------------------------------------------------------------------
1 | class AttrSubject;
2 |
3 | class Expr : AttrSubject {
4 | bit Abstract = abstract;
5 | }
6 |
7 | class DExpr : Expr {
8 | Expr Base = base;
9 | }
10 |
11 | // Constants
12 | def ConstantExpr : Expr;
13 | def IntegerConstantExpr : DExpr;
14 | def RealConstantExpr : DExpr;
15 | def ComplexConstantExpr : DExpr;
16 | def CharacterConstantExpr : DExpr;
17 | def BOZConstantExpr : DExpr;
18 | def LogicalConstantExpr : DExpr;
19 | def RepeatedConstantExpr : Expr;
20 |
21 | def FunctionRefExpr : Expr;
22 | def VarExpr : Expr;
23 | def UnresolvedIdentifierExpr : Expr;
24 | def UnaryExpr : Expr;
25 | def DefinedUnaryOperatorExpr : DExpr;
26 | def ImplicitCastExpr : Expr;
27 |
28 | def BinaryExpr : Expr;
29 | def DefinedBinaryOperatorExpr : DExpr;
30 |
31 | def DesignatorExpr : Expr<1>;
32 | def MemberExpr : DExpr;
33 | def SubstringExpr : DExpr;
34 | def ArrayElementExpr : DExpr;
35 | def ArraySectionExpr : DExpr;
36 | def AllocExpr : DExpr;
37 | def ImplicitArrayOperationExpr : Expr<1>;
38 | def ImplicitArrayPackExpr : DExpr;
39 | def ImplicitTempArrayExpr : DExpr;
40 |
41 | // Call Expressions
42 | def CallExpr : Expr;
43 | def IntrinsicCallExpr : Expr;
44 |
45 | //Other
46 | def ImpliedDoExpr : Expr;
47 | def ArrayConstructorExpr : Expr; // (/ /)
48 | def TypeConstructorExpr : Expr;
49 | def RangeExpr : Expr; // a : b
50 | def StridedRangeExpr : DExpr;
51 |
--------------------------------------------------------------------------------
/include/fort/Basic/LLVM.h:
--------------------------------------------------------------------------------
1 | //===--- LLVM.h - Import various common LLVM datatypes ----------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This file forward declares and imports various common LLVM datatypes that
11 | // fort wants to use unqualified.
12 | //
13 | //===----------------------------------------------------------------------===//
14 |
15 | #ifndef FORT_BASIC_LLVM_H__
16 | #define FORT_BASIC_LLVM_H__
17 |
18 | // This should be the only #include, force #includes of all the others on
19 | // clients.
20 | #include "llvm/Support/Casting.h"
21 |
22 | namespace llvm {
23 | // ADT's.
24 | class APInt;
25 | class APFloat;
26 | class StringRef;
27 | class Twine;
28 | template class ArrayRef;
29 | template class SmallString;
30 | template class SmallVector;
31 | template class SmallVectorImpl;
32 | template class Optional;
33 |
34 | class raw_ostream;
35 | class raw_pwrite_stream;
36 | // TODO: DenseMap, ...
37 | } // namespace llvm
38 |
39 | namespace fort {
40 | // Casting operators.
41 | using llvm::cast;
42 | using llvm::cast_or_null;
43 | using llvm::dyn_cast;
44 | using llvm::dyn_cast_or_null;
45 | using llvm::isa;
46 |
47 | // ADT's.
48 | using llvm::APFloat;
49 | using llvm::APInt;
50 | using llvm::ArrayRef;
51 | using llvm::SmallString;
52 | using llvm::SmallVector;
53 | using llvm::SmallVectorImpl;
54 | using llvm::StringRef;
55 | using llvm::Twine;
56 |
57 | using llvm::raw_ostream;
58 | using llvm::raw_pwrite_stream;
59 | } // end namespace fort.
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/include/fort/Basic/MacroBuilder.h:
--------------------------------------------------------------------------------
1 | //===--- MacroBuilder.h - CPP Macro building utility ------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | ///
10 | /// \file
11 | /// \brief Defines the fort::MacroBuilder utility class.
12 | ///
13 | //===----------------------------------------------------------------------===//
14 |
15 | #ifndef LLVM_FORT_BASIC_MACROBUILDER_H
16 | #define LLVM_FORT_BASIC_MACROBUILDER_H
17 |
18 | #include "fort/Basic/LLVM.h"
19 | #include "llvm/ADT/Twine.h"
20 | #include "llvm/Support/raw_ostream.h"
21 |
22 | namespace fort {
23 |
24 | class MacroBuilder {
25 | raw_ostream &Out;
26 |
27 | public:
28 | MacroBuilder(raw_ostream &Output) : Out(Output) {}
29 |
30 | /// Append a \#define line for macro of the form "\#define Name Value\n".
31 | void defineMacro(const Twine &Name, const Twine &Value = "1") {
32 | Out << "#define " << Name << ' ' << Value << '\n';
33 | }
34 |
35 | /// Append a \#undef line for Name. Name should be of the form XXX
36 | /// and we emit "\#undef XXX".
37 | void undefineMacro(const Twine &Name) { Out << "#undef " << Name << '\n'; }
38 |
39 | /// Directly append Str and a newline to the underlying buffer.
40 | void append(const Twine &Str) { Out << Str << '\n'; }
41 | };
42 |
43 | } // end namespace fort
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/include/fort/Basic/MakePtr.h:
--------------------------------------------------------------------------------
1 | //===--- MakePtr.h - pointer type templates --------------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This file defines the make_ptr and make_const_ptr templates.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #ifndef LLVM_FORT_BASIC_MAKEPTR_H
15 | #define LLVM_FORT_BASIC_MAKEPTR_H
16 |
17 | namespace fort {
18 |
19 | template struct make_ptr { typedef T *type; };
20 | template struct make_const_ptr { typedef const T *type; };
21 |
22 | } // end namespace fort
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/include/fort/Basic/SourceLocation.h:
--------------------------------------------------------------------------------
1 | //===--- SourceLocation.h - Compact identifier for Source Files -*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This file defines the SourceLocation class.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #ifndef LLVM_FORT_SOURCELOCATION_H
15 | #define LLVM_FORT_SOURCELOCATION_H
16 |
17 | #include "llvm/Support/SMLoc.h"
18 |
19 | namespace fort {
20 |
21 | typedef llvm::SMLoc SourceLocation;
22 | typedef llvm::SMRange SourceRange;
23 |
24 | } // namespace fort
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/include/fort/Basic/Specifiers.h:
--------------------------------------------------------------------------------
1 | //===--- Specifiers.h - Declaration and Type Specifiers ---------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This file defines various enumerations that describe declaration and
11 | // type specifiers.
12 | //
13 | //===----------------------------------------------------------------------===//
14 |
15 | #ifndef FORT_BASIC_SPECIFIERS_H
16 | #define FORT_BASIC_SPECIFIERS_H
17 |
18 | namespace fort {
19 | /// \brief [R404] Specifies the intrinsic type specifier.
20 | enum TypeSpecifierType {
21 | TST_unspecified,
22 | TST_integer,
23 | TST_real,
24 | TST_complex,
25 | TST_character,
26 | TST_logical,
27 | TST_struct
28 | };
29 |
30 | /// \brief [R502] Specifies the attribute specifiers for types.
31 | enum AttributeSpecifier {
32 | AS_unspecified = 0,
33 | AS_allocatable = 1 << 0,
34 | AS_asynchronous = 1 << 1,
35 | AS_codimension = 1 << 2,
36 | AS_contiguous = 1 << 3,
37 | AS_dimension = 1 << 4,
38 | AS_external = 1 << 5,
39 | AS_intrinsic = 1 << 6,
40 | AS_optional = 1 << 7,
41 | AS_parameter = 1 << 8,
42 | AS_pointer = 1 << 9,
43 | AS_protected = 1 << 10,
44 | AS_save = 1 << 11,
45 | AS_target = 1 << 12,
46 | AS_value = 1 << 13,
47 | AS_volatile = 1 << 14
48 | };
49 |
50 | /// \brief [R523] Specifies the intent specifier.
51 | enum IntentSpecifier { IS_unspecified, IS_in, IS_out, IS_inout };
52 |
53 | /// \brief [R507] Access specifier (public, private).
54 | enum AccessSpecifier { AC_unspecified, AC_public, AC_private };
55 |
56 | } // end namespace fort
57 |
58 | #endif // FORT_BASIC_SPECIFIERS_H
59 |
--------------------------------------------------------------------------------
/include/fort/Basic/StmtNodes.td:
--------------------------------------------------------------------------------
1 | class AttrSubject;
2 |
3 | class Stmt : AttrSubject {
4 | bit Abstract = abstract;
5 | }
6 |
7 | class DStmt : Stmt {
8 | Stmt Base = base;
9 | }
10 |
11 | // Statements
12 | def ConstructPartStmt : Stmt;
13 | def DeclStmt : Stmt;
14 | def CompoundStmt : Stmt;
15 | def ProgramStmt : Stmt;
16 | def ModuleStmt : Stmt;
17 | def UseStmt : Stmt;
18 | def ImportStmt : Stmt;
19 | def ImplicitStmt : Stmt;
20 | def DimensionStmt : Stmt;
21 | def FormatStmt : Stmt;
22 | def EntryStmt : Stmt;
23 | def AsynchronousStmt : Stmt;
24 | def ParameterStmt : Stmt;
25 | def ExternalStmt : Stmt;
26 | def IntrinsicStmt : Stmt;
27 | def SaveStmt : Stmt;
28 | def EquivalenceStmt : Stmt;
29 | def DataStmt : Stmt;
30 |
31 | // executable statements
32 | def BlockStmt : Stmt;
33 | def AssignStmt : Stmt;
34 | def AssignedGotoStmt : Stmt;
35 | def GotoStmt : Stmt;
36 | def ComputedGotoStmt : Stmt;
37 | def NamedConstructStmt : Stmt<1>;
38 | def IfStmt : DStmt;
39 | def CFBlockStmt : DStmt;
40 | def DoStmt : DStmt;
41 | def DoWhileStmt : DStmt;
42 | def CycleStmt : Stmt;
43 | def ExitStmt : Stmt;
44 | def SelectCaseStmt : DStmt;
45 | def SelectionCase : DStmt;
46 | def CaseStmt : DStmt;
47 | def DefaultCaseStmt : DStmt;
48 | def WhereStmt : Stmt;
49 | def ContinueStmt : Stmt;
50 | def StopStmt : Stmt;
51 | def ReturnStmt : Stmt;
52 | def CallStmt : Stmt;
53 | def AssignmentStmt : Stmt;
54 | def AllocateStmt : Stmt;
55 | def DeallocateStmt : Stmt;
56 | def PrintStmt : Stmt;
57 | def WriteStmt : Stmt;
58 |
--------------------------------------------------------------------------------
/include/fort/Basic/TargetOptions.h:
--------------------------------------------------------------------------------
1 | //===--- TargetOptions.h ----------------------------------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | ///
10 | /// \file
11 | /// \brief Defines the fort::TargetOptions class.
12 | ///
13 | //===----------------------------------------------------------------------===//
14 |
15 | #ifndef LLVM_FORT_FRONTEND_TARGETOPTIONS_H
16 | #define LLVM_FORT_FRONTEND_TARGETOPTIONS_H
17 |
18 | #include "fort/Basic/LLVM.h"
19 | #include "llvm/ADT/IntrusiveRefCntPtr.h"
20 | #include "llvm/Target/TargetOptions.h"
21 | #include
22 | #include
23 |
24 | namespace fort {
25 |
26 | /// \brief Options for controlling the target.
27 | class TargetOptions : public llvm::RefCountedBase {
28 | public:
29 | /// If given, the name of the target triple to compile for. If not given the
30 | /// target will be selected to match the host.
31 | std::string Triple;
32 |
33 | /// If given, the name of the target CPU to generate code for.
34 | std::string CPU;
35 |
36 | /// If given, the unit to use for floating point math
37 | std::string FPMath;
38 |
39 | /// If given, the name of the target ABI to use.
40 | std::string ABI;
41 |
42 | /// The EABI version to use
43 | llvm::EABI EABIVersion;
44 |
45 | /// If given, the version string of the linker in use.
46 | std::string LinkerVersion;
47 |
48 | /// \brief The list of target specific features to enable or disable, as
49 | /// written on the command line.
50 | std::vector FeaturesAsWritten;
51 |
52 | /// The list of target specific features to enable or disable -- this should
53 | /// be a list of strings starting with by '+' or '-'.
54 | std::vector Features;
55 | };
56 |
57 | } // end namespace fort
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/include/fort/Basic/Version.inc.in:
--------------------------------------------------------------------------------
1 | #define FORT_VERSION @FORT_VERSION@
2 | #define FORT_VERSION_STRING "@FORT_VERSION@"
3 | #define FORT_VERSION_MAJOR @FORT_VERSION_MAJOR@
4 | #define FORT_VERSION_MINOR @FORT_VERSION_MINOR@
5 | #define FORT_VERSION_PATCHLEVEL @FORT_VERSION_PATCHLEVEL@
6 |
--------------------------------------------------------------------------------
/include/fort/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_subdirectory(Basic)
2 | add_subdirectory(Driver)
3 | add_subdirectory(AST)
4 |
5 |
--------------------------------------------------------------------------------
/include/fort/CodeGen/BackendUtil.h:
--------------------------------------------------------------------------------
1 | //===--- BackendUtil.h - LLVM Backend Utilities -----------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef LLVM_FORT_CODEGEN_BACKEND_UTIL_H
11 | #define LLVM_FORT_CODEGEN_BACKEND_UTIL_H
12 |
13 | #include "fort/Basic/LLVM.h"
14 |
15 | namespace llvm {
16 | class Module;
17 | }
18 |
19 | namespace fort {
20 | class DiagnosticsEngine;
21 | class CodeGenOptions;
22 | class TargetOptions;
23 | class LangOptions;
24 |
25 | enum BackendAction {
26 | Backend_EmitAssembly, ///< Emit native assembly files
27 | Backend_EmitBC, ///< Emit LLVM bitcode files
28 | Backend_EmitLL, ///< Emit human-readable LLVM assembly
29 | Backend_EmitNothing, ///< Don't emit anything (benchmarking mode)
30 | Backend_EmitMCNull, ///< Run CodeGen, but don't emit anything
31 | Backend_EmitObj ///< Emit native object files
32 | };
33 |
34 | void EmitBackendOutput(DiagnosticsEngine &Diags, const CodeGenOptions &CGOpts,
35 | const TargetOptions &TOpts, const LangOptions &LOpts,
36 | StringRef TDesc, llvm::Module *M, BackendAction Action,
37 | raw_pwrite_stream *OS);
38 | } // namespace fort
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/include/fort/CodeGen/ModuleBuilder.h:
--------------------------------------------------------------------------------
1 | //===--- CodeGen/ModuleBuilder.h - Build LLVM from ASTs ---------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This file defines the ModuleBuilder interface.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #ifndef LLVM_FORT_CODEGEN_MODULEBUILDER_H
15 | #define LLVM_FORT_CODEGEN_MODULEBUILDER_H
16 |
17 | #include "fort/AST/ASTConsumer.h"
18 | #include "fort/Basic/TargetOptions.h"
19 | #include "fort/Frontend/CodeGenOptions.h"
20 | #include
21 |
22 | namespace llvm {
23 | class LLVMContext;
24 | class Module;
25 | } // namespace llvm
26 |
27 | namespace fort {
28 | class DiagnosticsEngine;
29 | class LangOptions;
30 |
31 | class CodeGenerator : public ASTConsumer {
32 | virtual void anchor();
33 |
34 | public:
35 | virtual llvm::Module *GetModule() = 0;
36 | virtual llvm::Module *ReleaseModule() = 0;
37 | };
38 |
39 | /// CreateLLVMCodeGen - Create a CodeGenerator instance.
40 | /// It is the responsibility of the caller to call delete on
41 | /// the allocated CodeGenerator instance.
42 | CodeGenerator *CreateLLVMCodeGen(DiagnosticsEngine &Diags,
43 | const std::string &ModuleName,
44 | const CodeGenOptions &CGO,
45 | const TargetOptions &TO, llvm::LLVMContext &C);
46 | } // namespace fort
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/include/fort/Config/config.h.cmake:
--------------------------------------------------------------------------------
1 | /* This generated file is for internal use. Do not include it from headers. */
2 |
3 | #ifdef FORT_CONFIG_H
4 | #error config.h can only be included once
5 | #else
6 | #define FORT_CONFIG_H
7 |
8 | /* Bug report URL. */
9 | #define BUG_REPORT_URL "${BUG_REPORT_URL}"
10 |
11 | /* Default linker to use. */
12 | #define FORT_DEFAULT_LINKER "${FORT_DEFAULT_LINKER}"
13 |
14 | /* Default runtime library to use. */
15 | #define FORT_DEFAULT_RTLIB "${FORT_DEFAULT_RTLIB}"
16 |
17 | /* Default OpenMP runtime used by -fopenmp. */
18 | #define FORT_DEFAULT_OPENMP_RUNTIME "${FORT_DEFAULT_OPENMP_RUNTIME}"
19 |
20 | /* Multilib suffix for libdir. */
21 | #define FORT_LIBDIR_SUFFIX "${FORT_LIBDIR_SUFFIX}"
22 |
23 | /* Relative directory for resource files */
24 | #define FORT_RESOURCE_DIR "${FORT_RESOURCE_DIR}"
25 |
26 | /* Default to all compiler invocations for --sysroot=. */
27 | #define DEFAULT_SYSROOT "${DEFAULT_SYSROOT}"
28 |
29 | /* Directory where gcc is installed. */
30 | #define GCC_INSTALL_PREFIX "${GCC_INSTALL_PREFIX}"
31 |
32 | /* Define if we have libxml2 */
33 | #cmakedefine FORT_HAVE_LIBXML ${FORT_HAVE_LIBXML}
34 |
35 | /* Define if we have z3 and want to build it */
36 | #cmakedefine FORT_ANALYZER_WITH_Z3 ${FORT_ANALYZER_WITH_Z3}
37 |
38 | /* Define if we have sys/resource.h (rlimits) */
39 | #cmakedefine FORT_HAVE_RLIMITS ${FORT_HAVE_RLIMITS}
40 |
41 | /* The LLVM product name and version */
42 | #define BACKEND_PACKAGE_STRING "${BACKEND_PACKAGE_STRING}"
43 |
44 | /* Linker version detected at compile time. */
45 | #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}"
46 |
47 | /* pass --build-id to ld */
48 | #cmakedefine ENABLE_LINKER_BUILD_ID
49 |
50 | /* enable x86 relax relocations by default */
51 | #cmakedefine01 ENABLE_X86_RELAX_RELOCATIONS
52 |
53 | /* Enable each functionality of modules */
54 | #cmakedefine FORT_ENABLE_ARCMT
55 | #cmakedefine FORT_ENABLE_OBJC_REWRITER
56 | #cmakedefine FORT_ENABLE_STATIC_ANALYZER
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/include/fort/Driver/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LLVM_TARGET_DEFINITIONS Options.td)
2 | tablegen(LLVM Options.inc -gen-opt-parser-defs)
3 | add_public_tablegen_target(FortDriverOptions)
4 |
--------------------------------------------------------------------------------
/include/fort/Driver/DriverDiagnostic.h:
--------------------------------------------------------------------------------
1 | //===--- DriverDiagnostic.h - Diagnostics for driver ------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef LLVM_FORT_DRIVERDIAGNOSTIC_H
11 | #define LLVM_FORT_DRIVERDIAGNOSTIC_H
12 |
13 | #include "fort/Basic/Diagnostic.h"
14 |
15 | namespace fort {
16 | namespace diag {
17 | enum {
18 | #define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, ACCESS, \
19 | NOWERROR, SHOWINSYSHEADER, CATEGORY) \
20 | ENUM,
21 | #define DRIVERSTART
22 | #include "fort/Basic/DiagnosticDriverKinds.inc"
23 | #undef DIAG
24 | NUM_BUILTIN_DRIVER_DIAGNOSTICS
25 | };
26 | } // end namespace diag
27 | } // end namespace fort
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/include/fort/Driver/Options.h:
--------------------------------------------------------------------------------
1 | //===--- Options.h - Option info & table ------------------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef LLVM_FORT_DRIVER_OPTIONS_H
11 | #define LLVM_FORT_DRIVER_OPTIONS_H
12 |
13 | #include
14 |
15 | namespace llvm {
16 | namespace opt {
17 | class OptTable;
18 | }
19 | } // namespace llvm
20 |
21 | namespace fort {
22 | namespace driver {
23 |
24 | namespace options {
25 | /// Flags specifically for fort options. Must not overlap with
26 | /// llvm::opt::DriverFlag.
27 | enum FortFlags {
28 | DriverOption = (1 << 4),
29 | LinkerInput = (1 << 5),
30 | NoArgumentUnused = (1 << 6),
31 | Unsupported = (1 << 7),
32 | FC1Option = (1 << 10),
33 | FC1AsOption = (1 << 10),
34 | NoDriverOption = (1 << 12),
35 | Ignored = (1 << 13)
36 | };
37 |
38 | enum ID {
39 | OPT_INVALID = 0, // This is not an option ID.
40 | #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
41 | HELPTEXT, METAVAR, VALUES) \
42 | OPT_##ID,
43 | #include "fort/Driver/Options.inc"
44 | LastOption
45 | #undef OPTION
46 | };
47 | } // namespace options
48 |
49 | std::unique_ptr createDriverOptTable();
50 | } // namespace driver
51 | } // namespace fort
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/include/fort/Frontend/ASTConsumers.h:
--------------------------------------------------------------------------------
1 | //===--- ASTConsumers.h - ASTConsumer implementations -----------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // AST Consumers.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #ifndef FORT_FRONTEND_ASTCONSUMERS_H
15 | #define FORT_FRONTEND_ASTCONSUMERS_H
16 |
17 | #include "fort/Basic/LLVM.h"
18 |
19 | namespace llvm {
20 | namespace sys {
21 | class Path;
22 | }
23 | } // namespace llvm
24 |
25 | namespace fort {
26 |
27 | class ASTConsumer;
28 |
29 | // AST dumper: dumps the raw AST in human-readable form to stderr; this is
30 | // intended for debugging.
31 | ASTConsumer *CreateASTDumper(StringRef FilterString);
32 |
33 | } // end namespace fort
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/include/fort/Frontend/FrontendDiagnostic.h:
--------------------------------------------------------------------------------
1 | //===--- DiagnosticFrontend.h - Diagnostics for frontend --------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef LLVM_FORT_FRONTENDDIAGNOSTIC_H
11 | #define LLVM_FORT_FRONTENDDIAGNOSTIC_H
12 |
13 | #include "fort/Basic/Diagnostic.h"
14 |
15 | namespace fort {
16 | namespace diag {
17 | enum {
18 | #define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, ACCESS, \
19 | NOWERROR, SHOWINSYSHEADER, CATEGORY) \
20 | ENUM,
21 | #define FRONTENDSTART
22 | #include "fort/Basic/DiagnosticFrontendKinds.inc"
23 | #undef DIAG
24 | NUM_BUILTIN_FRONTEND_DIAGNOSTICS
25 | };
26 | } // end namespace diag
27 | } // end namespace fort
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/include/fort/Frontend/TextDiagnosticBuffer.h:
--------------------------------------------------------------------------------
1 | //===--- TextDiagnosticBuffer.h - Buffer Text Diagnostics -------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This is a concrete diagnostic client, which buffers the diagnostic messages.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #ifndef LLVM_FORT_FRONTEND_TEXT_DIAGNOSTIC_BUFFER_H_
15 | #define LLVM_FORT_FRONTEND_TEXT_DIAGNOSTIC_BUFFER_H_
16 |
17 | #include "fort/Basic/Diagnostic.h"
18 | #include
19 | #include
20 |
21 | namespace fort {
22 |
23 | class Lexer;
24 |
25 | class TextDiagnosticBuffer : public DiagnosticClient {
26 | public:
27 | typedef std::vector> DiagList;
28 | typedef DiagList::iterator iterator;
29 | typedef DiagList::const_iterator const_iterator;
30 |
31 | private:
32 | DiagList Errors, Warnings, Notes;
33 |
34 | public:
35 | const_iterator err_begin() const { return Errors.begin(); }
36 | const_iterator err_end() const { return Errors.end(); }
37 |
38 | const_iterator warn_begin() const { return Warnings.begin(); }
39 | const_iterator warn_end() const { return Warnings.end(); }
40 |
41 | const_iterator note_begin() const { return Notes.begin(); }
42 | const_iterator note_end() const { return Notes.end(); }
43 |
44 | virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
45 | SourceLocation L, const llvm::Twine &Msg,
46 | llvm::ArrayRef Ranges,
47 | llvm::ArrayRef FixIts);
48 |
49 | /// FlushDiagnostics - Flush the buffered diagnostics to an given
50 | /// diagnostic engine.
51 | void FlushDiagnostics(DiagnosticsEngine &Diags) const;
52 | };
53 |
54 | } // namespace fort
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/include/fort/Frontend/TextDiagnosticPrinter.h:
--------------------------------------------------------------------------------
1 | //===--- TextDiagnosticPrinter.h - Text Diagnostic Client -------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This is a concrete diagnostic client, which prints the diagnostics to
11 | // standard error.
12 | //
13 | //===----------------------------------------------------------------------===//
14 |
15 | #ifndef FORT_FRONTEND_TEXT_DIAGNOSTIC_PRINTER_H_
16 | #define FORT_FRONTEND_TEXT_DIAGNOSTIC_PRINTER_H_
17 |
18 | #include "fort/Basic/Diagnostic.h"
19 |
20 | namespace llvm {
21 | class raw_ostream;
22 | class SourceLocation;
23 | class SourceMgr;
24 | } // end namespace llvm
25 |
26 | namespace fort {
27 |
28 | class LangOptions;
29 |
30 | class TextDiagnosticPrinter : public DiagnosticClient {
31 | llvm::SourceMgr &SrcMgr;
32 |
33 | public:
34 | TextDiagnosticPrinter(llvm::SourceMgr &SM) : SrcMgr(SM) {}
35 | virtual ~TextDiagnosticPrinter();
36 |
37 | // TODO: Emit caret diagnostics and Highlight range.
38 | virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
39 | SourceLocation L, const llvm::Twine &Msg,
40 | llvm::ArrayRef Ranges,
41 | llvm::ArrayRef FixIts);
42 | };
43 |
44 | } // end namespace fort
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/include/fort/Parse/LexDiagnostic.h:
--------------------------------------------------------------------------------
1 | //===--- LexDiagnostic.h - Diagnostics for lexer --------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef LLVM_FORT_LEXDIAGNOSTIC_H
11 | #define LLVM_FORT_LEXDIAGNOSTIC_H
12 |
13 | #include "fort/Basic/Diagnostic.h"
14 |
15 | namespace fort {
16 | namespace diag {
17 | enum {
18 | #define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, ACCESS, \
19 | NOWERROR, SHOWINSYSHEADER, CATEGORY) \
20 | ENUM,
21 | #define LEXSTART
22 | #include "fort/Basic/DiagnosticLexKinds.inc"
23 | #undef DIAG
24 | NUM_BUILTIN_LEX_DIAGNOSTICS
25 | };
26 | } // end namespace diag
27 | } // end namespace fort
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/include/fort/Parse/ParseDiagnostic.h:
--------------------------------------------------------------------------------
1 | //===--- ParseDiagnostic.h - Diagnostics for parser --------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef LLVM_FORT_PARSEDIAGNOSTIC_H
11 | #define LLVM_FORT_PARSEDIAGNOSTIC_H
12 |
13 | #include "fort/Basic/Diagnostic.h"
14 |
15 | namespace fort {
16 | namespace diag {
17 | enum {
18 | #define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, ACCESS, \
19 | NOWERROR, SHOWINSYSHEADER, CATEGORY) \
20 | ENUM,
21 | #define PARSESTART
22 | #include "fort/Basic/DiagnosticParseKinds.inc"
23 | #undef DIAG
24 | NUM_BUILTIN_PARSE_DIAGNOSTICS
25 | };
26 | } // end namespace diag
27 | } // end namespace fort
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/include/fort/Sema/SemaDiagnostic.h:
--------------------------------------------------------------------------------
1 | //===--- SemaDiagnostic.h - Diagnostics for semantics --------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef LLVM_FORT_SEMADIAGNOSTIC_H
11 | #define LLVM_FORT_SEMADIAGNOSTIC_H
12 |
13 | #include "fort/Basic/Diagnostic.h"
14 |
15 | namespace fort {
16 | namespace diag {
17 | enum {
18 | #define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, ACCESS, \
19 | NOWERROR, SHOWINSYSHEADER, CATEGORY) \
20 | ENUM,
21 | #define SEMASTART
22 | #include "fort/Basic/DiagnosticSemaKinds.inc"
23 | #undef DIAG
24 | NUM_BUILTIN_SEMA_DIAGNOSTICS
25 | };
26 | } // end namespace diag
27 | } // end namespace fort
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/lib/AST/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LLVM_LINK_COMPONENTS support)
2 |
3 | add_fort_library(fortAST
4 | ASTContext.cpp
5 | Decl.cpp
6 | DeclGroup.cpp
7 | DeclarationName.cpp
8 | Expr.cpp
9 | ExprConstant.cpp
10 | ExprArray.cpp
11 | FormatSpec.cpp
12 | FormatItem.cpp
13 | IOSpec.cpp
14 | Stmt.cpp
15 | ASTDumper.cpp
16 | Type.cpp
17 | IntrinsicFunctions.cpp
18 | )
19 |
20 | add_dependencies(fortAST
21 | FortDiagnosticCommon
22 | FortDeclNodes
23 | FortStmtNodes
24 | FortExprNodes
25 | )
26 |
27 | target_link_libraries(fortAST
28 | PRIVATE
29 | fortBasic
30 | )
31 |
--------------------------------------------------------------------------------
/lib/AST/DeclGroup.cpp:
--------------------------------------------------------------------------------
1 | //===--- DeclGroup.cpp - Classes for representing groups of Decls ----------==//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This file implements the DeclGroup and DeclGroupRef classes.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #include "fort/AST/DeclGroup.h"
15 | #include "fort/AST/ASTContext.h"
16 | #include "fort/AST/Decl.h"
17 | #include "llvm/Support/Allocator.h"
18 | #include
19 |
20 | namespace fort {
21 |
22 | DeclGroup *DeclGroup::Create(ASTContext &C, Decl **Decls, unsigned NumDecls) {
23 | assert(NumDecls > 1 && "Invalid DeclGroup");
24 | unsigned Size = sizeof(DeclGroup) + sizeof(Decl *) * NumDecls;
25 | void *Mem = C.Allocate(Size, alignof(DeclGroup));
26 | new (Mem) DeclGroup(NumDecls, Decls);
27 | return static_cast(Mem);
28 | }
29 |
30 | DeclGroup::DeclGroup(unsigned numdecls, Decl **decls) : NumDecls(numdecls) {
31 | assert(numdecls > 0);
32 | assert(decls);
33 | memcpy(this + 1, decls, numdecls * sizeof(*decls));
34 | }
35 |
36 | } // namespace fort
37 |
--------------------------------------------------------------------------------
/lib/AST/FormatSpec.cpp:
--------------------------------------------------------------------------------
1 | //===--- FormatSpec.cpp - Fortran FormatSpecifier -------------------------===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #include "fort/AST/FormatSpec.h"
11 | #include "fort/AST/ASTContext.h"
12 |
13 | namespace fort {
14 |
15 | StarFormatSpec::StarFormatSpec(SourceLocation Loc)
16 | : FormatSpec(FormatSpec::FS_Star, Loc) {}
17 |
18 | StarFormatSpec *StarFormatSpec::Create(ASTContext &C, SourceLocation Loc) {
19 | return new (C) StarFormatSpec(Loc);
20 | }
21 |
22 | CharacterExpFormatSpec::CharacterExpFormatSpec(SourceLocation Loc, Expr *F)
23 | : FormatSpec(FormatSpec::FS_CharExpr, Loc), Fmt(F) {}
24 |
25 | CharacterExpFormatSpec *
26 | CharacterExpFormatSpec::Create(ASTContext &C, SourceLocation Loc, Expr *Fmt) {
27 | return new (C) CharacterExpFormatSpec(Loc, Fmt);
28 | }
29 |
30 | LabelFormatSpec::LabelFormatSpec(SourceLocation Loc, StmtLabelReference Label)
31 | : FormatSpec(FormatSpec::FS_Label, Loc), StmtLabel(Label) {}
32 |
33 | LabelFormatSpec *LabelFormatSpec::Create(ASTContext &C, SourceLocation Loc,
34 | StmtLabelReference Label) {
35 | return new (C) LabelFormatSpec(Loc, Label);
36 | }
37 |
38 | void LabelFormatSpec::setLabel(StmtLabelReference Label) {
39 | assert(!StmtLabel.Statement);
40 | assert(Label.Statement);
41 | StmtLabel = Label;
42 | }
43 |
44 | VarLabelFormatSpec::VarLabelFormatSpec(SourceLocation Loc, VarExpr *VarRef)
45 | : FormatSpec(FormatSpec::FS_VarLabel, Loc), Var(VarRef) {}
46 |
47 | VarLabelFormatSpec *
48 | VarLabelFormatSpec::Create(ASTContext &C, SourceLocation Loc, VarExpr *Var) {
49 | return new (C) VarLabelFormatSpec(Loc, Var);
50 | }
51 |
52 | } // namespace fort
53 |
--------------------------------------------------------------------------------
/lib/AST/IOSpec.cpp:
--------------------------------------------------------------------------------
1 | //===--- IOSpec.cpp - Fortran IO Specifier -------------------------------===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #include "fort/AST/IOSpec.h"
11 | #include "fort/AST/ASTContext.h"
12 |
13 | namespace fort {
14 |
15 | ExternalStarUnitSpec::ExternalStarUnitSpec(SourceLocation Loc, bool IsLabeled)
16 | : UnitSpec(US_ExternalStar, Loc, IsLabeled) {}
17 |
18 | ExternalStarUnitSpec *ExternalStarUnitSpec::Create(ASTContext &C,
19 | SourceLocation Loc,
20 | bool IsLabeled) {
21 | return new (C) ExternalStarUnitSpec(Loc, IsLabeled);
22 | }
23 |
24 | ExternalIntegerUnitSpec::ExternalIntegerUnitSpec(SourceLocation Loc,
25 | Expr *Value, bool IsLabeled)
26 | : UnitSpec(US_ExternalInt, Loc, IsLabeled), E(Value) {}
27 |
28 | ExternalIntegerUnitSpec *ExternalIntegerUnitSpec::Create(ASTContext &C,
29 | SourceLocation Loc,
30 | Expr *Value,
31 | bool IsLabeled) {
32 | return new (C) ExternalIntegerUnitSpec(Loc, Value, IsLabeled);
33 | }
34 |
35 | InternalUnitSpec::InternalUnitSpec(SourceLocation Loc, Expr *Value,
36 | bool IsLabeled)
37 | : UnitSpec(US_Internal, Loc, IsLabeled), E(Value) {}
38 |
39 | InternalUnitSpec *InternalUnitSpec::Create(ASTContext &C, SourceLocation Loc,
40 | Expr *Value, bool IsLabeled) {
41 | return new (C) InternalUnitSpec(Loc, Value, IsLabeled);
42 | }
43 |
44 | } // end namespace fort
45 |
--------------------------------------------------------------------------------
/lib/Basic/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LLVM_LINK_COMPONENTS mc)
2 |
3 | find_first_existing_vc_file("${LLVM_MAIN_SRC_DIR}" llvm_vc)
4 | find_first_existing_vc_file("${FORT_SOURCE_DIR}" fort_vc)
5 |
6 | # The VC revision include that we want to generate.
7 | set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
8 |
9 | set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
10 |
11 | if (llvm_vc)
12 | set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
13 | endif()
14 | if (fort_vc)
15 | set(fort_source_dir ${FORT_SOURCE_DIR})
16 | endif()
17 |
18 | # Create custom target to generate the VC revision include.
19 | add_custom_command(OUTPUT "${version_inc}"
20 | DEPENDS "${llvm_vc}" "${fort_vc}" "${generate_vcs_version_script}"
21 | COMMAND ${CMAKE_COMMAND} "-DNAMES=\"LLVM;FORT\""
22 | "-DLLVM_SOURCE_DIR=${llvm_source_dir}"
23 | "-DFORT_SOURCE_DIR=${fort_source_dir}"
24 | "-DHEADER_FILE=${version_inc}"
25 | -P "${generate_vcs_version_script}")
26 |
27 | # Mark the generated header as being generated.
28 | set_source_files_properties("${version_inc}"
29 | PROPERTIES GENERATED TRUE
30 | HEADER_FILE_ONLY TRUE)
31 |
32 | set_property(SOURCE Version.cpp APPEND PROPERTY
33 | COMPILE_DEFINITIONS "HAVE_VCS_VERSION_INC")
34 |
35 | add_fort_library(fortBasic
36 | CharInfo.cpp
37 | Diagnostic.cpp
38 | DiagnosticIDs.cpp
39 | IdentifierTable.cpp
40 | TargetInfo.cpp
41 | Targets.cpp
42 | Token.cpp
43 | TokenKinds.cpp
44 | Version.cpp
45 | ${version_inc}
46 | )
47 |
48 |
--------------------------------------------------------------------------------
/lib/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_subdirectory(AST)
2 | add_subdirectory(Basic)
3 | add_subdirectory(Driver)
4 | add_subdirectory(Frontend)
5 | add_subdirectory(Parse)
6 | add_subdirectory(Sema)
7 | add_subdirectory(CodeGen)
8 |
--------------------------------------------------------------------------------
/lib/CodeGen/CGABI.cpp:
--------------------------------------------------------------------------------
1 | //===----- CGABI.h - ABI types-----------------------------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #include "CGABI.h"
11 |
12 | namespace fort {
13 | namespace CodeGen {
14 |
15 | ABIArgInfo FortranABI::GetArgABI(QualType ArgType) {
16 | if (ArgType->isCharacterType())
17 | return ABIArgInfo(
18 | ABIArgInfo::ExpandCharacterPutLengthToAdditionalArgsAsInt);
19 | else if (ArgType->isFunctionType())
20 | return ABIArgInfo(ABIArgInfo::Value);
21 |
22 | return ABIArgInfo(ABIArgInfo::Reference);
23 | }
24 |
25 | ABIRetInfo FortranABI::GetRetABI(QualType RetType) {
26 | if (RetType.isNull() || RetType->isVoidType())
27 | return ABIRetInfo(ABIRetInfo::Nothing);
28 | if (RetType->isCharacterType())
29 | return ABIRetInfo(ABIRetInfo::CharacterValueAsArg);
30 |
31 | return ABIRetInfo(ABIRetInfo::Value);
32 | }
33 |
34 | ABIArgInfo LibfortABI::GetArgABI(QualType ArgType) {
35 | if (ArgType->isComplexType() || ArgType->isCharacterType())
36 | return ABIArgInfo(ABIArgInfo::Expand);
37 | return ABIArgInfo(ABIArgInfo::Value);
38 | }
39 |
40 | ABIRetInfo LibfortABI::GetRetABI(QualType RetType) {
41 | return FortranABI::GetRetABI(RetType);
42 | }
43 |
44 | ABIArgInfo LibfortTransferABI::GetArgABI(QualType ArgType) {
45 | if (ArgType->isCharacterType())
46 | return LibfortABI::GetArgABI(ArgType);
47 |
48 | return ABIArgInfo(ABIArgInfo::ReferenceAsVoidExtraSize);
49 | }
50 |
51 | } // namespace CodeGen
52 | } // end namespace fort
53 |
--------------------------------------------------------------------------------
/lib/CodeGen/CGABI.h:
--------------------------------------------------------------------------------
1 | //===----- CGABI.h - ABI types-----------------------------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef FORT_CODEGEN_ABI_H
11 | #define FORT_CODEGEN_ABI_H
12 |
13 | #include "ABIInfo.h"
14 |
15 | namespace fort {
16 | namespace CodeGen {
17 |
18 | class FortranABI {
19 | public:
20 | virtual ~FortranABI() {}
21 | virtual ABIArgInfo GetArgABI(QualType ArgType);
22 | virtual ABIRetInfo GetRetABI(QualType RetType);
23 | };
24 |
25 | class LibfortABI : public FortranABI {
26 | public:
27 | virtual ~LibfortABI() {}
28 | ABIArgInfo GetArgABI(QualType ArgType);
29 | ABIRetInfo GetRetABI(QualType RetType);
30 | };
31 |
32 | class LibfortTransferABI : public LibfortABI {
33 | public:
34 | virtual ~LibfortTransferABI() {}
35 | ABIArgInfo GetArgABI(QualType ArgType);
36 | };
37 |
38 | } // namespace CodeGen
39 | } // end namespace fort
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/lib/CodeGen/CGBuilder.h:
--------------------------------------------------------------------------------
1 | //===-- CGBuilder.h - Choose IRBuilder implementation ----------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #ifndef FORT_CODEGEN_CGBUILDER_H
11 | #define FORT_CODEGEN_CGBUILDER_H
12 |
13 | #include "llvm/IR/IRBuilder.h"
14 |
15 | namespace fort {
16 | namespace CodeGen {
17 |
18 | typedef llvm::IRBuilder<> CGBuilderTy; // FIXME more explicit type?
19 |
20 | } // end namespace CodeGen
21 | } // end namespace fort
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/lib/CodeGen/CGIORuntime.cpp:
--------------------------------------------------------------------------------
1 | //===----- CGIORuntime.h - Interface to IO Runtimes -------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This provides an abstract class for IO statements code generation.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #include "CGIORuntime.h"
15 | #include "CodeGenFunction.h"
16 |
17 | namespace fort {
18 | namespace CodeGen {
19 |
20 | CGIORuntime::~CGIORuntime() {}
21 |
22 | } // namespace CodeGen
23 | } // end namespace fort
24 |
--------------------------------------------------------------------------------
/lib/CodeGen/CGIORuntime.h:
--------------------------------------------------------------------------------
1 | //===----- CGIORuntime.h - Interface to IO Runtimes -------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This provides an abstract class for IO statements code generation.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #ifndef FORT_CODEGEN_IORUNTIME_H
15 | #define FORT_CODEGEN_IORUNTIME_H
16 |
17 | #include "fort/AST/Stmt.h"
18 |
19 | namespace fort {
20 | namespace CodeGen {
21 |
22 | class CodeGenFunction;
23 | class CodeGenModule;
24 |
25 | class CGIORuntime {
26 | protected:
27 | CodeGenModule &CGM;
28 |
29 | public:
30 | CGIORuntime(CodeGenModule &cgm) : CGM(cgm) {}
31 | virtual ~CGIORuntime();
32 |
33 | virtual void EmitWriteStmt(CodeGenFunction &CGF, const WriteStmt *S) = 0;
34 | virtual void EmitPrintStmt(CodeGenFunction &CGF, const PrintStmt *S) = 0;
35 | };
36 |
37 | /// Creates an instance of a Libfort IO runtime class.
38 | CGIORuntime *CreateLibfortIORuntime(CodeGenModule &CGM);
39 |
40 | } // namespace CodeGen
41 | } // end namespace fort
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/lib/CodeGen/CGSystemRuntime.cpp:
--------------------------------------------------------------------------------
1 | //===----- CGSystemRuntime.h - Interface to System specific Runtimes ------===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This provides an abstract class for system specific runtime calls.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #include "CGSystemRuntime.h"
15 | #include "CodeGenFunction.h"
16 |
17 | namespace fort {
18 | namespace CodeGen {
19 |
20 | CGSystemRuntime::~CGSystemRuntime() {}
21 |
22 | llvm::Value *CGSystemRuntime::EmitMalloc(CodeGenFunction &CGF, llvm::Type *T,
23 | llvm::Value *Size) {
24 | return CGF.getBuilder().CreateBitCast(EmitMalloc(CGF, Size), T);
25 | }
26 |
27 | } // namespace CodeGen
28 | } // end namespace fort
29 |
--------------------------------------------------------------------------------
/lib/CodeGen/CGSystemRuntime.h:
--------------------------------------------------------------------------------
1 | //===----- CGSystemRuntime.h - Interface to System specific Runtimes ------===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This provides an abstract class for system specific runtime calls.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #ifndef FORT_CODEGEN_SYSTEMRUNTIME_H
15 | #define FORT_CODEGEN_SYSTEMRUNTIME_H
16 |
17 | #include "fort/AST/Stmt.h"
18 |
19 | namespace llvm {
20 | class Value;
21 | class Type;
22 | } // namespace llvm
23 |
24 | namespace fort {
25 | namespace CodeGen {
26 |
27 | class CodeGenFunction;
28 | class CodeGenModule;
29 |
30 | class CGSystemRuntime {
31 | protected:
32 | CodeGenModule &CGM;
33 |
34 | public:
35 | CGSystemRuntime(CodeGenModule &cgm) : CGM(cgm) {}
36 | virtual ~CGSystemRuntime();
37 |
38 | virtual void EmitInit(CodeGenFunction &CGF) = 0;
39 |
40 | virtual llvm::Value *EmitMalloc(CodeGenFunction &CGF, llvm::Value *Size) = 0;
41 | llvm::Value *EmitMalloc(CodeGenFunction &CGF, llvm::Type *T,
42 | llvm::Value *Size);
43 | virtual void EmitFree(CodeGenFunction &CGF, llvm::Value *Ptr) = 0;
44 |
45 | virtual llvm::Value *EmitETIME(CodeGenFunction &CGF,
46 | ArrayRef Arguments) = 0;
47 | };
48 |
49 | /// Creates an instance of a Libfort System runtime class.
50 | CGSystemRuntime *CreateLibfortSystemRuntime(CodeGenModule &CGM);
51 |
52 | } // namespace CodeGen
53 | } // end namespace fort
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/lib/CodeGen/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_fort_library(fortCodeGen
2 | ModuleBuilder.cpp
3 | CodeGenModule.cpp
4 | CodeGenFunction.cpp
5 | CodeGenTypes.cpp
6 | CodeGenAction.cpp
7 | BackendUtil.cpp
8 | TargetInfo.cpp
9 | CGABI.cpp
10 | CGDecl.cpp
11 | CGStmt.cpp
12 | CGExpr.cpp
13 | CGExprScalar.cpp
14 | CGExprComplex.cpp
15 | CGExprCharacter.cpp
16 | CGExprAgg.cpp
17 | CGArray.cpp
18 | CGIntrinsic.cpp
19 | CGArrayIntrinsic.cpp
20 | CGCall.cpp
21 | CGIORuntime.cpp
22 | CGIOLibfort.cpp
23 | CGSystemRuntime.cpp
24 | CGSystemLibfort.cpp
25 | )
26 |
27 | target_link_libraries(fortCodeGen
28 | fortAST
29 | LLVMCore
30 | )
31 |
--------------------------------------------------------------------------------
/lib/CodeGen/TargetInfo.h:
--------------------------------------------------------------------------------
1 | //===---- TargetInfo.h - Encapsulate target details -------------*- C++ -*-===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // These classes wrap the information about a call or function
11 | // definition used to handle ABI compliancy.
12 | //
13 | //===----------------------------------------------------------------------===//
14 |
15 | #ifndef FORT_CODEGEN_TARGETINFO_H
16 | #define FORT_CODEGEN_TARGETINFO_H
17 |
18 | #include "fort/AST/Type.h"
19 | #include "fort/Basic/LLVM.h"
20 | #include "llvm/ADT/SmallString.h"
21 | #include "llvm/ADT/StringRef.h"
22 |
23 | namespace llvm {
24 | class GlobalValue;
25 | class Type;
26 | class Value;
27 | } // namespace llvm
28 |
29 | namespace fort {
30 | class ABIInfo;
31 | class Decl;
32 |
33 | namespace CodeGen {
34 | class CallArgList;
35 | class CodeGenModule;
36 | class CodeGenFunction;
37 | class CGFunctionInfo;
38 | } // namespace CodeGen
39 |
40 | /// TargetCodeGenInfo - This class organizes various target-specific
41 | /// codegeneration issues, like target-specific attributes, builtins and so
42 | /// on.
43 | class TargetCodeGenInfo {
44 | ABIInfo *Info;
45 |
46 | public:
47 | TargetCodeGenInfo(ABIInfo *info = nullptr) : Info(info) {}
48 | virtual ~TargetCodeGenInfo();
49 |
50 | /// getABIInfo() - Returns ABI info helper for the target.
51 | const ABIInfo &getABIInfo() const { return *Info; }
52 | };
53 | } // namespace fort
54 |
55 | #endif // FORT_CODEGEN_TARGETINFO_H
56 |
--------------------------------------------------------------------------------
/lib/Driver/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_fort_library(fortDriver
2 | DriverOptions.cpp
3 | DEPENDS
4 | FortDriverOptions
5 | )
6 |
7 |
--------------------------------------------------------------------------------
/lib/Driver/DriverOptions.cpp:
--------------------------------------------------------------------------------
1 | //===--- DriverOptions.cpp - Driver Options Table -------------------------===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 |
10 | #include "fort/Driver/Options.h"
11 | #include "llvm/ADT/STLExtras.h"
12 | #include "llvm/Option/OptTable.h"
13 | #include "llvm/Option/Option.h"
14 | #include
15 |
16 | using namespace fort::driver;
17 | using namespace fort::driver::options;
18 | using namespace llvm::opt;
19 |
20 | #define PREFIX(NAME, VALUE) static const char *const NAME[] = VALUE;
21 | #include "fort/Driver/Options.inc"
22 | #undef PREFIX
23 |
24 | static const OptTable::Info InfoTable[] = {
25 | #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
26 | HELPTEXT, METAVAR, VALUES) \
27 | {PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, \
28 | PARAM, FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, VALUES},
29 | #include "fort/Driver/Options.inc"
30 | #undef OPTION
31 | };
32 |
33 | namespace {
34 |
35 | class DriverOptTable : public OptTable {
36 | public:
37 | DriverOptTable()
38 | : OptTable(InfoTable) {}
39 | };
40 |
41 | }
42 |
43 | std::unique_ptr fort::driver::createDriverOptTable() {
44 | auto Result = std::make_unique();
45 | // Options.inc is included in DriverOptions.cpp, and calls OptTable's
46 | // addValues function.
47 | // Opt is a variable used in the code fragment in Options.inc.
48 | OptTable &Opt = *Result;
49 | #define OPTTABLE_ARG_INIT
50 | #include "fort/Driver/Options.inc"
51 | #undef OPTTABLE_ARG_INIT
52 | return std::move(Result);
53 | }
54 |
--------------------------------------------------------------------------------
/lib/Frontend/ASTConsumers.cpp:
--------------------------------------------------------------------------------
1 | //===--- ASTConsumers.cpp - ASTConsumer implementations -------------------===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // AST Consumer Implementations.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #include "fort/Frontend/ASTConsumers.h"
15 | #include "fort/AST/ASTConsumer.h"
16 | #include "fort/AST/ASTContext.h"
17 | #include
18 |
19 | using namespace fort;
20 |
21 | namespace {
22 |
23 | class ASTPrinter : public ASTConsumer {
24 | public:
25 | std::string FilterString;
26 |
27 | ASTPrinter(StringRef Filter) : FilterString(Filter) {}
28 |
29 | void HandleTranslationUnit(ASTContext &Ctx) {
30 | Ctx.getTranslationUnitDecl()->dump();
31 | }
32 | };
33 |
34 | } // namespace
35 |
36 | ASTConsumer *fort::CreateASTDumper(StringRef FilterString) {
37 | return new ASTPrinter(FilterString);
38 | }
39 |
--------------------------------------------------------------------------------
/lib/Frontend/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_fort_library(fortFrontend
2 | ASTConsumers.cpp
3 | TextDiagnosticPrinter.cpp
4 | TextDiagnosticBuffer.cpp
5 | VerifyDiagnosticConsumer.cpp
6 | )
7 |
--------------------------------------------------------------------------------
/lib/Frontend/TextDiagnosticPrinter.cpp:
--------------------------------------------------------------------------------
1 | //===--- TextDiagnosticPrinter.cpp - Diagnostic Printer -------------------===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This diagnostic client prints out their diagnostic messages.
11 | //
12 | //===----------------------------------------------------------------------===//
13 |
14 | #include "fort/Frontend/TextDiagnosticPrinter.h"
15 | #include "llvm/ADT/None.h"
16 | #include "llvm/ADT/SmallString.h"
17 | #include "llvm/ADT/StringExtras.h"
18 | #include "llvm/Support/MemoryBuffer.h"
19 | #include "llvm/Support/SourceMgr.h"
20 | #include "llvm/Support/raw_ostream.h"
21 | #include
22 |
23 | namespace fort {
24 |
25 | TextDiagnosticPrinter::~TextDiagnosticPrinter() {}
26 |
27 | void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
28 | SourceLocation L,
29 | const llvm::Twine &Msg,
30 | llvm::ArrayRef Ranges,
31 | llvm::ArrayRef FixIts) {
32 | // Default implementation (Warnings/errors count).
33 | DiagnosticClient::HandleDiagnostic(Level, L, Msg, Ranges, FixIts);
34 | llvm::SourceMgr::DiagKind MsgTy;
35 | switch (Level) {
36 | case DiagnosticsEngine::Ignored:
37 | return;
38 | case DiagnosticsEngine::Note:
39 | MsgTy = llvm::SourceMgr::DK_Note;
40 | break;
41 | case DiagnosticsEngine::Warning:
42 | MsgTy = llvm::SourceMgr::DK_Warning;
43 | break;
44 | case DiagnosticsEngine::Error:
45 | MsgTy = llvm::SourceMgr::DK_Error;
46 | break;
47 | case DiagnosticsEngine::Fatal:
48 | MsgTy = llvm::SourceMgr::DK_Error;
49 | break;
50 | }
51 |
52 | SrcMgr.PrintMessage(L, MsgTy, Msg, Ranges, FixIts, true);
53 | }
54 |
55 | } // namespace fort
56 |
--------------------------------------------------------------------------------
/lib/Parse/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_fort_library(fortParse
2 | Lexer.cpp
3 | ParseDecl.cpp
4 | ParseSpecStmt.cpp
5 | ParseExec.cpp
6 | ParseExpr.cpp
7 | ParseFormat.cpp
8 | Parser.cpp
9 | FixedForm.cpp
10 | )
11 |
12 | add_dependencies(fortParse
13 | FortDeclNodes
14 | FortDiagnosticParse
15 | )
16 |
17 | target_link_libraries(fortParse
18 | fortAST
19 | )
20 |
--------------------------------------------------------------------------------
/lib/Sema/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_fort_library(fortSema
2 | DeclSpec.cpp
3 | Scope.cpp
4 | Sema.cpp
5 | SemaDecl.cpp
6 | SemaExecStmt.cpp
7 | SemaDataStmt.cpp
8 | SemaExpr.cpp
9 | SemaArrayExpr.cpp
10 | SemaChecking.cpp
11 | SemaIntrinsic.cpp
12 | SemaFormat.cpp
13 | SemaIO.cpp
14 | SemaEquivalence.cpp
15 | Spec.cpp
16 | )
17 |
18 | target_link_libraries(fortSema
19 | fortAST
20 | )
21 |
--------------------------------------------------------------------------------
/test/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | configure_lit_site_cfg(
2 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
3 | ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
4 | )
5 |
6 | configure_file(TestRunner.sh.in ${CMAKE_CURRENT_BINARY_DIR}/TestRunner.sh)
7 |
8 | option(FORT_TEST_USE_VG "Run Fort tests under Valgrind" OFF)
9 | if(FORT_TEST_USE_VG)
10 | set(FORT_TEST_EXTRA_ARGS ${FORT_TEST_EXTRA_ARGS} "--vg")
11 | endif ()
12 |
13 | list(APPEND FORT_TEST_DEPS
14 | fort
15 | )
16 |
17 | set(FORT_TEST_PARAMS
18 | fort_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
19 | )
20 |
21 | if( NOT FORT_BUILT_STANDALONE )
22 | list(APPEND FORT_TEST_DEPS
23 | llvm-config
24 | FileCheck not
25 | )
26 | endif()
27 |
28 | add_lit_testsuite(check-fort "Running Fort regression tests"
29 | ${CMAKE_CURRENT_BINARY_DIR}
30 | PARAMS ${FORT_TEST_PARAMS}
31 | DEPENDS ${FORT_TEST_DEPS}
32 | ARGS ${FORT_TEST_EXTRA_ARGS}
33 | )
34 | set_target_properties(check-fort PROPERTIES FOLDER "Fort tests")
35 |
36 |
--------------------------------------------------------------------------------
/test/CodeGen/Intrinsics/bitops.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | PROGRAM bittest
4 |
5 | integer i
6 | integer(8) i64
7 | logical l
8 |
9 | i = 12
10 | i = not(i) ! CHECK: xor i32 {{.*}}, -1
11 | i = iand(i, 15) ! CHECK: and i32
12 | i = iand(1,2) ! CHECK: store i32 0
13 | i = ior(i, 1) ! CHECK: or i32
14 | i = ior(7,8) ! CHECK: store i32 15
15 | i64 = ieor(i64, i64) ! CHECK: xor i64
16 | i = ieor(1,3) ! CHECK: store i32 2
17 |
18 | l = btest(i, 2) ! CHECK: and i32 {{.*}}, 4
19 | continue ! CHECK-NEXT: icmp ne i32
20 | continue ! CHECK-NEXT: select i1 {{.*}}, i1 true, i1 false
21 | l = btest(8,3) ! CHECK: store i32 1
22 |
23 | i = ibset(i, 2) ! CHECK: or i32 {{.*}}, 4
24 | i = ibset(12,1) ! CHECK: store i32 14
25 | i64 = ibclr(i64, 1) ! CHECK: and i64 {{.*}}, -3
26 | i = ibclr(14,1) ! CHECK: store i32 12
27 |
28 | i = ibits(i, 2, 4) ! CHECK: lshr i32 {{.*}}, 2
29 | continue ! CHECK-NEXT: and i32 {{.*}}, 15
30 | i = ibits(14, 1, 3) ! CHECK: store i32 7
31 |
32 | i = ishft(i, 4) ! CHECK: shl i32 {{.*}}, 4
33 | i = ishft(i, -2) ! CHECK: lshr i32 {{.*}}, 2
34 | i = ishft(i, i/4) ! CHECK: icmp sge i32 {{.*}}, 0
35 | continue ! CHECK: select i1
36 |
37 | i = ishft(3, 1) ! CHECK: store i32 6
38 | i = ishft(8, -1) ! CHECK: store i32 4
39 |
40 | end
41 |
--------------------------------------------------------------------------------
/test/CodeGen/Intrinsics/inquiry.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | PROGRAM inquirytest
4 |
5 | integer i
6 | integer(8) i64
7 | complex(8) c8
8 |
9 | data i / bit_size(23) /
10 |
11 | i = kind(i) ! CHECK: store i32 4
12 | i = kind(i64) ! CHECK-NEXT: store i32 8
13 | i64 = kind(c8) ! CHECK-NEXT: store i64 8
14 |
15 | i = bit_size(i) ! CHECK-NEXT: store i32 32
16 | i = bit_size(i64) ! CHECK-NEXT: store i32 64
17 |
18 | i = selected_int_kind(7) ! CHECK-NEXT: store i32 4
19 | i = selected_int_kind(1000) ! CHECK-NEXT: store i32 -1
20 |
21 | i = selected_int_kind(i) ! CHECK: call i32 @libfort_selected_int_kind(i32
22 | i64 = selected_int_kind(i64) ! CHECK: call i32 @libfort_selected_int_kind(i32
23 |
24 | end
25 |
--------------------------------------------------------------------------------
/test/CodeGen/Intrinsics/maxminloc.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | PROGRAM maxminloctest
4 |
5 | INTRINSIC maxloc, minloc
6 | integer i_arr(5)
7 | real r_arr(5)
8 |
9 | i_arr = (/ 4, 7, 2, 1, 0 /)
10 | i = maxloc(i_arr, 1) ! CHECK: icmp sgt i32
11 | continue ! CHECK: br i1
12 |
13 | i = minloc((/ 0, 5, 42, -54, 1 /), 1)
14 |
15 | r_arr = 1.0
16 | i = maxloc(r_arr, 1)
17 |
18 | i = maxloc(r_arr + (/ 1.0, 0.0, 2.0, 3.0, 4.0 /), 1)
19 |
20 | i = maxloc(r_arr(:3), 1)
21 |
22 | ! FIXME: add codegen for other variations of max/min loc
23 |
24 | END
25 |
--------------------------------------------------------------------------------
/test/CodeGen/array.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | PROGRAM helloArrays
4 |
5 | REAL R(10) ! CHECK: alloca [10 x float]
6 | INTEGER I(-1:5) ! CHECK: alloca [7 x i32]
7 | COMPLEX C(10, 0:9, 10) ! CHECK: alloca [1000 x { float, float }]
8 | CHARACTER*20 STR(-5:4, 9) ! CHECK: alloca [90 x [20 x i8]]
9 |
10 | INTEGER ii
11 | INTEGER (Kind=1) is
12 | REAL rr
13 | COMPLEX cc
14 | CHARACTER*20 STRSTR
15 |
16 | rr = r(1) ! CHECK: getelementptr inbounds [10 x float], [10 x float]*
17 | CONTINUE ! CHECK: getelementptr float, float*
18 | CONTINUE ! CHECK: load float, float*
19 |
20 | ii = i(0) ! CHECK: getelementptr i32, i32*
21 |
22 | is = 1
23 | i(is) = r(is) ! CHECK: sext i8
24 |
25 | cc = c(1, 1, 1) ! CHECK: getelementptr { float, float }, { float, float }*
26 |
27 | STRSTR = STR(4, 9) ! CHECK: getelementptr [20 x i8], [20 x i8]*
28 |
29 | i(5) = 11
30 | r(1) = 1.0
31 | c(10, 9, 10) = (1.0, 0.0)
32 | str(1,1) = 'Hello'
33 |
34 | END
35 |
--------------------------------------------------------------------------------
/test/CodeGen/arrayArgument.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | SUBROUTINE SUB(IARR, IARR2, LEN, RARR)
4 | INTEGER IARR(10), IARR2(*)
5 | INTEGER LEN, I, J
6 | REAL RARR(LEN, *)
7 |
8 | IARR(1) = 11
9 | IARR2(25) = 13
10 |
11 | RARR(22, 4) = 1.0 ! CHECK: load i32, i32*
12 | CONTINUE ! CHECK: mul i64 3
13 | CONTINUE ! CHECK: add i64 21
14 | CONTINUE ! CHECK: getelementptr float, float*
15 |
16 | DO I = 1, 10
17 | IARR(I) = -1 ! CHECK: load i32, i32*
18 | CONTINUE ! CHECK: sub i64
19 | CONTINUE ! CHECK: getelementptr i32, i32*
20 | END DO
21 |
22 | DO I = 1, LEN
23 | DO J = 1, LEN
24 | RARR(I, J) = 0.0
25 | END DO
26 | END DO
27 | END
28 |
29 | PROGRAM f77ArrayArgs
30 |
31 | PARAMETER(xdim = 42)
32 | INTEGER i1(10), i2(50)
33 | REAL r1(xdim, xdim)
34 |
35 | CALL sub(i1, i2, xdim, r1)
36 |
37 | END
38 |
39 |
--------------------------------------------------------------------------------
/test/CodeGen/arrayAssignment.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s
2 |
3 | PROGRAM test
4 |
5 | integer i_mat(4,4), i_mat2(4,4)
6 | integer i
7 |
8 | i = 11
9 | i_mat = i
10 | i_mat2 = i_mat
11 | i_mat(1:3,:) = 2
12 | i_mat(:1,:1) = 11
13 | i_mat(1,:) = 10
14 | i_mat(:2,4) = 12
15 | i_mat(:3:2,1:3:1) = 13
16 |
17 | END
18 |
--------------------------------------------------------------------------------
/test/CodeGen/arrayConstructor.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | PROGRAM test ! CHECK: private constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
4 |
5 | integer i_arr(4), i_mat(4,4)
6 | logical l_arr(4)
7 | integer i
8 | parameter(i = 0)
9 | integer n
10 |
11 |
12 | i_arr = (/ 1, 2, 3, 4 /)
13 | i_arr = (/ i, i, 2, 4 /)
14 | n = 42
15 | i_arr = (/ n, i, 2, n /)
16 |
17 | i_arr = i_arr + (/ 0, 1, 2, 3 /)
18 |
19 | l_arr = (/ .false., .true., .false., i == n /)
20 |
21 | END
22 |
--------------------------------------------------------------------------------
/test/CodeGen/arrayOperations.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s
2 |
3 | PROGRAM test
4 |
5 | integer i_mat(4,4), i_mat2(4,4)
6 | real r_mat(4,4)
7 | complex c_mat(4,4), c_mat2(4,4)
8 | logical l_mat(4,4)
9 | integer i
10 |
11 | i = 11
12 | i_mat = 11
13 | i_mat2 = 12
14 | i_mat = 1.0
15 | r_mat = 1.0
16 | c_mat = (1.0,0.0)
17 | c_mat2 = c_mat
18 | i_mat = r_mat
19 |
20 | i_mat = i_mat + i_mat2
21 | i_mat2 = i_mat * (2 - 4) + r_mat
22 |
23 | c_mat = c_mat * c_mat2
24 | i_mat = c_mat + i_mat2
25 |
26 | l_mat = i_mat <= i_mat2
27 |
28 | i_mat = int(r_mat)
29 | r_mat = real(i_mat)
30 | c_mat = cmplx(c_mat2)
31 | c_mat = cmplx(i_mat,r_mat)
32 |
33 | r_mat = aimag(c_mat)
34 | c_mat = conjg(c_mat)
35 | i_mat = abs(i_mat) + sqrt(r_mat)
36 | r_mat = sin(r_mat) * cos(r_mat) + tan(r_mat)
37 | c_mat = exp(c_mat) + sin(c_mat)
38 |
39 | END
40 |
--------------------------------------------------------------------------------
/test/CodeGen/arrayTempAndPacking.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s
2 |
3 | SUBROUTINE SUB(LEN, IMAT)
4 | INTEGER LEN, IMAT(LEN, *)
5 | END
6 |
7 | PROGRAM test
8 | INTEGER IMAT(4,4)
9 |
10 | IMAT = 0
11 | CALL SUB(4, -IMAT + 1)
12 | END
13 |
--------------------------------------------------------------------------------
/test/CodeGen/callableArguments.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | SUBROUTINE SUB(F, G) ! CHECK: void (i32*)* %f, i32 (float*)* %g
4 | EXTERNAL F
5 | LOGICAL G
6 | EXTERNAL G
7 |
8 | CALL F(2) ! CHECK: call void %f(i32*
9 | IF(G(3.0)) THEN ! CHECK: call i32 %g(float*
10 | END IF
11 | END
12 |
13 | SUBROUTINE F(I)
14 | END
15 |
16 | LOGICAL FUNCTION FOO(R)
17 | Foo = .true.
18 | END
19 |
20 | PROGRAM test
21 | CALL SUB(F, FOO) ! CHECK: call void @sub_(void (i32*)* @f_, i32 (float*)* @foo_)
22 | END
23 |
--------------------------------------------------------------------------------
/test/CodeGen/character.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | SUBROUTINE FOO(STR) ! CHECK: define void @foo_(i8* %str, i32 %str.length)
4 | CHARACTER*(*) STR
5 | STR = 'AGAIN'
6 | END
7 |
8 | SUBROUTINE OOF(STR, R) ! CHECK: define void @oof_(i8* %str, float* noalias %r, i32 %str.length)
9 | CHARACTER*(*) STR
10 | REAL R
11 | STR = 'AGAIN'
12 | END
13 |
14 |
15 | CHARACTER*10 FUNCTION BAR(I) ! CHECK: define void @bar_(i32* noalias %i, { i8*, i64 } %bar)
16 | INTEGER I
17 | BAR = 'STRING'
18 | BAR = BAR
19 | END
20 |
21 | SUBROUTINE SUB(C,C2)
22 | CHARACTER C
23 | CHARACTER*2 C2
24 | IF(C.EQ.'A') RETURN ! CHECK: call i32 @libfort_compare_char1(i8* {{.*}}, i64 1, i8* {{.*}}, i64 1)
25 | IF(C2.NE.'HI') RETURN ! CHECK: call i32 @libfort_compare_char1(i8* {{.*}}, i64 2, i8* {{.*}}, i64 2)
26 | END
27 |
28 | PROGRAM test
29 | CHARACTER STR ! CHECK: alloca [1 x i8]
30 | CHARACTER*20 STR2 ! CHECK: alloca [20 x i8]
31 | PARAMETER (Label = '...')
32 | LOGICAL L
33 |
34 | STR = 'HELLO' ! CHECK: call void @libfort_assignment_char1
35 | STR = STR
36 | STR = STR(1:1)
37 |
38 | STR = STR // ' WORLD' ! CHECK: call void @libfort_concat_char1
39 |
40 | L = STR .EQ. STR ! CHECK: call i32 @libfort_compare_char1
41 | CONTINUE ! CHECK: icmp eq i32
42 |
43 | L = STR .NE. STR ! CHECK: call i32 @libfort_compare_char1
44 | CONTINUE ! CHECK: icmp ne i32
45 |
46 | CALL FOO(STR)
47 |
48 | STR = BAR(2)
49 |
50 | STR2 = 'GREETINGS'
51 | STR2 = Label
52 |
53 | CALL FOO(BAR(1))
54 |
55 | STR2 = 'JK ' // BAR(10) // ' KG'
56 |
57 | END PROGRAM
58 |
--------------------------------------------------------------------------------
/test/CodeGen/characterIntrinsic.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM test
3 | CHARACTER STR
4 | LOGICAL L
5 | INTEGER I
6 |
7 | INTRINSIC len, len_trim, index, lle, lgt
8 |
9 | I = len('Hello') ! CHECK: store i32 5
10 |
11 | I = len_trim('Hello ') ! CHECK: @libfort_lentrim_char1
12 |
13 | STR = 'Hello'
14 |
15 | I = index(STR, STR(:)) ! CHECK: call i{{.*}} @libfort_index_char1
16 |
17 | L = lle(STR, 'Hello')
18 | L = lgt(STR, 'World') ! CHECK: call i32 @libfort_lexcompare_char1
19 |
20 | END PROGRAM
21 |
--------------------------------------------------------------------------------
/test/CodeGen/common.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | program com ! CHECK: @__BLNK__ = common global { i32, i32, float, { float, float } } zeroinitializer, align 16
4 | integer i,j ! CHECK: @dir_ = common global { [20 x i8], i32 } zeroinitializer, align 16
5 | real r
6 | complex c
7 | common i,j,r,c
8 |
9 | integer str_len
10 | character(20) str
11 | common /dir/ str
12 | common /dir/ str_len
13 | save /dir/
14 |
15 | i = 0 ! CHECK: store i32 0, i32* getelementptr inbounds ({ i32, i32, float, { float, float } }, { i32, i32, float, { float, float } }* @__BLNK__, i32 0, i32 0)
16 | r = 1.0
17 | str_len = j ! CHECK: load i32, i32* getelementptr inbounds ({ i32, i32, float, { float, float } }, { i32, i32, float, { float, float } }* @__BLNK__, i32 0, i32 1)
18 | continue ! CHECK-NEXT: i32* getelementptr inbounds ({ [20 x i8], i32 }, { [20 x i8], i32 }* @dir_, i32 0, i32 1)
19 |
20 | str = 'Hello'
21 |
22 | end
23 |
24 | subroutine sub1
25 | integer j
26 | real r
27 | common j, r
28 | character(10) str
29 | common /dir/ str
30 | j = 1 ! CHECK: store i32 1, i32* getelementptr inbounds ({ i32, float }, { i32, float }* bitcast ({ i32, i32, float, { float, float } }* @__BLNK__ to { i32, float }*), i32 0, i32 0)
31 | r = 1.0
32 | str = 'Foo'
33 | end
34 |
--------------------------------------------------------------------------------
/test/CodeGen/complexArithmetic.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM test
3 | COMPLEX C ! CHECK: alloca { float, float }
4 | DOUBLE COMPLEX DC ! CHECK: alloca { double, double }
5 | LOGICAL L
6 |
7 | C = C ! CHECK: getelementptr inbounds { float, float }, { float, float }*
8 | CONTINUE ! CHECK: load float, float*
9 |
10 | C = +C
11 | C = -C ! CHECK: fneg float
12 | CONTINUE ! CHECK: fneg float
13 |
14 | C = C + C ! CHECK: fadd float
15 | CONTINUE ! CHECK: fadd float
16 |
17 | C = C - C ! CHECK: fsub float
18 | CONTINUE ! CHECK: fsub float
19 |
20 | C = C * C ! CHECK: fmul float
21 | CONTINUE ! CHECK: fmul float
22 | CONTINUE ! CHECK: fsub float
23 | CONTINUE ! CHECK: fmul float
24 | CONTINUE ! CHECK: fmul float
25 | CONTINUE ! CHECK: fadd float
26 |
27 | C = C / C ! CHECK: br i1
28 |
29 | C = (1, 2) + C ! CHECK: fadd float 1
30 | CONTINUE ! CHECK: fadd float 2
31 |
32 | C = (-7.0, 7.0) - C ! CHECK: fsub float -7
33 | CONTINUE ! CHECK: fsub float 7
34 |
35 | L = (0.0, 1.0) .EQ. C ! CHECK: fcmp oeq float 0
36 | CONTINUE ! CHECK: fcmp oeq float 1
37 | CONTINUE ! CHECK: and i1
38 |
39 | L = (1.0, 0.0) .NE. C ! CHECK: fcmp une float 1
40 | CONTINUE ! CHECK: fcmp une float 0
41 | CONTINUE ! CHECK: or i1
42 |
43 | C = (1.0, 1.0)
44 | C = C ** 1
45 | C = C ** 2
46 | C = C ** 3 ! CHECK: call void @libfort_cpowif(float {{.*}}, float {{.*}}, i32 3, { float, float }*
47 | C = C ** C ! CHECK: call void @libfort_cpowf(float {{.*}}, float {{.*}}, float {{.*}}, float {{.*}}, { float, float }*
48 |
49 | DC = (2d0, 1d0) + DC ! CHECK: fadd double 2
50 | CONTINUE ! CHECK: fadd double 1
51 | END
52 |
--------------------------------------------------------------------------------
/test/CodeGen/complexIntrinsic.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM testcomplexintrinsics
3 | COMPLEX c
4 | INTRINSIC aimag, conjg
5 | REAL r
6 |
7 | c = (1.0, 0.0) ! CHECK: store float
8 | CONTINUE ! CHECK: store float
9 | r = aimag(c) ! CHECK: store float
10 | c = conjg(c) ! CHECK: fneg float
11 | CONTINUE ! CHECK: store float
12 | CONTINUE ! CHECK: store float
13 |
14 | END
15 |
16 |
--------------------------------------------------------------------------------
/test/CodeGen/complexIntrinsicMath.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - -O1 %s | FileCheck %s
2 | PROGRAM testcomplexintrinsicmath
3 | COMPLEX c
4 | INTRINSIC abs, sqrt, sin, cos, log, exp
5 |
6 | c = (1.0, 0.0)
7 |
8 | c = abs(c) ! CHECK: call float @libfort_cabsf
9 | c = sqrt(c) ! CHECK: call void @libfort_csqrtf(float {{.*}}, float {{.*}}, { float, float }*
10 | c = sin(c) ! CHECK: call void @libfort_csinf(float {{.*}}, float {{.*}}, { float, float }*
11 | c = cos(c) ! CHECK: call void @libfort_ccosf(float {{.*}}, float {{.*}}, { float, float }*
12 | c = log(c) ! CHECK: call void @libfort_clogf(float {{.*}}, float {{.*}}, { float, float }*
13 | c = exp(c) ! CHECK: call void @libfort_cexpf(float {{.*}}, float {{.*}}, { float, float }*
14 |
15 | END
16 |
--------------------------------------------------------------------------------
/test/CodeGen/computedGoto.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM gototest
3 | INTEGER I
4 |
5 | 10 I = 0
6 | 20 GOTO (10,30) I ! CHECK: switch i32
7 |
8 | 30 I = 1
9 |
10 | END PROGRAM
11 |
--------------------------------------------------------------------------------
/test/CodeGen/core.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM test
3 | STOP ! CHECK: call void @libfort_stop()
4 | END PROGRAM
5 |
--------------------------------------------------------------------------------
/test/CodeGen/data.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM datatest
3 | INTEGER I, J
4 | REAL X
5 | INTEGER I_ARR(10)
6 | LOGICAL L_ARR(4)
7 | character(len=5) str1
8 |
9 | DATA (I_ARR(I), I = 1,10) / 2*0, 5*2, 3*-1 /
10 |
11 | DATA L_ARR / .false., .true., .false., .true. /
12 |
13 | data str1 / 'Hello' /
14 |
15 | DATA I / 1 / J, X / 2*0 / ! CHECK: store i32 1
16 | CONTINUE ! CHECK-NEXT: store i32 0
17 | CONTINUE ! CHECK-NEXT: store float 0
18 |
19 | continue ! CHECK: call void @llvm.memcpy.p0i8.p0i8
20 |
21 | END PROGRAM
22 |
--------------------------------------------------------------------------------
/test/CodeGen/defaultDouble8.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fdefault-real-8 -fdefault-double-8 -emit-llvm -o - %s | FileCheck %s
2 |
3 | program test
4 | real x ! CHECK: alloca double
5 | double precision y ! CHECK-NEXT: alloca double
6 | integer i ! CHECK-NEXT: alloca i32
7 | end
8 |
--------------------------------------------------------------------------------
/test/CodeGen/defaultInt8.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fdefault-integer-8 -emit-llvm -o - %s | FileCheck %s
2 |
3 | program test
4 | integer i ! CHECK: alloca i64
5 | logical l ! CHECK-NEXT: alloca i64
6 | end
7 |
--------------------------------------------------------------------------------
/test/CodeGen/defaultReal8.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fdefault-real-8 -emit-llvm -o - %s | FileCheck %s
2 |
3 | program test
4 | real x ! CHECK: alloca double
5 | double precision y ! CHECK-NEXT: alloca fp128
6 | integer i ! CHECK-NEXT: alloca i32
7 | end
8 |
--------------------------------------------------------------------------------
/test/CodeGen/do.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s
2 | PROGRAM dowhiletest
3 | INTEGER I
4 | INTEGER J
5 | REAL R, Z
6 |
7 | J = 1
8 | DO I = 1, 10
9 | J = J * I
10 | END DO
11 |
12 | DO I = 1, 10, -2
13 | J = J - I
14 | END DO
15 |
16 | Z = 0.0
17 | DO R = 1.0, 2.5, 0.25
18 | Z = Z + R
19 | END DO
20 |
21 | END PROGRAM
22 |
--------------------------------------------------------------------------------
/test/CodeGen/dowhile.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM dowhiletest
3 | INTEGER I
4 |
5 | I = 0
6 | DO WHILE(I .LT. 10) ! CHECK: icmp slt
7 | I = I + 1 ! CHECK: br i1
8 | END DO ! CHECK: br label
9 |
10 | END PROGRAM
11 |
--------------------------------------------------------------------------------
/test/CodeGen/equivalence.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | PROGRAM eqtest
4 | INTEGER I, J ! CHECK: alloca i8, i64 4, align
5 | REAL X ! CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 0
6 | EQUIVALENCE(I, J, X)
7 | INTEGER IS
8 | INTEGER I_MAT(4,4), I_MAT2(4,4) ! CHECK: alloca i8, i64 80, align
9 | EQUIVALENCE (IS, I_MAT) ! CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 16
10 | EQUIVALENCE (IS, I_MAT2(1,2))
11 |
12 | I = 0
13 | X = 1.0
14 |
15 | IS = 1
16 | I_MAT(1,1) = 2
17 | END PROGRAM
18 |
--------------------------------------------------------------------------------
/test/CodeGen/exitCycle.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s
2 | PROGRAM test
3 |
4 | do i = 1,10
5 | exit
6 | end do
7 |
8 | outer: do i = 1,10
9 | inner: do j = 1, 10
10 | cycle outer
11 | end do inner
12 | exit outer
13 | end do outer
14 |
15 | END
16 |
--------------------------------------------------------------------------------
/test/CodeGen/goto.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM gototest
3 |
4 | 1000 CONTINUE ! CHECK: 0:
5 | GOTO 1000 ! CHECK: br label %0
6 |
7 | GOTO 2000
8 | 2000 CONTINUE
9 |
10 | END
11 |
--------------------------------------------------------------------------------
/test/CodeGen/if.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM iftest
3 | INTEGER I
4 | LOGICAL L
5 |
6 | IF(.true.) I = I ! CHECK: br i1 true
7 | L = .false. ! CHECK: br label
8 |
9 | IF(L) THEN ! CHECK: br i1
10 | I = I * 2 ! CHECK: br label
11 | ELSE
12 | I = I + 2 ! CHECK: br label
13 | END IF
14 |
15 | IF(I .LE. 0) THEN ! CHECK: icmp sle
16 | I = I + 2 ! CHECK: br i1
17 | ELSE IF(I .GT. 10) THEN ! CHECK: icmp sgt
18 | I = I / 4 ! CHECK: br i1
19 | ELSE
20 | I = -I
21 | END IF
22 |
23 | END PROGRAM
24 |
--------------------------------------------------------------------------------
/test/CodeGen/implicitConversion.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM test
3 | INTEGER I
4 | REAL X
5 | COMPLEX C
6 | LOGICAL L
7 | DOUBLE PRECISION D
8 | DOUBLE COMPLEX CD
9 |
10 | I = 0
11 | X = 1.0
12 | C = (1.0,0.0)
13 | D = 1.0d1
14 |
15 | X = X + I ! CHECK: sitofp i32
16 | CONTINUE ! CHECK: fadd float
17 | CONTINUE ! CHECK: store float
18 |
19 | I = X - I ! CHECK: sitofp i32
20 | CONTINUE ! CHECK: fsub float
21 | CONTINUE ! CHECK: fptosi float
22 | CONTINUE ! CHECK: store i32
23 |
24 | L = X .EQ. I ! CHECK: sitofp i32
25 | CONTINUE ! CHECK: fcmp oeq float
26 |
27 | X = C ! CHECK: store float
28 | I = C ! CHECK: fptosi float
29 | CONTINUE ! CHECK: store i32
30 | C = X ! CHECK: store float
31 | CONTINUE ! CHECK: store float 0
32 | C = I ! CHECK: sitofp i32
33 | CONTINUE ! CHECK: store float
34 | CONTINUE ! CHECK: store float 0
35 |
36 | C = C + X
37 | C = C - I
38 |
39 | D = X ! CHECK: fpext float
40 | X = D ! CHECK: fptrunc double
41 | D = D + X ! CHECK: fadd double
42 | I = D ! CHECK: fptosi double
43 | D = I ! CHECK: sitofp i32
44 |
45 | C = D ! CHECK: fptrunc
46 | CONTINUE ! CHECK: store float 0
47 |
48 | CD = C ! CHECK: fpext float
49 | CONTINUE ! CHECK: fpext float
50 |
51 | CD = I ! CHECK: sitofp i32
52 | CONTINUE ! CHECK: store double 0
53 |
54 | END
55 |
--------------------------------------------------------------------------------
/test/CodeGen/init.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | SUBROUTINE sub()
3 | ! CHECK: @sub_r_ = {{.*}} global float
4 | ! CHECK: store float 2.500000e+00, float* @sub_r_
5 | real :: r = 2.5
6 | END
7 |
8 | PROGRAM test
9 | integer :: x = 10
10 | ! CHECK: %x = alloca i32
11 | ! CHECK: store i32 10, i32* %x
12 | END PROGRAM
13 |
--------------------------------------------------------------------------------
/test/CodeGen/intrinsicConversion.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM intrinsicconv
3 | INTEGER I
4 | REAL R
5 | COMPLEX C
6 | DOUBLE PRECISION D
7 | CHARACTER STR
8 |
9 | INTRINSIC int, real, dble, cmplx, ichar, char
10 |
11 | i = 0
12 | r = 1.0
13 | c = (1.0, 0.0)
14 | d = 1.0d0
15 |
16 |
17 | i = int(r) ! CHECK: fptosi float
18 | continue ! CHECK: store i32
19 | i = int(c) ! CHECK: fptosi float
20 | continue ! CHECK: store i32
21 |
22 | r = real(i) ! CHECK: sitofp
23 | r = real(c)
24 |
25 | d = dble(i) ! CHECK: sitofp i32
26 | d = dble(r) ! CHECK: fpext float
27 |
28 | c = cmplx(i) ! CHECK: sitofp
29 | c = cmplx(r)
30 | c = cmplx(d) ! CHECK: fptrunc
31 | c = cmplx(r, r)
32 | c = cmplx(1.0, r)
33 | c = cmplx(i, r)
34 | c = cmplx( (1.0, 2.0 ) )
35 |
36 | i = ichar('A') ! CHECK: zext i8
37 | str = char(i) ! CHECK: trunc i32
38 | i = ichar(char(66))
39 |
40 | END
41 |
--------------------------------------------------------------------------------
/test/CodeGen/mainProgram.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | ! RUN: %fort -S -o - %s
3 | ! FIXME ^ full codegen command above needs to use more explicit target(s)
4 | ! and better redirect its output
5 | PROGRAM test ! CHECK: define i32 @main
6 | CONTINUE ! CHECK: br label
7 | END PROGRAM ! CHECK: ret i32 0
8 |
--------------------------------------------------------------------------------
/test/CodeGen/memory.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort %s -O0 -S -emit-llvm -o - | FileCheck %s
2 | program p
3 | integer(kind=4), allocatable :: a(10), b(5) ! CHECK: %a = alloca i32*
4 | continue ! CHECK: %b = alloca i32*
5 | allocate(a(10), b(5)) ! CHECK: @libfort_malloc({{.*}}40)
6 | continue ! CHECK-NEXT: bitcast i8* {{.*}} to i32*
7 | continue ! CHECK-NEXT: store i32* {{.*}}, i32** %a
8 | continue ! CHECK: @libfort_malloc({{.*}}20)
9 | continue ! CHECK-NEXT: bitcast i8* {{.*}} to i32*
10 | continue ! CHECK-NEXT: store i32* {{.*}}, i32** %b
11 | deallocate(a,b) ! CHECK: load {{.*}} %a
12 | continue ! CHECK: call void @libfort_free
13 | continue ! CHECK: load {{.*}} %b
14 | continue ! CHECK: call void @libfort_free
15 | end program
16 |
--------------------------------------------------------------------------------
/test/CodeGen/module.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort %s -S -emit-llvm -o - | FileCheck %s
2 | module mod
3 | integer N ! CHECK: @__mod_MOD_n_ = internal global i32
4 | integer c ! CHECK: @__mod_MOD_c_ = internal global i32
5 | integer m
6 | parameter(m = 10) ! CHECK-NOT: @__mod_MOD_m_
7 | contains
8 | subroutine sub(x) ! CHECK: define void @__mod_MOD_sub_(i32* noalias %x)
9 | integer, intent(out) :: x
10 | x = m ! CHECK: store i32 10, i32* %x
11 | end subroutine
12 | integer function f(x) ! CHECK: define i32 @__mod_MOD_f_(i32* noalias %x)
13 | integer, intent(in) :: x
14 | c = x ! CHECK: i32* @__mod_MOD_c
15 | ! CHECK: %n = load i32, i32* @__mod_MOD_n_
16 | ! CHECK: store i32 %n, i32* %f
17 | f = N
18 | end function
19 | end module
20 |
--------------------------------------------------------------------------------
/test/CodeGen/save.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | SUBROUTINE SUB() ! CHECK: @sub_i_ = {{.*}} global i32
4 | INTEGER I ! CHECK: @sub_r_ = {{.*}} global float
5 | SAVE I ! CHECK: @foo_mat_ = {{.*}} global [16 x float]
6 | REAL :: R = 2.5 ! CHECK: @func_arr_ = {{.*}} global [10 x i32]
7 |
8 | I = 0 ! CHECK: store i32 0, i32* @sub_i_
9 | END
10 |
11 | SUBROUTINE FOO(I)
12 | INTEGER I
13 | REAL MAT(4,4)
14 | SAVE
15 |
16 | IF(I == 0) MAT(1,1) = 42.0 ! CHECK: store float {{.*}}[16 x float]* @foo_mat_
17 | END
18 |
19 | FUNCTION FUNC(I)
20 | INTEGER I, K, FUNC
21 | INTEGER ARR(10)
22 | SAVE ARR
23 | DATA ARR / 10*0 /
24 | DATA K / 1 /
25 |
26 | ARR(I+1) = 42
27 | FUNC = ARR(I)
28 | CALL FOO(I+1)
29 | END
30 |
--------------------------------------------------------------------------------
/test/CodeGen/scalarArithmetic.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM test
3 | INTEGER X ! CHECK: alloca i32
4 | REAL Y ! CHECK: alloca float
5 | LOGICAL L ! CHECK: alloca i32
6 | DOUBLE PRECISION DP ! CHECK: alloca double
7 |
8 | X = X ! CHECK: load i32, i32*
9 | X = +X ! CHECK: load i32, i32*
10 | X = -X ! CHECK: sub i32 0
11 |
12 | X = X + X ! CHECK: add i32
13 | X = X - X ! CHECK: sub i32
14 | X = X * X ! CHECK: mul i32
15 | X = X / X ! CHECK: sdiv i32
16 |
17 | Y = Y ! CHECK: load float, float*
18 | Y = -Y ! CHECK: fneg
19 |
20 | Y = Y + Y ! CHECK: fadd float
21 | Y = Y - Y ! CHECK: fsub float
22 | Y = Y * Y ! CHECK: fmul float
23 | Y = Y / Y ! CHECK: fdiv float
24 |
25 | X = 1 + X ! CHECK: add i32 1
26 | Y = 2.5 * Y ! CHECK: fmul float 2.5
27 |
28 | L = 1 .EQ. X ! CHECK: icmp eq i32 1
29 | L = 0 .NE. X ! CHECK: icmp ne i32 0
30 | L = 42 .LE. X ! CHECK: icmp sle i32 42
31 | L = X .LT. X ! CHECK: icmp slt i32
32 | L = X .GE. X ! CHECK: icmp sge i32
33 | L = X .GT. X ! CHECK: icmp sgt i32
34 |
35 | L = 1.0 .EQ. Y ! CHECK: fcmp oeq float 1
36 | L = 0.0 .NE. Y ! CHECK: fcmp une float 0
37 | L = Y .LE. Y ! CHECK: fcmp ole float
38 | L = Y .LT. Y ! CHECK: fcmp olt float
39 | L = Y .GE. Y ! CHECK: fcmp oge float
40 | L = Y .GT. Y ! CHECK: fcmp ogt float
41 |
42 | Y = Y ** 4.0 ! CHECK: call float @llvm.pow.f32
43 | Y = Y ** 5 ! CHECK: call float @llvm.powi.f32
44 | X = X ** 2 ! CHECK: call i32 @libfort_pow_i4_i4
45 |
46 | DP = DP ! CHECK: load double, double*
47 | DP = 1.0d0 + DP ! CHECK: fadd double 1
48 | L = DP .EQ. DP ! CHECK: fcmp oeq double
49 | DP = DP ** 2 ! CHECK: call double @llvm.powi.f64
50 |
51 | END PROGRAM
52 |
--------------------------------------------------------------------------------
/test/CodeGen/scalarIntrinsicMath.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM testscalarmath
3 | INTEGER i
4 | REAL x
5 | DOUBLE PRECISION d
6 |
7 | INTRINSIC abs, mod, sign, dim
8 | INTRINSIC max, min
9 | INTRINSIC sqrt, exp, log, log10
10 | INTRINSIC sin, cos, tan
11 | INTRINSIC asin, acos, atan2
12 | INTRINSIC sinh, cosh, tanh
13 |
14 | x = 1.0
15 | i = 7
16 |
17 | i = abs(i) ! CHECK: select i1
18 | i = mod(13, i) ! CHECK: srem i32 13
19 |
20 | x = abs(x) ! CHECK: call float @llvm.fabs.f32
21 | x = mod(4.0, x) ! CHECK: frem float 4
22 | x = sign(x, x) ! CHECK: select
23 | x = dim(i, 88) ! CHECK: icmp sgt i32
24 | CONTINUE ! CHECK: sub
25 | CONTINUE ! CHECK: select
26 |
27 | x = max(x, 1.0, -7.0) ! CHECK: fcmp oge
28 | CONTINUE ! CHECK: select
29 | CONTINUE ! CHECK: fcmp oge
30 | CONTINUE ! CHECK: select
31 |
32 | x = sqrt(x) ! CHECK: call float @llvm.sqrt.f32
33 | x = exp(x) ! CHECK: call float @llvm.exp.f32
34 | x = log(x) ! CHECK: call float @llvm.log.f32
35 | x = log10(x) ! CHECK: call float @llvm.log10.f32
36 | x = sin(x) ! CHECK: call float @llvm.sin.f32
37 | x = cos(x) ! CHECK: call float @llvm.cos.f32
38 | x = tan(x) ! CHECK: call float @tanf(float
39 | x = atan2(2.0,x)! CHECK: call float @atan2f(float 2
40 |
41 | d = sin(d) ! CHECK: call double @llvm.sin.f64
42 | d = cosh(d) ! CHECK: call double @cosh(
43 | d = exp(d) ! CHECK: call double @llvm.exp.f64
44 |
45 | END
46 |
--------------------------------------------------------------------------------
/test/CodeGen/scalarIntrinsicTruncRound.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM testscalartruncround
3 | INTEGER i
4 | REAL x
5 |
6 | INTRINSIC aint, anint, nint, ceiling, floor
7 |
8 | x = 2.25
9 |
10 | x = aint(x) ! CHECK: call float @llvm.trunc.f32
11 | x = -1.75
12 | x = anint(x) ! CHECK: call float @llvm.rint.f32
13 | x = 3.75
14 | i = nint(x) ! CHECK: call float @llvm.rint.f32
15 | CONTINUE ! CHECK: fptosi
16 | CONTINUE ! CHECK: store i32
17 |
18 | i = ceiling(x) ! CHECK: call float @llvm.ceil.f32
19 | i = floor(x) ! CHECK: call float @llvm.floor.f32
20 |
21 | END PROGRAM
22 |
--------------------------------------------------------------------------------
/test/CodeGen/scalarLogical.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM test
3 | LOGICAL L ! CHECK: alloca i32
4 | INTEGER I
5 |
6 | L = L ! CHECK: load i32, i32*
7 | L = .NOT. L ! CHECK: xor i32
8 |
9 | L = .TRUE. .EQV. L ! CHECK: icmp eq i1 true
10 | L = .FALSE. .NEQV. L ! CHECK: icmp ne i1 false
11 |
12 | I = 5
13 |
14 | L = I .LT. 10 .AND. I .GT. 1
15 | CONTINUE ! CHECK: icmp slt i32
16 | CONTINUE ! CHECK: br i1
17 | CONTINUE ! CHECK: load i32, i32*
18 | CONTINUE ! CHECK: icmp sgt i32
19 | CONTINUE ! CHECK: br i1
20 | CONTINUE ! CHECK: br label
21 | CONTINUE ! CHECK: br label
22 | CONTINUE ! CHECK: phi i1
23 |
24 | L = 0 .EQ. I .OR. 1 .EQ. I
25 | CONTINUE ! CHECK: icmp eq i32 0
26 | CONTINUE ! CHECK: br i1
27 | CONTINUE ! CHECK: load i32, i32*
28 | CONTINUE ! CHECK: icmp eq i32 1
29 | CONTINUE ! CHECK: br i1
30 | CONTINUE ! CHECK: br label
31 | CONTINUE ! CHECK: br label
32 | CONTINUE ! CHECK: phi i1
33 |
34 | END PROGRAM
35 |
--------------------------------------------------------------------------------
/test/CodeGen/selectcase.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM test
3 | INTEGER I, J
4 | CHARACTER (Len = 10) STR, NAME
5 | LOGICAL L
6 | I = 0
7 |
8 | SELECT CASE(I)
9 | CASE (2,3) ! CHECK: icmp eq i32
10 | J = 1 ! CHECK-NEXT: br i1
11 | CASE (-1:1) ! CHECK: icmp sle i32 -1
12 | J = 0 ! CHECK-NEXT: icmp sle i32 {{.*}}, 1
13 | continue ! CHECK-NEXT: and i1
14 | continue ! CHECK-NEXT: br i1
15 | CASE (-10:, :100) ! CHECK: icmp sle i32 -10
16 | J = -1 ! CHECK-NEXT: br i1
17 | continue ! CHECK: icmp sle i32 {{.*}}, 100
18 | CASE DEFAULT ! CHECK-NEXT: br i1
19 | J = 42
20 | END SELECT
21 |
22 | STR = 'Hello World'
23 | SELECT CASE(STR) ! CHECK: call i32 @libfort_compare_char1
24 | CASE ('Hello') ! CHECK-NEXT: icmp eq i32
25 | J = 0 ! CHECK-NEXT: br i1
26 | CASE ('A':'C', 'Foo')
27 | J = 1
28 | CASE DEFAULT
29 | J = 42
30 | END SELECT
31 |
32 | L = .true.
33 | SELECT CASE(L)
34 | CASE (.true.)
35 | J = 0
36 | CASE DEFAULT
37 | J = 42
38 | END SELECT
39 |
40 |
41 | END PROGRAM test
42 |
--------------------------------------------------------------------------------
/test/CodeGen/statementFunctions.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM test
3 | X(I) = I + 1
4 | COMPLEX A
5 | COMPLEX J
6 | J(A) = A * (1.0,1.0)
7 | CHARACTER*(5) ABC
8 | ABC() = 'VOLBE'
9 |
10 | REAL XVAL
11 | COMPLEX JVAL
12 |
13 | XVAL = X(2) ! CHECK: store float 3
14 | JVAL = J((1.0,2.0))
15 |
16 | PRINT *, ABC()
17 |
18 | END PROGRAM test
19 |
--------------------------------------------------------------------------------
/test/CodeGen/subprogram.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | SUBROUTINE SUB ! CHECK: define void @sub_()
4 | END ! CHECK: ret void
5 |
6 | SUBROUTINE SUB2(I, R, C, L) ! CHECK: define void @sub2_(i32* noalias %i, float* noalias %r, { float, float }* noalias %c, i32* noalias %l)
7 | INTEGER I
8 | REAL R
9 | COMPLEX C
10 | LOGICAL L
11 | INTEGER J
12 |
13 | J = I ! CHECK: load i32, i32* %i
14 | C = R ! CHECK: load float, float* %r
15 |
16 | IF(L) THEN ! CHECK: load i32, i32* %l
17 | J = 0
18 | END IF
19 |
20 | END ! CHECK: ret void
21 |
22 | REAL FUNCTION SQUARE(X) ! CHECK: define float @square_(float* noalias %x)
23 | REAL X ! CHECK: alloca float
24 | SQUARE = X * X
25 | RETURN ! CHECK: ret float
26 | END
27 |
28 | COMPLEX FUNCTION DOUBLE(C)
29 | COMPLEX C
30 | DOUBLE = C+C
31 |
32 | CONTINUE ! CHECK: load float, float*
33 | CONTINUE ! CHECK: load float, float*
34 | END
35 |
36 | PROGRAM test
37 | REAL R
38 | COMPLEX C
39 | PARAMETER (PI = 3.0)
40 | INTRINSIC REAL, CMPLX
41 |
42 | REAL ExtFunc
43 | EXTERNAL ExtSub, ExtSub2, ExtFunc
44 |
45 | R = SQUARE(2.0) ! CHECK: store float 2.0
46 | CONTINUE ! CHECK: call float @square_(float*
47 |
48 | R = SQUARE(R) ! CHECK: call float @square_(float*
49 | R = SQUARE(SQUARE(R))
50 |
51 | R = SQUARE(PI) ! CHECK: call float @square_(float*
52 |
53 | C = DOUBLE((1.0, 2.0)) ! CHECK: store float 1
54 | CONTINUE ! CHECK: store float 2
55 | CONTINUE ! CHECK: call {{.*}} @double_
56 | C = DOUBLE(DOUBLE(C))
57 |
58 | C = DOUBLE(CMPLX(SQUARE(R)))
59 |
60 | CALL SUB ! CHECK: call void @sub_
61 |
62 | CALL SUB2(1, 2.0, (1.0, 2.0), .false.)
63 | CONTINUE ! CHECK: store i32 1
64 | CONTINUE ! CHECK: store float 2.0
65 | CONTINUE ! CHECK: store float 1.0
66 | CONTINUE ! CHECK: store float 2.0
67 | CONTINUE ! CHECK: store i32 0
68 | CONTINUE ! CHECK: call void @sub2_
69 |
70 | R = ExtFunc(ExtFunc(1.0)) ! CHECK: call float @extfunc_(float*
71 |
72 | CALL ExtSub ! CHECK: call void @extsub_()
73 | CALL ExtSub() ! CHECK: call void @extsub_()
74 | CALL ExtSub2(R, C) ! CHECK: call void @extsub2_(float*
75 |
76 |
77 | END
78 |
--------------------------------------------------------------------------------
/test/CodeGen/systemIntrinsics.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | PROGRAM sys ! CHECK: call void @libfort_sys_init()
4 |
5 | REAL ETIME
6 | INTRINSIC ETIME
7 | REAL R_ARR(2)
8 | REAL T
9 |
10 | T = ETIME(R_ARR) ! CHECK: call float @libfort_etimef(float* {{.*}}, float*
11 |
12 | END
13 |
--------------------------------------------------------------------------------
/test/CodeGen/type.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 |
3 | program typeTest
4 |
5 | type Point
6 | sequence
7 | real x,y
8 | end type
9 |
10 | type Triangle
11 | type(Point) vertices(3)
12 | integer color
13 | end type
14 |
15 | type(Point) p ! CHECK: alloca { float, float }
16 | type(Triangle) t ! CHECK: alloca { [3 x { float, float }], i32 }
17 | type(Point) pa(3)
18 |
19 | type(Point) gen
20 | external gen
21 |
22 |
23 | p = Point(1.0,0.0)
24 | p = p ! CHECK: store { float, float } {{.*}}, { float, float }*
25 | pa(1) = p
26 | p = pa(1)
27 |
28 | p%x = 1.0
29 | p%y = p%x
30 | pa(1)%x = p%y
31 |
32 | ! FIXME: t%vertices(1) = p
33 | t%color = 0
34 |
35 | p = gen()
36 |
37 | end program
38 |
39 | subroutine sub(p) ! CHECK: define void @sub_({ float, float }* noalias
40 | type Point
41 | sequence
42 | real x,y
43 | end type
44 | type(Point) p
45 | p%x= 1.0
46 | end
47 |
48 | function func(i) ! CHECK: define {{.*}} @func_(i32* noalias
49 | integer i
50 | type Point
51 | sequence
52 | real x,y
53 | end type
54 | type(Point) func
55 | func = Point(i, 4.25)
56 | end
57 |
58 | subroutine foo
59 |
60 | type Point
61 | real x,y
62 | end type
63 |
64 | type(Point) p1, p2
65 |
66 | data p1 / Point(1, 2) / ! CHECK: store { float, float }
67 | data p2%x, p2%y / 2.0, 4.0 / ! CHECK: store { float, float }
68 |
69 | end
70 |
--------------------------------------------------------------------------------
/test/CodeGen/unformattedWrite.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s
2 | PROGRAM test
3 |
4 | WRITE (*,*) 'Hello world!', 2, 3.5, .true., (1.0, 2.0)
5 | PRINT *, 'Hello world!'
6 |
7 | END PROGRAM
8 |
--------------------------------------------------------------------------------
/test/CodeGen/use.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort %s -S -emit-llvm -o - | FileCheck %s
2 | module m
3 | integer n ! CHECK: @__m_MOD_n_ = internal global i32
4 | contains
5 | function f(x) result(r)
6 | integer :: x
7 | integer :: r
8 | r = x * 2
9 | end function
10 | end module
11 | program p
12 | use m, the_function => f
13 | implicit none
14 | n = 4 ! CHECK: store i32 4, i32* @__m_MOD_n_
15 | n = the_function(n) ! CHECK: call i32 @__m_MOD_f_(i32* @__m_MOD_n_)
16 | print *, n
17 | end program
18 |
--------------------------------------------------------------------------------
/test/CodeGen/valueAssignment.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s | FileCheck %s
2 | PROGRAM test
3 | INTEGER X
4 | REAL Y
5 | LOGICAL L
6 | COMPLEX C
7 |
8 | PARAMETER(IC = 0)
9 | PARAMETER(RC = 1.2)
10 | PARAMETER(CC = (1.0, 2.0))
11 | PARAMETER(LC = .true. .EQV. .false.)
12 |
13 | X = 1 ! CHECK: store i32 1, i32*
14 | Y = 0.0 ! CHECK: store float 0
15 | L = .false. ! CHECK: store i32 0, i32*
16 |
17 | CONTINUE ! CHECK: getelementptr inbounds { float, float }
18 | C = (1.0, 3.0) ! CHECK: store float 1
19 | CONTINUE ! CHECK: getelementptr inbounds { float, float }
20 | CONTINUE ! CHECK: store float 3
21 |
22 | X = IC
23 | Y = RC
24 | C = CC
25 | L = LC
26 |
27 | END
28 |
--------------------------------------------------------------------------------
/test/CodeGen/where.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -emit-llvm -o - %s
2 |
3 | PROGRAM test
4 |
5 | integer i_mat(4,4), i_mat2(4,4)
6 | integer i
7 |
8 | i_mat = 0
9 | i_mat2 = 1
10 | i_mat2(1,2) = 0
11 | i_mat2(3,3) = 0
12 |
13 | where(i_mat < i_mat2)
14 | i_mat = i_mat2
15 | else where
16 | i_mat = -24
17 | end where
18 |
19 | END
20 |
--------------------------------------------------------------------------------
/test/CodeGen/x86LinuxAggregateABI.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -triple "i686-unknown-linux" -emit-llvm -o - %s | FileCheck %s
2 |
3 | complex function foo() ! CHECK: define void @foo_({ float, float }*
4 | foo = (1.0, 2.0)
5 | end
6 |
7 | complex(8) function bar() ! CHECK: define void @bar_({ double, double }*
8 | bar = 0.0
9 | end
10 |
11 | program test
12 | complex c
13 | complex(8) dc
14 |
15 | c = foo()
16 | dc = bar()
17 | end
18 |
--------------------------------------------------------------------------------
/test/CodeGen/x86_64LinuxAggregateABI.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -triple "x86_64-unknown-linux" -emit-llvm -o - %s | FileCheck %s
2 |
3 | complex function foo() ! CHECK: define <2 x float> @foo_()
4 | foo = (1.0, 2.0)
5 | end
6 |
7 | complex(8) function bar() ! CHECK: define { double, double } @bar_()
8 | bar = 0.0
9 | end
10 |
--------------------------------------------------------------------------------
/test/Driver/args.f95:
--------------------------------------------------------------------------------
1 | ! RUN: not %fort -flong-nonexistent-command-line-arg %s 2>&1 | FileCheck %s -check-prefix=NON-EXISTENT
2 |
3 | ! NON-EXISTENT: unknown argument: '-flong-nonexistent-command-line-arg'
4 |
5 |
--------------------------------------------------------------------------------
/test/Driver/lineLength.f95:
--------------------------------------------------------------------------------
1 | ! RUN: not %fort -fsyntax-only -ffree-line-length-garbage %s 2>&1 | FileCheck %s -check-prefix=VALUE
2 | ! RUN: not %fort -fsyntax-only -ffree-line-length-1parrot %s 2>&1 | FileCheck %s -check-prefix=VALUE
3 | ! RUN: not %fort -fsyntax-only -ffixed-line-length-garbage %s 2>&1 | FileCheck %s -check-prefix=VALUE
4 | ! RUN: not %fort -fsyntax-only -ffixed-line-length-1parrot %s 2>&1 | FileCheck %s -check-prefix=VALUE
5 |
6 | ! RUN: not %fort -fsyntax-only -ffixed-line-length-garbage %s 2>&1 | FileCheck %s -check-prefix=VALUE
7 | ! RUN: not %fort -fsyntax-only -ffixed-line-length-1parrot %s 2>&1 | FileCheck %s -check-prefix=VALUE
8 | ! RUN: not %fort -fsyntax-only -ffree-line-length-garbage %s 2>&1 | FileCheck %s -check-prefix=VALUE
9 | ! RUN: not %fort -fsyntax-only -ffree-line-length-1parrot %s 2>&1 | FileCheck %s -check-prefix=VALUE
10 |
11 | ! RUN: not %fort -fsyntax-only -ffree-line-length-1000000000000000000000000 %s 2>&1 | FileCheck %s -check-prefix=SIZE
12 | ! RUN: not %fort -fsyntax-only -ffixed-line-length-1000000000000000000000000 %s 2>&1 | FileCheck %s -check-prefix=SIZE
13 |
14 | ! RUN: not %fort -fsyntax-only -ffixed-line-length-1000000000000000000000000 %s 2>&1 | FileCheck %s -check-prefix=SIZE
15 | ! RUN: not %fort -fsyntax-only -ffree-line-length-1000000000000000000000000 %s 2>&1 | FileCheck %s -check-prefix=SIZE
16 |
17 | ! VALUE: invalid value
18 | ! SIZE: value '1000000000000000000000000' is too big
19 |
20 |
--------------------------------------------------------------------------------
/test/Lexer/constants.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM constants
3 | CHARACTER * 11 C ! expected-error@+1 {{missing terminating ' character}}
4 | C = 'hello world
5 | END PROGRAM constants
6 |
--------------------------------------------------------------------------------
/test/Lexer/continuation.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | & ! expected-error {{continuation character used out of context}}
3 | PROGRAM continuations
4 | & ! expected-error {{continuation character used out of context}}
5 | END PROGRAM continuations
6 |
--------------------------------------------------------------------------------
/test/Lexer/definedOperator.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM definedOperators
3 | .OP ! expected-error {{defined operator missing end '.'}}
4 | END PROGRAM definedOperators
5 |
--------------------------------------------------------------------------------
/test/Lexer/fixedForm.f:
--------------------------------------------------------------------------------
1 | program hello
2 | C RUN: %fort -fsyntax-only %s
3 | C Comment
4 | * Another comment
5 | INT
6 | c CCc
7 | * comment
8 | $E
9 | +GER I
10 | I
11 | == 0
12 | * continued
13 | 10 end
14 |
--------------------------------------------------------------------------------
/test/Lexer/fixedForm2.f:
--------------------------------------------------------------------------------
1 | * RUN: %fort -fsyntax-only %s
2 | * RUN: %fort -fsyntax-only -ast-print %s 2>&1 | FileCheck %s
3 | * an extract from chemm.f
4 | SUBROUTINE FOO(M, N, ALPHA, BETA)
5 | REAL M, N, ALPHA, BETA
6 | PARAMETER (ZERO = 0.0)
7 | PARAMETER (ONE = 1.0)
8 | *
9 | * Quick return if possible.
10 | *
11 | IF ((M.EQ.0) .OR. (N.EQ.0) .OR.
12 | + ((ALPHA.EQ.ZERO).AND. (BETA.EQ.ONE))) RETURN
13 | *
14 | * And when alpha.eq.zero.
15 | *
16 | M = N
17 | ++1.0
18 | * CHECK: m = (n+1)
19 | RETURN
20 | END
21 |
--------------------------------------------------------------------------------
/test/Lexer/fixedFormDefinedOperators.f:
--------------------------------------------------------------------------------
1 | program hello
2 | C RUN: %fort -fsyntax-only %s
3 | integer i
4 | logical l
5 | if(l . and. l) i = 2
6 | if(l . a nd . i . e q. 0) then
7 | end if
8 | end
9 |
--------------------------------------------------------------------------------
/test/Lexer/fixedFormSquash.f:
--------------------------------------------------------------------------------
1 | PROGRAMfoo
2 | C RUN: %fort -fsyntax-only %s
3 | C RUN: %fort -fsyntax-only -ast-print %s 2>&1 | FileCheck %s
4 | INTEGERI,DOI,IDO
5 | C next line is a DO statement, not DOI =
6 | C CHECK: do i = 1, 10
7 | 100 DOI=1,10
8 | ENDDO
9 | IDO=I
10 | C CHECK: do doi = 1, 10
11 | DODOI=1,10
12 | C CHECK: i = ido
13 | I=I D O
14 | ENDDO
15 | C CHECK: assign 100 to i
16 | ASSIGN100T OI
17 | IF(I==0)GOTOI
18 | E ND PRO GRAMfoo
19 |
--------------------------------------------------------------------------------
/test/Lexer/fixedFormString.f:
--------------------------------------------------------------------------------
1 | PROGRAM text
2 | C RUN: %fort -fsyntax-only %s
3 | C RUN: %fort -fsyntax-only -ast-print %s 2>&1 | FileCheck --strict-whitespace %s
4 | CHARACTER *256 MESS(09)
5 | DATA MESS(01)/
6 | .' He llo
7 | .Wo
8 | . - rld'/
9 | C CHECK: ' He lloWo - rld'
10 | DATA MESS(02)/
11 | .' Blah blah blah
12 | .Blah blah blah.'/
13 | DATA MESS(03)/
14 | .' Blah blah blah
15 | .Blah blah blah
16 | .Blah blah blah.'/
17 | DATA MESS(08)/
18 | .' ''UNKOWN'
19 | .' STATUS.'/
20 | END
21 |
--------------------------------------------------------------------------------
/test/Lexer/include.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -I%test_dir/Lexer/ < %s
2 | PROGRAM inc
3 | INCLUDE 'includedFile.inc'
4 | END PROGRAM inc
5 |
--------------------------------------------------------------------------------
/test/Lexer/includeFail.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM inc
3 | INCLUDE 22 ! expected-error {{expected 'FILENAME'}}
4 | INCLUDE '' ! expected-error {{empty filename}}
5 | INCLUDE 'thisFileDoesntExist.f95' ! expected-error {{'thisFileDoesntExist.f95' file not found}}
6 | END PROGRAM inc
7 |
--------------------------------------------------------------------------------
/test/Lexer/includedFile.inc:
--------------------------------------------------------------------------------
1 | CHARACTER (LEN=200) :: NOTASTRING
2 | NOTASTRING = 'Actually a string'
3 | PRINT *, NOTASTRING
4 |
--------------------------------------------------------------------------------
/test/Lexer/numberConstants.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 | PROGRAM constants
4 | REAL X
5 | DOUBLE PRECISION Y
6 |
7 | X = 1e+1
8 | X = 1e2
9 | X = 1E-3
10 | X = 1.0
11 | X = 1.25
12 | X = 1.5E+2
13 | X = -0.9e-4
14 |
15 | Y = 1d1
16 | Y = 2d+5
17 | Y = +3D-4
18 | Y = 0.4d4
19 | Y = -0.125D-2
20 | Y = 1.0d+2
21 | if(1.LT.2) then
22 | end if
23 |
24 | if(1.eq.2) then
25 | end if
26 |
27 | if(1.ne.2) then
28 | end if
29 |
30 | if(1. / 2. >= .5) then ! CHECK: (1/2)>=0.5
31 | end if
32 |
33 | X = 1e ! expected-error {{exponent has no digits}}
34 | Y = -2D- ! expected-error {{exponent has no digits}}
35 | END PROGRAM constants
36 |
--------------------------------------------------------------------------------
/test/Lexer/torture.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | P&
3 | &R&
4 | &O&
5 | &G&
6 | &R&
7 | &A&
8 | &M&
9 | & TORTURE
10 | ! Torture the lexer and parser.
11 | CHARACTER (LEN=256) :: A, B, C, D, E, F, G
12 |
13 | A = '&
14 | &'
15 | B = '"&
16 | &"'
17 | C = 'Hello & ! world &
18 | & ooh! here'&
19 | &'s a &
20 | ! Yo! comment here!
21 | &fugly contiua&
22 | &tion'''
23 | ! An '&' is not allowed on a line by itself or with only a comment.
24 | D = '''&
25 | &"'
26 | E = ''''
27 | F = """"
28 | G = ''&
29 | &''
30 | END PROGRAM TORTURE
31 |
--------------------------------------------------------------------------------
/test/Parser/array.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM arrtest
3 | DIMENSION I_ARR2(1,2,3,4)
4 | INTEGER I_ARR(30)
5 | REAL MATRIX(4,4)
6 | LOGICAL SET(10:20)
7 | INTEGER I_ARR2
8 | REAL, DIMENSION(2,2) :: MATRIX2
9 | INTEGER I_SCAL
10 |
11 |
12 | I_ARR(1) = 2
13 | I_ARR(2) = I_ARR(1)
14 | I_ARR(3) = 4
15 | I_ARR(4) = I_ARR(3 ! expected-error {{expected ')'}}
16 | I_ARR(4) = I_ARR( ! expected-error {{expected an expression after '('}}
17 | I_ARR(4) = I_ARR(1, ! expected-error {{expected an expression after ','}}
18 | I_ARR2(1,1,1,1) = 3
19 | I_ARR(4) = I_ARR( / ) ! expected-error {{expected an expression}}
20 | I_ARR2(1,1,1,2) = I_ARR2(1,1,1,1)
21 |
22 | I_SCAL = I_SCAL(3) ! expected-error {{unexpected '('}}
23 |
24 | MATRIX(1,1) = 0.0
25 | MATRIX(2,2) = MATRIX(1,1)
26 | ENDPROGRAM arrtest
27 |
--------------------------------------------------------------------------------
/test/Parser/arrayConstructor.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM arrtest
3 | INTEGER I_ARR(5)
4 | REAL R_ARR(6)
5 | INTEGER I
6 |
7 | I = 0
8 | I_ARR = (/ 1, 2, 3, -11, I /)
9 | R_ARR = (/ 1.0, 2.0, REAL(11), REAL(I), 2.0 * 4.0 + 6.0, 11.0 /)
10 |
11 | I_ARR = (/ 1, 2, 4, 5, 6 ! expected-error {{expected '/)'}}
12 |
13 | ENDPROGRAM arrtest
14 |
--------------------------------------------------------------------------------
/test/Parser/assignedGoto.f:
--------------------------------------------------------------------------------
1 | C RUN: %fort -fsyntax-only -verify %s
2 |
3 | PROGRAM test
4 | INTEGERI,TOI
5 | ASSIGN100TOI
6 | C FIXME: fixed-form comments
7 | C expected-error@+1 {{expected 'to'}}
8 | ASSIGN100
9 | TO I = 1
10 | 100 CONTINUE
11 | E ND PRO GRAMt e s t
12 |
13 |
--------------------------------------------------------------------------------
/test/Parser/assignedGoto.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM gototest
3 | INTEGER I
4 | INTEGER DEST
5 | REAL R
6 |
7 | 10 I = 0
8 | 20 R = 1.0
9 | ASSIGN 10 TO DEST
10 |
11 | ASSIGN TO DEST ! expected-error {{expected statement label after 'ASSIGN'}}
12 | ASSIGN 10 DEST ! expected-error {{expected 'to'}}
13 | ASSIGN 10 TO 2 ! expected-error {{expected identifier}}
14 |
15 | GO TO DEST
16 | GOTO DEST (10)
17 | GO TO DEST (10, 20)
18 |
19 | GO TO DEST (X) ! expected-error {{expected statement label}}
20 | GOTO DEST (10, 'WRONG') ! expected-error {{expected statement label}}
21 | GO TO DEST (10 ! expected-error {{expected ')'}}
22 |
23 | END PROGRAM
24 |
--------------------------------------------------------------------------------
/test/Parser/assignedGotoImplicitDecl.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM gototest
3 |
4 | 10 CONTINUE
5 | ASSIGN 10 TO I
6 |
7 | END PROGRAM
8 |
9 | subroutine foo
10 | implicit none
11 | 10 CONTINUE
12 | ASSIGN 10 TO I ! expected-error {{use of undeclared identifier 'i'}}
13 | end
14 |
--------------------------------------------------------------------------------
/test/Parser/call.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | PROGRAM test
4 | EXTERNAL SUB
5 | EXTERNAL FUNC
6 |
7 | CALL SUB
8 | CALL SUB()
9 | CALL FUNC(1,2)
10 |
11 | CALL 22 ! expected-error {{expected identifier}}
12 |
13 | CALL FUNC(1,2 ! expected-error {{expected ')'}}
14 | CALL FUNC 1,2) ! expected-error {{expected '('}}
15 | END
16 |
--------------------------------------------------------------------------------
/test/Parser/characterSubstring.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM charsubstring
3 | CHARACTER (LEN=16) :: C
4 | CHARACTER * 10 C_ARR
5 | DIMENSION C_ARR(4)
6 |
7 | C = 'HELLO'
8 | C = 'HELLO'(1:3)
9 | C = 'HELLO'(1:4 ! expected-error {{expected ')'}}
10 | C = 'HELLO'(1 4) ! expected-error {{expected ':'}}
11 | C = 'HELLO'(:)
12 | C = 'HELLO'(2:)
13 | C = 'HELLO'(:3)
14 |
15 | C = C(1:2)
16 | C = C(:)
17 | C = (C(2:))
18 | C = C(1 8) ! expected-error {{expected ':'}}
19 | C = C(:(5+2) ! expected-error {{expected ')'}}
20 | C = C(: :: ! expected-error {{expected an expression}}
21 | continue ! expected-error@-1 {{expected ')'}}
22 | C = C( :: : ) ! expected-error {{expected an expression}}
23 |
24 | C_ARR(1) = C
25 | C_ARR(2) = C_ARR(1)(1:)
26 | C_ARR(3)(1:3) = (C_ARR(2)(:))
27 |
28 | ENDPROGRAM charsubstring
29 |
--------------------------------------------------------------------------------
/test/Parser/common.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | program test
4 | integer x,y,z,w,i,j,k
5 | real r
6 |
7 | common x,y, /a/ z, /w/ w
8 | common /a/ i(10,-5:8)
9 | common // j,k
10 | common / / r
11 |
12 | common /a/ ! expected-error {{expected identifier}}
13 | common ! expected-error {{expected identifier}}
14 |
15 | end program
16 |
17 | subroutine sub1
18 | integer i
19 | common /a/i
20 | save /a/
21 | end
22 |
--------------------------------------------------------------------------------
/test/Parser/complexConstants.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM constants
3 | COMPLEX C
4 | PARAMETER (ZERO = 0.0)
5 |
6 | C = (1.0,2.0)
7 | C = (2.343,1E-4)
8 | C = (4,3)
9 | C = (-1,0)
10 | C = (ZERO, ZERO)
11 |
12 | C = (1, .false.) ! expected-error {{expected an integer or a real constant expression}}
13 | END PROGRAM constants
14 |
--------------------------------------------------------------------------------
/test/Parser/computedGoto.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | PROGRAM gototest
3 | INTEGER I
4 |
5 | 10 I = 0
6 | 20 GOTO(10) I
7 | GOTO(10, 20) 3-1
8 | 30 I = 3
9 | GOTO(10, 20, 30) I
10 |
11 | END PROGRAM
12 |
--------------------------------------------------------------------------------
/test/Parser/continue.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | PROGRAM contest
3 | CONTINUE
4 | END PROGRAM contest
5 |
--------------------------------------------------------------------------------
/test/Parser/data.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM datatest
3 | INTEGER I, J, K
4 | REAL X,Y,Z, A, B
5 | INTEGER I_ARR(10)
6 |
7 | DATA I / 1 /
8 | DATA J, K / 2*42 /
9 |
10 | DATA X Y / 1, 2 / ! expected-error {{expected '/'}}
11 |
12 | DATA X, Y / 1 2 / ! expected-error {{expected '/'}}
13 |
14 | DATA A/1/,B/2/
15 |
16 | DATA ! expected-error {{expected an expression}}
17 |
18 | ! FIXME: sema
19 | !DATA (I_ARR(I), I = 1,10) / 10*0 /
20 |
21 | END PROGRAM
22 |
--------------------------------------------------------------------------------
/test/Parser/dimension.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM dimtest
3 |
4 | DIMENSION X(1,2,3,4,5)
5 | INTEGER X
6 |
7 | INTEGER Y, Z, W
8 | DIMENSION Y(20), Z(10)
9 |
10 | DIMENSION W(20 ! expected-error {{expected ')'}}
11 |
12 | REAL A, B, C
13 |
14 | DIMENSION A(1,2) B(3,4) ! expected-error {{expected ','}}
15 |
16 | ENDPROGRAM
17 |
--------------------------------------------------------------------------------
/test/Parser/do.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM dotest
3 | INTEGER I
4 | REAL R
5 | REAL x
6 |
7 | R = 1.0
8 | DO 10 I = 1,10
9 | R = I * R
10 | 10 CONTINUE
11 |
12 | R = 0.0
13 | DO 20 I = 1,10,2
14 | 20 R = R + I
15 |
16 | DO 30 'V' = 1,100,5 ! expected-error {{expected identifier}}
17 | R = R - I
18 | 30 CONTINUE
19 |
20 | DO 40 I 1,100 ! expected-error {{expected '='}}
21 | 40 R = R * 1
22 |
23 | DO 50 I = 1 100 ! expected-error {{expected ','}}
24 | R = R + I
25 | 50 CONTINUE
26 |
27 | DO 60 I = ! expected-error {{expected an expression after '='}}
28 | 60 CONTINUE
29 |
30 | DO 70 I = 1, ! expected-error {{expected an expression after ','}}
31 | 70 CONTINUE
32 |
33 | DO 80 I = 1,3, ! expected-error {{expected an expression after ','}}
34 | 80 CONTINUE
35 |
36 | DO 90 I = ! expected-error {{expected an expression after '='}}
37 | 1 , 4 ! expected-error {{}}
38 | 90 CONTINUE
39 |
40 | DO 100 I = 1, ! expected-error {{expected an expression after ','}}
41 | I ! expected-error {{expected '='}}
42 | 100 CONTINUE
43 |
44 | DO I = 1,10
45 | R = 0
46 | END DO
47 |
48 | DO I = 1,10,2
49 | R = R + I
50 | ENDDO
51 |
52 | DO x I = 1,2 ! expected-error {{expected '='}}
53 | END DO
54 |
55 | DO 200,I = 1,5
56 | 200 CONTINUE
57 |
58 | DO,I=1,5
59 | ENDDO
60 |
61 | DO,WHILE(.false.)
62 | END DO
63 |
64 | END PROGRAM
65 |
--------------------------------------------------------------------------------
/test/Parser/doImplicitDecl.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM dotest
3 | REAL R
4 | DO 10 I = 1,10
5 | R = I * R
6 | 10 CONTINUE
7 | END
8 |
9 | subroutine foo
10 | implicit none
11 | do i = 1,10 ! expected-error {{use of undeclared identifier 'i'}}
12 | end do
13 | end
14 |
--------------------------------------------------------------------------------
/test/Parser/doRecovery.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM dotest
3 | integer i
4 |
5 | ! The do statement must be processed no matter what, as we want to match the end do
6 |
7 | do 'a' = 1, 10 ! expected-error {{expected identifier}}
8 | end do
9 |
10 | do i 1,10 ! expected-error {{expected '='}}
11 | end do
12 |
13 | do i = ,10 ! expected-error {{expected an expression}}
14 | end do
15 |
16 | do i = 1 ! expected-error {{expected ','}}
17 | end do
18 |
19 | do i = 1, ! expected-error {{expected an expression after ','}}
20 | end do
21 |
22 | do while( ! expected-error {{expected an expression after '('}}
23 | end do
24 |
25 | END
26 |
--------------------------------------------------------------------------------
/test/Parser/double.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | PROGRAM doubletest
3 | IMPLICIT NONE
4 | DOUBLE PRECISION DBL
5 | DOUBLE COMPLEX DC
6 |
7 | END PROGRAM
8 |
--------------------------------------------------------------------------------
/test/Parser/dynamicAssociation.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify %s
2 | program a
3 | ! TODO defferred shape
4 | integer, allocatable :: a(10), b(10, 10), c(10,10,10)
5 | allocate(8) ! expected-error {{expected identifier}}
6 | allocate(a(10), ! expected-error {{expected identifier}}
7 | allocate(b(10,10) ! expected-error {{expected ')'}}
8 | allocate(a) ! expected-error {{expected '('}}
9 | continue ! expected-error@-1 {{expected array specification}}
10 | allocate(a(10))
11 | allocate(b(10), c(10, 10, 10))
12 | deallocate(.5) ! expected-error {{expected identifier}}
13 | deallocate(c ! expected-error {{expected ')'}}
14 | deallocate(a,) ! expected-error {{expected identifier}}
15 | deallocate(a)
16 | end program
17 |
--------------------------------------------------------------------------------
/test/Parser/empty.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | PROGRAM test
3 | END PROGRAM test
4 |
--------------------------------------------------------------------------------
/test/Parser/end.f:
--------------------------------------------------------------------------------
1 | * RUN: %fort -fsyntax-only %s
2 | * RUN: %fort -fsyntax-only -ast-print %s 2>&1 | FileCheck %s
3 |
4 | PROGRAM D
5 | * CHECK: endd = 0
6 | INTEGER ENDD
7 | ENDD = 0
8 | END D
9 |
--------------------------------------------------------------------------------
/test/Parser/equivalence.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -verify -fsyntax-only < %s
2 |
3 | PROGRAM equivtest
4 | REAL A, B
5 | EQUIVALENCE (A,B)
6 | INTEGER I, J, K, M, N, O(3)
7 | EQUIVALENCE (A, I), (B, K)
8 |
9 | EQUIVALENCE (I,J ! expected-error {{expected ')'}}
10 | EQUIVALENCE (M, N) (M, O(1)) ! expected-error {{expected ','}}
11 |
12 | END
13 |
--------------------------------------------------------------------------------
/test/Parser/exitCycle.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | PROGRAM test
3 |
4 | do i = 1,10
5 | exit
6 | end do
7 |
8 | outer: do i = 1,10
9 | inner: do j = 1, 10
10 | cycle outer
11 | end do inner
12 | exit outer
13 | end do outer
14 |
15 | END
16 |
--------------------------------------------------------------------------------
/test/Parser/expressions.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 | PROGRAM expressions
4 | REAL x,y,z,w
5 | LOGICAL l
6 |
7 | X = 2.0
8 | y = 1.0
9 | Z = 2.0
10 | W = 3.0
11 |
12 | x = x + y-z + w ! CHECK: (((x+y)-z)+w)
13 | x = x+y * Z ! CHECK: (x+(y*z))
14 | x = x * y + z ! CHECK: ((x*y)+z)
15 | x = (x + Y) * z ! CHECK: ((x+y)*z)
16 | x = x * y ** z ! CHECK: (x*(y**z))
17 | x = x + y ** z / w ! CHECK: (x+((y**z)/w))
18 | x = x+y ** (z / w) ! CHECK: (x+(y**(z/w)))
19 |
20 | x = (X + y) * z - w ! CHECK: (((x+y)*z)-w)
21 | x = x + y * -z ! CHECK: (x+(y*(-z)))
22 |
23 | l = x + y .EQ. z ! CHECK: ((x+y)==z)
24 | l = x / y .LT. z ! CHECK: ((x/y)(z**w))
26 |
27 | x = x
28 | x = (x)
29 | x = ( 2 () 3 ! expected-error {{expected ')'}}
30 | x = (1, ) ! expected-error {{expected an expression}}
31 | x = (3 ! expected-error {{expected ')'}}
32 |
33 | x = ! expected-error {{expected an expression after '='}}
34 |
35 | ENDPROGRAM expressions
36 |
--------------------------------------------------------------------------------
/test/Parser/external.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM exttest
3 | EXTERNAL FUNC, FUNC2
4 |
5 | EXTERNAL X Y ! expected-error {{expected ','}}
6 | EXTERNAL 'ABS' ! expected-error {{expected identifier}}
7 | EXTERNAL ZZ, &
8 | MM, ! expected-error {{expected identifier}}
9 |
10 | ! FIXME: move error location to after vv
11 | EXTERNAL VV &
12 | NN ! expected-error {{expected ','}}
13 |
14 | END PROGRAM
15 |
--------------------------------------------------------------------------------
/test/Parser/fixedForm.f95:
--------------------------------------------------------------------------------
1 | C RUN: %fort -ffixed-form -fsyntax-only < %s
2 |
3 | program test
4 | int eg er ii, i
5 | i = i i
6 | end program
7 |
--------------------------------------------------------------------------------
/test/Parser/fixedFormDo.f:
--------------------------------------------------------------------------------
1 | C RUN: %fort -fsyntax-only %s
2 | C RUN: %fort -fsyntax-only -ast-print %s 2>&1 | FileCheck %s
3 | PROGRAM test
4 | INTEGERNE,DOI(10),DONE,DOWHILE,DOWHILEI,WHILEI
5 | DOI=1,10
6 | ENDDO
7 | C CHECK: done = 1
8 | DONE=1
9 | C CHECK: done = (1+2)
10 | DO NE =1+2
11 | C CHECK: do 100 i = 1, 10
12 | DO100I=1,10
13 | C CHECK: done = 2
14 | 100 DON E = 2
15 | C CHECK: do done = 1, 10
16 | DODONE=1,10
17 | ENDDO
18 |
19 | C CHECK: dowhile = 33
20 | DOW H ILE=33
21 | C CHECK: dowhilei = 1
22 | DOWHILEI =1
23 | DOWHILE(.true.)
24 | ENDDO
25 |
26 | DOWHILEI=1,10
27 | ENDDO
28 |
29 | C CHECK: doi(1) = 1
30 | DOI(1) = 1
31 | DOI(2) = 2
32 |
33 | E ND PRO GRAMt e s t
34 |
--------------------------------------------------------------------------------
/test/Parser/fixedFormExitCycle.f:
--------------------------------------------------------------------------------
1 | * RUN: %fort -fsyntax-only %s
2 | PROGRAM test
3 | doi=1,10
4 | exit
5 | enddo
6 | outer:doi=1,10
7 | inner:doj=1,10
8 | exitouter
9 | enddoinner
10 | cycleouter
11 | enddoouter
12 | END
13 |
--------------------------------------------------------------------------------
/test/Parser/fixedFormFunction.f:
--------------------------------------------------------------------------------
1 | * RUN: %fort -fsyntax-only %s
2 | * RUN: %fort -fsyntax-only -ast-print %s 2>&1 | FileCheck %s
3 | LOGICALFUNCTIONFOO()
4 | * CHECK: foo = false
5 | FOO = .false.
6 | RETURN
7 | END
8 |
9 | IN T EGE R(Kind=8) F U N CTIONB A R 2()
10 | END
11 |
12 | LOGICAL(2)FUNCTIONBAR()
13 | C CHECK: bar = logical(true,Kind=2)
14 | BAR = .true.
15 | RETURN
16 | END
17 |
--------------------------------------------------------------------------------
/test/Parser/fixedFormLength.f:
--------------------------------------------------------------------------------
1 | * RUN: %fort -fsyntax-only -ffixed-line-length-90 %s
2 | * RUN: %fort -fsyntax-only -ffixed-line-length-0 %s
3 | * RUN: %fort -fsyntax-only -ffixed-line-length-none %s
4 | * RUN: not %fort -fsyntax-only -ffixed-line-length-50 %s 2>&1 | FileCheck %s -check-prefix=LINE-LENGTH
5 | * RUN: not %fort -fsyntax-only %s 2>&1 | FileCheck %s -check-prefix=LINE-LENGTH
6 |
7 | PROGRAM test
8 | CHARACTER *72 STR
9 | * LINE-LENGTH: expected '/'
10 | DATA STR/'abcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyz'/
11 | END
12 |
--------------------------------------------------------------------------------
/test/Parser/fixedFormNamedConstructs.f:
--------------------------------------------------------------------------------
1 | * RUN: %fort -fsyntax-only %s
2 | PROGRAM test
3 | c:DOI=1,10
4 | ENDDOc
5 | b:DOWHILE(.false.)
6 | ENDDOb
7 | a:IF(.true.)THEN
8 | ELSEIF(.false.)THENa
9 | ELSEa
10 | ENDIFa
11 | END
12 |
--------------------------------------------------------------------------------
/test/Parser/fixedif.f:
--------------------------------------------------------------------------------
1 | * RUN: %fort -fsyntax-only %s
2 | * RUN: %fort -fsyntax-only -ast-print %s 2>&1 | FileCheck %s
3 | PROGRAM iftest
4 | * an implicit integer declaration.
5 | * CHECK: ifatal = 0
6 | IFATAL = 0
7 | * an if statement
8 | IF(.FALSE.)IFATAL=0
9 | IF(.true.)THEN
10 | IFATAL=0
11 | ELSEIF(.false.)THEN
12 | IFATAL=1
13 | ENDIF
14 | END
15 |
--------------------------------------------------------------------------------
/test/Parser/format.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM formattest
3 |
4 | 1000 FORMAT (A)
5 | 1001 FORMAT (I1, ' string ', A2)
6 | 1002 FORMAT (JK) ! expected-error {{'JK' isn't a valid format descriptor}}
7 | 1003 FORMAT (A, I1A2) ! expected-error {{invalid ending for a format descriptor}}
8 | 1004 FORMAT (I) ! expected-error {{expected an integer literal constant after 'I'}}
9 | 1005 FORMAT (I1.) ! expected-error {{expected an integer literal constant after '.'}}
10 | 1006 FORMAT ('Hello ', A)
11 | 1007 FORMAT (1X, 'String', 1X)
12 | 1008 FORMAT (X, 'String', 2X) ! expected-error {{expected an integer literal constant before 'X'}}
13 | 1009 FORMAT (1) ! expected-error {{expected a format descriptor}}
14 | 1010 FORMAT (F1.1, E1.1, G1.1, E1.1E2)
15 | 1011 FORMAT (F1) ! expected-error {{expected '.'}}
16 | 1012 FORMAT (E12.) ! expected-error {{expected an integer literal constant after '.'}}
17 | 1013 FORMAT (E1.4e) ! expected-error {{expected an integer literal constant after 'E'}}
18 | 1014 FORMAT (T1, TL20, TR99)
19 | 1015 FORMAT (T, TL2) ! expected-error {{expected an integer literal constant after 'T'}}
20 | 1016 FORMAT ('Hello', :, I1)
21 |
22 | END PROGRAM
23 |
--------------------------------------------------------------------------------
/test/Parser/freeForm.f:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -ffree-form -fsyntax-only -verify < %s
2 |
3 | program test
4 | integer ii, i
5 | i = i i ! expected-error {{expected line break or ';' at end of statement}}
6 | end program
7 |
--------------------------------------------------------------------------------
/test/Parser/freeFormLength.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -ffree-line-length-136 %s
2 | ! RUN: %fort -fsyntax-only -ffree-line-length-0 %s
3 | ! RUN: %fort -fsyntax-only -ffree-line-length-none %s
4 |
5 | ! RUN: not %fort -fsyntax-only -ffree-line-length-100 %s 2>&1 | FileCheck %s -check-prefix=LINE-LENGTH
6 | ! RUN: not %fort -fsyntax-only %s 2>&1 | FileCheck %s -check-prefix=LINE-LENGTH
7 |
8 | program test
9 | character(len=126) :: str
10 | !LINE-LENGTH: missing terminating ' character
11 | str = 'abcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyz'
12 | end program
13 |
--------------------------------------------------------------------------------
/test/Parser/goto.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM gototest
3 | INTEGER I
4 |
5 | 10 I = 0
6 | GO TO 10
7 | GOTO 10
8 |
9 | GO TO HELL ! expected-error {{use of undeclared identifier 'hell'}}
10 | GO TO 2.0 ! expected-error {{expected statement label after 'GO TO'}}
11 | END PROGRAM
12 |
--------------------------------------------------------------------------------
/test/Parser/hello_world.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | PROGRAM HELLO_WORLD
3 | CHARACTER (LEN=11) :: C
4 | C = 'hello world'
5 | PRINT *, C
6 | PRINT *, 'hello world'
7 | END PROGRAM HELLO_WORLD
8 |
--------------------------------------------------------------------------------
/test/Parser/if.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM iftest
3 | CHARACTER (LEN=11) :: C
4 | IF(1 == 1) C = "YES"
5 |
6 | IF(0 == 0) ! expected-error {{expected an executable statement}}
7 | C = "NO"
8 |
9 | IF 1 == 2) C = "NO" ! expected-error {{expected '(' after 'IF'}}
10 | IF(1 == 2 C = "NO" ! expected-error {{expected ')'}}
11 |
12 | IF( ! expected-error {{expected an expression after '('}}
13 | C == "YES") C = "NO" ! expected-error {{expected '='}} FIXME proper error
14 |
15 | IF(1 == 2) THEN
16 | C = "NO"
17 | END IF
18 |
19 | IF(3 == 3) THEN
20 | C = "MAYBE"
21 | ELSE
22 | C = "ENDOFDAYS"
23 | ENDIF
24 |
25 | IF(42 == 69) THEN
26 | C = "NOPE"
27 | ELSE IF(12 == 13) THEN
28 | C = "POSSIBLY"
29 | ELSEIF(123 == 123) THEN
30 | C = "CORRECT"
31 | PRINT *, C
32 | ELSE
33 | C = "NEVER"
34 | END IF
35 |
36 | IF(1 == 0) THEN
37 | C = "YES"
38 | ELSE IF 12 == 23) THEN ! expected-error {{expected '(' after 'ELSE IF'}}
39 | C = "NO"
40 | END IF
41 |
42 | IF(1 == 0) THEN
43 | C = "NO"
44 | ELSE IF( ! expected-error {{expected an expression after '('}}
45 | C = "NO"
46 | END IF
47 |
48 | !Here comes nesting
49 | IF(33 == 22) THEN
50 | IF(22 == 33) THEN
51 | IF(11 == 11) THEN
52 | STOP
53 | END IF
54 | ELSE
55 | PRINT *, C
56 | ENDIF
57 | END IF
58 |
59 | IF(1 == 2) THEN ! expected-note {{to match this 'if'}}
60 | C = "NO" ! expected-error@+1 {{expected 'end if'}}
61 | END PROGRAM iftest
62 |
--------------------------------------------------------------------------------
/test/Parser/ifRecovery.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM dotest
3 | integer i
4 |
5 | ! The if statement must be processed no matter what, as we want to match the end if
6 |
7 | if .true. then ! expected-error {{expected '(' after 'IF'}}
8 | end if
9 |
10 | if () then ! expected-error {{expected an expression}}
11 | end if
12 |
13 | if (.false. ! expected-error {{expected ')'}}
14 | end if
15 |
16 | if(.true.) then
17 | else if then ! expected-error {{expected '(' after 'ELSE IF'}}
18 | end if
19 |
20 | if(::) i = 0 ! expected-error {{expected an expression}}
21 |
22 | END
23 |
--------------------------------------------------------------------------------
/test/Parser/implicit.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM imptest
3 | IMPLICIT INTEGER(A)
4 | IMPLICIT REAL(B, G), COMPLEX(H)
5 | IMPLICIT INTEGER(C-D)
6 | IMPLICIT REAL(M - N)
7 |
8 | IMPLICIT REAL (0) ! expected-error {{expected a letter}}
9 | IMPLICIT REAL (X-'Y') ! expected-error {{expected a letter}}
10 | IMPLICIT REAL X ! expected-error {{expected '('}}
11 | IMPLICIT REAL (X ! expected-error {{expected ')'}}
12 |
13 | IMPLICIT REAL(Z) INTEGER(V) ! expected-error {{expected ','}}
14 |
15 | A = 33
16 | B = 44.9
17 | C = A
18 | D = C
19 | M = B
20 | N = M
21 |
22 | END PROGRAM imptest
23 |
--------------------------------------------------------------------------------
/test/Parser/implicitFunctions.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 |
4 | PROGRAM imptest
5 | integer i
6 | real func
7 | real func2
8 | real func3(10)
9 |
10 | i = 0
11 | func2 = 1
12 | i = abs(i) ! CHECK: i = abs(i)
13 | i = foo(i) ! CHECK: i = int(foo(i))
14 | i = func(i)! CHECK: i = int(func(i))
15 | i = func3(i) ! CHECK: i = int(func3(i))
16 | i = func2(i) ! expected-error {{unexpected '('}}
17 | END
18 |
--------------------------------------------------------------------------------
/test/Parser/implicitNone.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM imptest
3 | IMPLICIT NONE (V) ! expected-error {{expected line break or ';' at end of statement}}
4 | END
5 |
--------------------------------------------------------------------------------
/test/Parser/intrinsic.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM intrintest
3 | INTRINSIC INT, MOD
4 | INTRINSIC :: ABS
5 |
6 | INTRINSIC REAL DBLE ! expected-error {{expected ','}}
7 | INTRINSIC 'LLE' ! expected-error {{expected identifier}}
8 |
9 | END PROGRAM
10 |
--------------------------------------------------------------------------------
/test/Parser/minimal.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | END
3 |
--------------------------------------------------------------------------------
/test/Parser/minimalAmbiguous.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | INTEGER I
3 | I = 0
4 | END
5 |
--------------------------------------------------------------------------------
/test/Parser/module.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify %s
2 | ! RUN: %fort -fsyntax-only -verify %s -ast-print 2>&1 | FileCheck %s
3 | module e ! CHECK: module e
4 | end module ! CHECK: end module
5 | module c ! CHECK: module c
6 | contains
7 | end module ! CHECK: end module
8 | module mod ! CHECK: module mod
9 | type point
10 | real :: x, y
11 | end type
12 | ! CHECK: integer, parameter, save n = 10
13 | integer, parameter :: n = 10
14 | ! CHECK: integer m = 20
15 | integer m
16 | parameter(m = 20)
17 | contains
18 | subroutine sub(x) ! CHECK: subroutine sub(x)
19 | integer, intent(out) :: x ! CHECK: integer, intent(out) x
20 | x = 1 ! CHECK: x = 1
21 | end subroutine ! CHECK: end subroutine
22 | function r(a) ! CHECK: real function r(a)
23 | implicit none
24 | type(point), intent(in) :: a ! CHECK: type point, intent(in) a
25 | real :: r
26 | r = sqrt(a%x**2 + a%y**2)
27 | end function
28 | end module ! CHECK: end module
29 | module ! expected-error {{expected identifier after 'module'}}
30 | end
31 |
--------------------------------------------------------------------------------
/test/Parser/namedConstructs.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | PROGRAM test
3 |
4 | a: IF(.false.) THEN
5 | END IF a
6 |
7 | b: DO I = 1,10
8 | END DO b
9 |
10 | 1 c: DO WHILE(.false.)
11 | END DO c
12 |
13 | d: IF(.true.) THEN
14 | ELSE IF(.false.) THEN d
15 | ELSE d
16 | END IF d
17 |
18 | END
19 |
--------------------------------------------------------------------------------
/test/Parser/parameter.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM paramtest
3 | PARAMETER (x=0, y = 2.5, c = 'A')
4 | PARAMETER (NUM = 0.1e4)
5 | PARAMETER (CM = (0.5,-6e2))
6 |
7 | PARAMETER (Z 1) ! expected-error {{expected '='}}
8 | PARAMETER (1) ! expected-error {{expected identifier}}
9 |
10 | PARAMETER ! expected-error {{expected '('}}
11 | PARAMETER (A = 1 B = 2) ! expected-error {{expected ','}}
12 | PARAMETER (d = 33 ! expected-error {{expected ')'}}
13 | PARAMETER (chuff = 1)
14 |
15 | END PROGRAM paramtest
16 |
--------------------------------------------------------------------------------
/test/Parser/program.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM what ! expected-note {{to match this 'program'}}
3 | CONTINUE ! expected-error@+1 {{expected 'end program'}}
4 |
--------------------------------------------------------------------------------
/test/Parser/readWritePrint.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | PROGRAM test
3 |
4 | 10 FORMAT('Message= ',A)
5 |
6 | WRITE(*,*) 'Hello world'
7 | PRINT *, 'Hello world'
8 | PRINT *, 'Hello', 'world', '!'
9 | WRITE (*,10) 'Hello world'
10 | PRINT 10, 'Test'
11 | WRITE (*,20) 'now'
12 | WRITE (*, FMT=10)'then'
13 |
14 | 20 FORMAT('Future is ',A)
15 |
16 | END PROGRAM
17 |
--------------------------------------------------------------------------------
/test/Parser/recursive.f:
--------------------------------------------------------------------------------
1 | C RUN: %fort -fsyntax-only %s
2 |
3 | RECURSI VE SUB ROUTINE SU B()
4 | END
5 | RECU RSIV E FUNCTIO N F OO()
6 | END
7 |
8 | RECU RSIVE INTE GER FU NCTION FUNC()
9 | FUNC = 1
10 | END
11 |
12 | INTEGER RECURS IVE FU NCTION FUNC2()
13 | FUNC2 = 2
14 | END
15 |
16 | INTEGER(8) RECURS IVE FU NCTION FUNC3()
17 | FUNC3 = 2
18 | END
19 |
20 | RECU RSIVE INTE GER (2) FU NCTION FUNC4()
21 | FUNC4 = 1
22 | END
23 |
--------------------------------------------------------------------------------
/test/Parser/recursive.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | RECURSIVE SUBROUTINE SUB()
4 | END
5 |
6 | RECURSIVE FUNCTION FOO()
7 | END
8 |
9 | RECURSIVE INTEGER FUNCTION FUNC()
10 | FUNC = 1
11 | END
12 |
13 | INTEGER RECURSIVE FUNCTION FUNC2()
14 | FUNC2 = 2
15 | END
16 |
17 | RECURSIVE INTEGER RECURSIVE FUNCTION M() ! expected-error {{expected 'function'}}
18 | END
19 |
20 | RECURSIVE PROGRAM main ! expected-error {{expected 'function' or 'subroutine' after 'recursive'}}
21 | END
22 |
--------------------------------------------------------------------------------
/test/Parser/result.f:
--------------------------------------------------------------------------------
1 | C RUN: %fort -fsyntax-only %s
2 |
3 | FUNCTIO N F OO()RESULT(I)
4 | I=1
5 | END
6 |
--------------------------------------------------------------------------------
/test/Parser/result.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | INTEGER FUNCTION FOO() RESULT(I)
4 | END
5 |
6 | FUNCTION BAR() RESULT ! expected-error {{expected '('}}
7 | END
8 |
9 | FUNCTION FUNC() RESULT( ! expected-error {{expected identifier}}
10 | END
11 |
--------------------------------------------------------------------------------
/test/Parser/return.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 |
3 | SUBROUTINE FOO
4 | RETURN
5 | END
6 |
7 | FUNCTION BAR()
8 | BAR = 1.0
9 | RETURN
10 | END
11 |
--------------------------------------------------------------------------------
/test/Parser/save.f:
--------------------------------------------------------------------------------
1 | C RUN: %fort -fsyntax-only %s
2 | C RUN: %fort -fsyntax-only -ast-print %s 2>&1 | FileCheck %s
3 |
4 | SUBROUTINE FOO
5 | INTEGER SAVEALPHA
6 | SAVESAVEALPHA
7 | C CHECK: savealpha = 1
8 | SAVEALPHA=1
9 | C CHECK-NEXT: savebeta = real(1)
10 | SAVEBETA=1
11 | C CHECK-NEXT: savegamma = real(2)
12 | SAVEGAMMA=2
13 | END
14 |
--------------------------------------------------------------------------------
/test/Parser/save.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -verify -fsyntax-only < %s
2 |
3 | SUBROUTINE FOO
4 | INTEGER I
5 | SAVE
6 | END
7 |
8 | SUBROUTINE BAR
9 | INTEGER I, J
10 | SAVE I, J
11 | END
12 |
13 | SUBROUTINE BAM
14 | INTEGER K, L
15 | SAVE K, 11 ! expected-error {{expected identifier}}
16 | END
17 |
--------------------------------------------------------------------------------
/test/Parser/selectcase.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | PROGRAM selecttest
4 | INTEGER I
5 | SELECT CASE(1)
6 | END SELECT
7 |
8 | I = 0
9 | a: SELECT CASE(I)
10 | CASE DEFAULT a
11 | END SELECT a
12 |
13 | SELECT CASE(I)
14 | CASE (1,2)
15 | I = 1
16 | CASE (3:)
17 | I = 42
18 | END SELECT
19 |
20 | SELECT CASE(I)
21 | CASE (:1)
22 | I = -1
23 | CASE (2:6,7)
24 | I = 3
25 | CASE DEFAULT
26 | I = 0
27 | END SELECT
28 |
29 | SELECT CASE(I ! expected-error {{expected ')'}}
30 | CASE () ! expected-error {{expected an expression}}
31 | END SELECT
32 |
33 | SELECT CASE(1)
34 | I = 0 ! expected-error {{expected 'case' or 'end select' statement after 'select case' statement}}
35 | I = 1
36 | END SELECT
37 |
38 | SELECT CASE(1)
39 | SELECT CASE(2) ! expected-error {{expected 'case' or 'end select' statement after 'select case' statement}}
40 | END SELECT
41 | I = 1
42 | END SELECT
43 |
44 | END
45 |
--------------------------------------------------------------------------------
/test/Parser/statementFunctions.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM test
3 | INTEGER ARR(10)
4 | X(I) = I+2
5 | Y(A) = CMPLX(A) ** (1.0,-4.0)
6 | J() = 1.0
7 | II(J) = ARR(J)
8 | ZZ() = 1 2 3 ! expected-error {{expected line break or ';' at end of statement}}
9 | ZZK(I = 2 ! expected-error {{expected ')'}}
10 | ARR(1) = 1
11 |
12 | END PROGRAM test
13 |
--------------------------------------------------------------------------------
/test/Parser/statementTermination.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM termtest
3 | INTEGER I
4 |
5 | 2 FORMAT(A) A ! expected-error {{expected line break or ';' at end of statement}}
6 |
7 | 1 CONTINUE 11 ! expected-error {{expected line break or ';' at end of statement}}
8 | PRINT *,I 2 ! expected-error {{expected line break or ';' at end of statement}}
9 | GOTO 1 + 10 ! expected-error {{expected line break or ';' at end of statement}}
10 | ! FIXME: GOTO 1;GOTO 1
11 | IF(.false.) THEN what ! expected-error {{expected line break or ';' at end of statement}}
12 | END IF
13 | DO I = 1,10 man ! expected-error {{expected line break or ';' at end of statement}}
14 | END DO
15 | ASSIGN 1 TO I I ! expected-error {{expected line break or ';' at end of statement}}
16 |
17 | END PROGRAM termtest
18 |
--------------------------------------------------------------------------------
/test/Parser/stop.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | PROGRAM stoptest
3 | STOP
4 | END PROGRAM stoptest
5 |
--------------------------------------------------------------------------------
/test/Parser/subprogram.f:
--------------------------------------------------------------------------------
1 | C RUN: %fort -fsyntax-only %s
2 |
3 | SUBROUTINE FOO(x,y,z)
4 | EN D SUBROUTINEfoo
5 |
--------------------------------------------------------------------------------
/test/Parser/subprogram.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | SUBROUTINE FOO
4 | END
5 |
6 | SUBROUTINE BAR(X,Y)
7 | INTEGER X,Y
8 | END SUBROUTINE
9 |
10 | FUNCTION F()
11 | END
12 |
13 | REAL FUNCTION FF()
14 | END
15 |
16 | FUNCTION F2(X,Y)
17 | REAL X,Y
18 | X = FF( ! expected-error {{expected ')'}}
19 | END FUNCTION
20 |
21 | SUBROUTINE SUB( ! expected-error {{expected ')'}}
22 |
23 | END
24 |
25 | FUNCTION FUNC ! expected-error {{expected '('}}
26 | ENDFUNCTION
27 |
28 |
29 |
--------------------------------------------------------------------------------
/test/Parser/type.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -verify -fsyntax-only < %s
2 | PROGRAM typetest
3 | TYPE Point
4 | REAL X, Y
5 | END TYPE Point
6 |
7 | type :: pair
8 | integer(2) i,j
9 | end type pair
10 |
11 | type person
12 | character*10 name(2)
13 | character*20, dimension(5:10) :: save, skills
14 | integer age
15 | real, dimension(2,2) :: personality
16 | integer, save :: id ! expected-error {{use of 'save' attribute specifier in a type construct}}
17 | real, k :: m ! expected-error {{expected attribute specifier}}
18 | integer, dimension(3,3) rank ! expected-error {{expected '::'}}
19 | end type
20 |
21 | type foo 22 ! expected-error {{expected line break or ';' at end of statement}}
22 | integer :: k
23 | character(20) :: string
24 | character(10) str
25 | end type
26 |
27 | type sphere
28 | sequence
29 | real x, y, z, radius
30 | end type
31 |
32 | type ping
33 | integer, dimension(11) :: arr1, arr2(13)
34 | character a(10)*(5), b*8, c(1)
35 | character*10 :: p*10 ! expected-error {{duplicate character length declaration specifier}}
36 | end type
37 |
38 | type(Point) p1, p2
39 | type(sphere) sp
40 |
41 | type( ! expected-error {{expected identifier}}
42 | type(ping x ! expected-error {{expected ')'}}
43 |
44 | type params ! expected-note {{to match this 'type'}}
45 | integer i
46 | i = 22 ! expected-error {{expected 'end type'}}
47 |
48 | END PROGRAM typetest
49 |
--------------------------------------------------------------------------------
/test/Parser/variables.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | PROGRAM vartest
3 | IMPLICIT NONE
4 | INTEGER :: I
5 | REAL :: R
6 | LOGICAL :: L
7 | INTEGER I2
8 | REAL R2
9 | LOGICAL L2,L3,L4,L5
10 | DOUBLE PRECISION :: X
11 | DOUBLE PRECISION X2
12 |
13 | I = 22
14 | I = -13
15 | I = +777
16 | R = 12.0
17 | L = .TRUE.
18 | L = .false.
19 |
20 | I2 = I
21 | R2 = R
22 | L2 = L
23 |
24 | L3 = L
25 | L4 = .true.
26 | L5 = L3
27 |
28 | X = 3.4
29 | X2 = X
30 |
31 | END PROGRAM vartest
32 |
--------------------------------------------------------------------------------
/test/Parser/where.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM wheretest
3 | INTEGER I_ARR(5)
4 | REAL R_ARR(5)
5 |
6 | I_ARR = 0
7 |
8 | WHERE(I_ARR == 0) I_ARR = I_ARR + 1
9 |
10 | WHERE(I_ARR <= 1)
11 | R_ARR = I_ARR * 2.0
12 | ELSE WHERE
13 | R_ARR = 0.0
14 | END WHERE
15 |
16 | WHERE(R_ARR >= 10.0)
17 | R_ARR = I_ARR
18 | END WHERE
19 |
20 | WHERE R_ARR >= 1.0) ! expected-error {{expected '('}}
21 | R_ARR = -1.0
22 | END WHERE
23 |
24 | WHERE ( ! expected-error {{expected an expression}}
25 | R_ARR = 0.0
26 | END WHERE
27 |
28 | WHERE (I_ARR < R_ARR ! expected-error {{expected ')'}}
29 | I_ARR = R_ARR
30 | END WHERE
31 |
32 | END
33 |
--------------------------------------------------------------------------------
/test/Sema/Intrinsics/bitops.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 |
4 | PROGRAM test
5 | intrinsic iand, ieor, ior
6 | intrinsic not
7 | intrinsic btest, ibclr, ibset, ibits, ishft, ishftc
8 |
9 | integer i, i_arr(10), i_mat(4,4)
10 | integer(8) i64, i64_arr(10)
11 | logical l, l_arr(10)
12 |
13 | i = not(i)
14 | i = not(2.0) ! expected-error {{passing 'real' to parameter of incompatible type 'integer'}}
15 | i = not(i64) ! CHECK: i = int(not(i64))
16 |
17 | i = iand(i,1)
18 | i = ior(i,i) ! CHECK: i = ior(i, i)
19 | i = ieor(2,i)
20 | i = iand(i64,i) ! expected-error {{conflicting types in arguments 'i' and 'j' ('integer (Kind=8)' and 'integer')}}
21 | i = iand(i,2.0) ! expected-error {{conflicting types in arguments 'i' and 'j' ('integer' and 'real')}}
22 | i_arr = iand(i_arr,7)
23 | i64 = ior(i64,int(4,8))
24 | i = ieor(2.0,2.0) ! expected-error {{passing 'real' to parameter of incompatible type 'integer'}}
25 |
26 | l = btest(1,2)
27 | i = ibclr(i,2)
28 | i = ibset(i,2)
29 | i = ibits(i,2,2)
30 | l = btest(i64,2)
31 | i64 = ibset(i64,2)
32 | i64 = ibclr(i64,i)
33 | i = ibset(3,2.0) ! expected-error {{passing 'real' to parameter of incompatible type 'integer'}}
34 | l_arr = btest(i_arr, i_mat) ! expected-error {{conflicting shapes in arguments 'i' and 'pos' (1 dimension and 2 dimensions)}}
35 |
36 | i = ishft(i,-2)
37 | i = ishft(i,4)
38 | i = ishftc(i,i)
39 |
40 | end
41 |
--------------------------------------------------------------------------------
/test/Sema/Intrinsics/etime.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | PROGRAM test
4 | intrinsic etime
5 |
6 | real tarr(2), ttriple(3)
7 | integer iarr(2)
8 | real result
9 |
10 | result = etime(tarr)
11 | result = etime(iarr) ! expected-error {{passing 'integer array' to parameter 'tarray' of incompatible type 'real array'}}
12 | result = etime(ttriple) ! expected-error {{passing array with dimension 1 of size 3 to argument 'tarray' of incompatible size 2}}
13 |
14 | END PROGRAM
15 |
16 | SUBROUTINE FOO
17 | real etime
18 | intrinsic etime
19 |
20 | real tarr(2)
21 | result = etime(tarr)
22 | END
23 |
--------------------------------------------------------------------------------
/test/Sema/Intrinsics/numericInquiry.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | PROGRAM test
4 | intrinsic radix, digits, minexponent, maxexponent
5 | intrinsic precision, range
6 | intrinsic huge, tiny, epsilon
7 |
8 | integer i
9 | real x
10 | logical l
11 |
12 | x = radix(1.0)
13 | i = radix(0)
14 | x = digits(1.0)
15 | i = digits(1)
16 | x = minexponent(1.0)
17 |
18 | x = precision(x)
19 | x = range(x)
20 |
21 | x = huge(x)
22 | i = tiny(i)
23 | x = epsilon(x)
24 |
25 | i = maxexponent(i) ! expected-error {{passing 'integer' to parameter of incompatible type 'real'}}
26 | i = tiny(l) ! expected-error {{passing 'logical' to parameter of incompatible type 'integer' or 'real'}}
27 | x = epsilon(i) ! expected-error {{passing 'integer' to parameter of incompatible type 'real'}}
28 |
29 | END PROGRAM
30 |
--------------------------------------------------------------------------------
/test/Sema/arithmeticExpressions.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 | PROGRAM arithexpressions
4 | IMPLICIT NONE
5 | INTEGER i
6 | REAL r
7 | DOUBLE PRECISION d
8 | COMPLEX c
9 |
10 | i = 0
11 | r = 1.0
12 | d = 1.0
13 | c = (1.0,1.0)
14 |
15 | i = 1 + 1 ! CHECK: (1+1)
16 | i = i - i ! CHECK: (i-i)
17 | i = i * i ! CHECK: (i*i)
18 | i = i / i ! CHECK: (i/i)
19 | i = i ** 3 ! CHECK: (i**3)
20 |
21 | i = i ** 'pow' ! expected-error {{invalid operands to an arithmetic binary expression ('integer' and 'character')}}
22 | i = i + .false. ! expected-error {{invalid operands to an arithmetic binary expression ('integer' and 'logical')}}
23 | i = 'true' * .true. ! expected-error {{invalid operands to an arithmetic binary expression ('character' and 'logical')}}
24 |
25 | r = r + 1.0 ! CHECK: (r+1)
26 |
27 | r = r * i ! CHECK: r = (r*real(i))
28 | d = d - i ! CHECK: d = (d-real(i,Kind=8))
29 | c = c / i ! CHECK: c = (c/cmplx(i))
30 | r = r ** I ! CHECK: r = (r**i)
31 | d = d ** i ! CHECK: d = (d**i)
32 | c = c ** i ! CHECK: c = (c**i)
33 |
34 | r = i * r ! CHECK: r = (real(i)*r)
35 | r = r - r ! CHECK: r = (r-r)
36 | d = D / r ! CHECK: d = (d/real(r,Kind=8))
37 | C = c ** r ! CHECK: c = (c**cmplx(r))
38 |
39 | d = i + d ! CHECK: d = (real(i,Kind=8)+d)
40 | d = r * d ! CHECK: d = (real(r,Kind=8)*d)
41 | d = d - 2.0D1 ! CHECK: d = (d-20)
42 | d = c / d
43 |
44 | c = i + c ! CHECK: c = (cmplx(i)+c)
45 | c = r - c ! CHECK: c = (cmplx(r)-c)
46 | c = d * c
47 | c = c / c ! CHECK: (c/c)
48 | c = c ** r ! CHECK: c = (c**cmplx(r))
49 |
50 | i = +(i)
51 | i = -r ! CHECK: i = int((-r))
52 | c = -c
53 |
54 | i = +.FALSE. ! expected-error {{invalid operand to an arithmetic unary expression ('logical')}}
55 | r = -'TRUE' ! expected-error {{invalid operand to an arithmetic unary expression ('character')}}
56 |
57 |
58 | ENDPROGRAM arithexpressions
59 |
--------------------------------------------------------------------------------
/test/Sema/arrayAssignment.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | PROGRAM arrtest
4 | INTEGER I_ARR(5), I_ARR2(10), I_MAT(2,2)
5 | REAL R_ARR(5), R_ARR2(10)
6 | CHARACTER(Len = 10) STR_ARR(5)
7 |
8 | I_ARR = 1
9 | I_ARR = 2.0
10 | I_ARR = I_ARR
11 | R_ARR = I_ARR
12 | I_ARR = R_ARR
13 | STR_ARR = 'ABC'
14 |
15 | I_ARR = I_MAT ! expected-error {{conflicting shapes in an array expression (1 dimension and 2 dimensions)}}
16 | I_ARR = I_ARR2 ! expected-error {{conflicting size for dimension 1 in an array expression (5 and 10)}}
17 | R_ARR2 = I_ARR ! expected-error {{conflicting size for dimension 1 in an array expression (10 and 5)}}
18 | I_ARR = 'ABC' ! expected-error {{assigning to 'integer' from incompatible type 'character'}}
19 | R_ARR = STR_ARR ! expected-error {{assigning to 'real' from incompatible type 'character (Len=10)'}}
20 |
21 | ENDPROGRAM arrtest
22 |
23 | SUBROUTINE FOO(I_ARR)
24 | INTEGER I_ARR(*), I_ARR2(5)
25 |
26 | I_ARR2 = I_ARR ! expected-error {{use of an array expression with an implied dimension specification}}
27 | I_ARR = I_ARR2 ! expected-error {{use of an array expression with an implied dimension specification}}
28 | END
29 |
--------------------------------------------------------------------------------
/test/Sema/arrayConstructor.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | REAL FUNCTION foo()
3 | foo = 1.0
4 | END
5 | PROGRAM arrtest
6 | INTEGER I_ARR(5),I_MAT(2,2),I_ARR2(3)
7 | REAL R_ARR(7)
8 | CHARACTER(Len = 10) STR_ARR(2)
9 | INTEGER I
10 |
11 | I = 0
12 | I_ARR = (/ 1, 2, 3, -11, I /)
13 | I_ARR = (/ 1,2, (/ 3,4,5 /) /)
14 | I_ARR = (/ (/ (/ 0, 1 /), 2 /), 3, (/ 4 /) /)
15 | R_ARR = (/ 1.0, 2.0, REAL(11), REAL(I), 2.0 * 4.0 + 6.0, 1.0, foo() /)
16 | STR_ARR = (/ 'Hello', 'World' /)
17 | I_ARR = (/ I_MAT, 22 /)
18 | I_ARR = (/ 1, I_ARR2, I /)
19 |
20 | I_ARR = (/ I_ARR, I_MAT /) ! expected-error {{conflicting size for dimension 1 in an array expression (5 and 9)}}
21 |
22 | I_ARR = (/ 1, 2, 3.0, 11, 5/) ! expected-error {{expected an expression of 'integer' type ('real' invalid)}}
23 | STR_ARR = (/ 'Hello', 2 /) ! expected-error {{expected an expression of 'character' type ('integer' invalid)}}
24 |
25 | ENDPROGRAM arrtest
26 |
--------------------------------------------------------------------------------
/test/Sema/arrayIntrinsics.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | PROGRAM arrayIntrinsics
4 | intrinsic maxloc, minloc
5 |
6 | integer i_mat(10,10), i_arr(10)
7 | logical l_mat(10,10), l_mat2(2,2), l_arr(100)
8 | real r_mat(10,10)
9 | complex c_mat(10,10)
10 |
11 |
12 | integer i_pair(2), i_triple(3), i
13 |
14 | i_mat = 0
15 | r_mat = 0
16 | c_mat = 0
17 | l_mat = .true.
18 |
19 | ! MAXLOC/MINLOC
20 | ! FIXME: add support for optional dimension parameter
21 | ! FIXME: add test for invalid second parameter (diag referencing both dim and mask)
22 |
23 | i_pair = maxloc(i_mat)
24 | i_pair = minloc(r_mat)
25 |
26 | i = maxloc(i_arr, 1)
27 | i_pair = minloc(i_arr,1)
28 |
29 | i_pair = maxloc(i_mat, l_mat)
30 |
31 | i = minloc(i_arr, 2.0) ! expected-error {{passing 'real' to parameter 'dim' of incompatible type 'integer' (or parameter 'mask' of type 'logical array')}}
32 | i_pair = maxloc(i_mat, l_arr) ! expected-error {{conflicting shapes in arguments 'array' and 'mask' (2 dimensions and 1 dimension)}}
33 | i_pair = maxloc(i_mat, l_mat2) ! expected-error {{conflicting size for dimension 1 in arguments 'array' and 'mask' (10 and 2)}}
34 | i_pair = maxloc(c_mat) ! expected-error {{passing 'complex array' to parameter 'array' of incompatible type 'integer array' or 'real array'}}
35 | i_pair = minloc(l_mat) ! expected-error {{passing 'logical array' to parameter 'array' of incompatible type 'integer array' or 'real array'}}
36 | i_pair = maxloc(i) ! expected-error {{passing 'integer' to parameter 'array' of incompatible type 'integer array' or 'real array'}}
37 |
38 | i = minloc(i_mat) ! expected-error {{assigning to 'integer' from incompatible type 'integer array'}}
39 | i_triple = maxloc(i_mat) ! expected-error {{conflicting size for dimension 1 in an array expression (3 and 2)}}
40 | i_triple = maxloc(i_arr) ! expected-error {{conflicting size for dimension 1 in an array expression (3 and 1)}}
41 |
42 | END PROGRAM
43 |
--------------------------------------------------------------------------------
/test/Sema/arraySections.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-dump %s 2>&1 | FileCheck %s
3 |
4 | SUBROUTINE foo(I_ARR)
5 | INTEGER I_ARR(*)
6 | END
7 |
8 | SUBROUTINE bar(I_MAT)
9 | INTEGER I_MAT(4,*)
10 | END
11 |
12 | PROGRAM arrtest
13 | INTEGER I_ARR(5), I_MAT(4,4), I_CUBE(4,8,16)
14 |
15 | I_ARR = I_ARR(:)
16 | I_ARR(1:3) = 2
17 | I_ARR(2:) = 3
18 | I_ARR(:4) = 1
19 | I_ARR(:) = I_ARR(:)
20 |
21 | I_ARR(1:4:2) = 0
22 |
23 | I_MAT(:,:) = 0
24 | I_MAT(:,1) = 1
25 | I_MAT(2,1:1) = 2
26 | I_MAT(:, 1:4:2) = 4
27 | I_CUBE(:,1:4,1) = I_MAT
28 |
29 | CALL foo(I_ARR) ! CHECK: foo(i_arr)
30 | CALL foo(I_ARR(:))
31 | CALL foo(I_ARR(2:))
32 | CALL foo(I_ARR(1:5:2)) ! CHECK: foo(ImplicitArrayPackExpr(i_arr(1:5:2)))
33 | CALL bar(I_MAT(:,:))
34 | CALL bar(I_MAT) ! CHECK: bar(i_mat)
35 | CALL bar(I_MAT(:,1:)) ! CHECK: bar(i_mat(:, 1:))
36 | CALL bar(I_MAT(1:2,3:4)) ! CHECK: bar(ImplicitArrayPackExpr(i_mat(1:2, 3:4)))
37 | CALL bar(I_CUBE(:,:,1)) ! CHECK: bar(i_cube(:, :, 1))
38 | CALL bar(I_CUBE(:,1:4,1)) ! CHECK: bar(i_cube(:, 1:4, 1))
39 | ! FIXME: the packing below isn't required
40 | CALL bar(I_CUBE(1:4,1:4,1)) ! CHECK: bar(ImplicitArrayPackExpr(i_cube(1:4, 1:4, 1)))
41 | CALL bar(I_CUBE(1:3,1:4,1)) ! CHECK: bar(ImplicitArrayPackExpr(i_cube(1:3, 1:4, 1)))
42 | CALL bar(I_CUBE(1,1:4,1:4)) ! CHECK: bar(ImplicitArrayPackExpr(i_cube(1, 1:4, 1:4)))
43 | CALL bar(I_CUBE(:,1,1:4)) ! CHECK: bar(ImplicitArrayPackExpr(i_cube(:, 1, 1:4)))
44 | CALL foo(I_CUBE(:,1,1)) ! CHECK: foo(i_cube(:, 1, 1))
45 | CALL foo(I_CUBE(1,:,1)) ! CHECK: foo(ImplicitArrayPackExpr(i_cube(1, :, 1)))
46 |
47 | I_MAT(:) = 0 ! expected-error {{array subscript must have 2 subscript expressions}}
48 |
49 | ENDPROGRAM arrtest
50 |
--------------------------------------------------------------------------------
/test/Sema/arraySpec.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 |
4 | SUBROUTINE SUB(ARR, ARR2, ARR3)
5 | INTEGER ARR(*)
6 | INTEGER ARR2(*,*) ! expected-error {{the dimension declarator '*' must be used only in the last dimension}}
7 | REAL ARR3(10,*)
8 | INTEGER i
9 |
10 | i = ARR(1) ! CHECK: i = arr(1)
11 | i = ARR3(3,2) ! CHECK: i = int(arr3(3, 2))
12 | END
13 |
14 | SUBROUTINE BUS(L, J, A, ARR, ARR2, ARR3, ARR4, ARR5)
15 | INTEGER L, J
16 | INTEGER I
17 | REAL A
18 | REAL ARR2(L)
19 | DIMENSION ARR(L)
20 | REAL ARR3(L+J+1)
21 | REAL ARR4(L+A) ! expected-error {{array specifier requires an integer argument ('real' invalid)}}
22 | REAL ARR5(L+I) ! expected-error {{expected a constant expression}}
23 |
24 | ! ARR is REAL by implicit
25 | I = ARR(1) ! CHECK: i = int(arr(1))
26 | I = ARR2(1) ! CHECK: i = int(arr2(1))
27 | END
28 |
29 | SUBROUTINE USB(LENGTH)
30 | INTEGER LENGTH
31 | INTEGER M_ARM ! expected-note {{declared here}}
32 | DIMENSION M_ARM(*) ! expected-error {{use of dimension declarator '*' for a local variable 'm_arm'}}
33 |
34 | REAL X_ARM(LENGTH)
35 | INTEGER I
36 | I = LENGTH
37 | X_ARM(1) = 1.0
38 | END
39 |
40 | PROGRAM arrtest
41 | INTEGER I_ARR(30, 10:20, 20)
42 | INTEGER I_ARR2(I_ARR(1,2,3)) ! expected-error {{expected an integer constant expression}}
43 | INTEGER I_ARR3(.false.:2) ! expected-error {{expected an integer constant expression}}
44 |
45 | INTEGER I_ARRM(*) ! expected-error {{use of dimension declarator '*' for a local variable 'i_arrm'}}
46 | INTEGER I ! expected-note@-1 {{declared here}}
47 |
48 | ENDPROGRAM arrtest
49 |
--------------------------------------------------------------------------------
/test/Sema/arraySubscript.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM arrtest
3 | INTEGER I_ARR(30)
4 | INTEGER I_ARR2(30,20)
5 | LOGICAL L_ARR(16)
6 |
7 | I_ARR(1) = 1
8 |
9 | I_ARR(1) = I_ARR(1,1) ! expected-error {{array subscript must have 1 subscript expression}}
10 | I_ARR2(1) = I_ARR(1) ! expected-error {{array subscript must have 2 subscript expressions}}
11 |
12 | I_ARR(1) = I_ARR(I_ARR(1))
13 | I_ARR(I_ARR(I_ARR(1))) = 2
14 |
15 | I_ARR(1) = I_ARR('HELLO') ! expected-error {{expected an expression of integer type ('character' invalid)}}
16 | I_ARR(1) = I_ARR(.TRUE.) ! expected-error {{expected an expression of integer type ('logical' invalid)}}
17 | I_ARR(1) = I_ARR2(1,3.0) ! expected-error {{expected an expression of integer type ('real' invalid)}}
18 | I_ARR(1) = I_ARR((42.0,69.0)) ! expected-error {{expected an expression of integer type ('complex' invalid)}}
19 |
20 | L_ARR(1) = .false.
21 | I_ARR(5) = I_ARR(L_ARR(1)) ! expected-error {{expected an expression of integer type ('logical' invalid)}}
22 | ENDPROGRAM arrtest
23 |
--------------------------------------------------------------------------------
/test/Sema/assignedGoto.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM gototest
3 | INTEGER I
4 | INTEGER DEST
5 | REAL R
6 |
7 | 10 I = 0
8 | ASSIGN 10 TO DEST
9 |
10 | ASSIGN 20 TO DEST
11 | 20 I = 20
12 |
13 | ASSIGN 10 TO R ! expected-error {{statement requires an integer variable ('real' invalid)}}
14 |
15 | ASSIGN 666 TO DEST ! expected-error {{use of undeclared statement label '666'}}
16 |
17 | GO TO DEST (10, 20, 30)
18 | 30 GOTO DEST
19 |
20 | GO TO DEST (999) ! expected-error {{use of undeclared statement label '999'}}
21 |
22 | GOTO R ! expected-error {{statement requires an integer variable ('real' invalid)}}
23 |
24 | END PROGRAM
25 |
--------------------------------------------------------------------------------
/test/Sema/call.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | SUBROUTINE SUB(I,J)
4 | END
5 |
6 | REAL FUNCTION FOO()
7 | Foo = 1
8 | END
9 |
10 | PROGRAM test
11 | EXTERNAL FUNC
12 | INTEGER NOFUNC
13 |
14 | CALL SUB(1,2)
15 | CALL SUB ! expected-error {{too few arguments to subroutine call, expected 2, have 0}}
16 | CALL SUB(1) ! expected-error {{too few arguments to subroutine call, expected 2, have 1}}
17 | CALL SUB(1,2,3,4) ! expected-error {{too many arguments to subroutine call, expected 2, have 4}}
18 | CALL FUNC
19 | CALL IMPFUNC(1,2)
20 |
21 | CALL NOFUNC ! expected-error {{statement requires a subroutine reference (variable 'nofunc' invalid)}}
22 | CALL FOO ! expected-error {{statement requires a subroutine reference (function 'foo' invalid)}}
23 | END
24 |
--------------------------------------------------------------------------------
/test/Sema/callableArguments.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | ! NB: this test is for f77 style external arguments, not for f2003 procedure pointers
3 |
4 | SUBROUTINE SUB(F, G, H)
5 | EXTERNAL F
6 | LOGICAL G
7 | EXTERNAL G
8 | EXTERNAL H
9 | LOGICAL H
10 |
11 | CALL F(2)
12 | IF(G(3.0)) THEN
13 | END IF
14 | END
15 |
16 | SUBROUTINE F(I)
17 | END
18 |
19 | LOGICAL FUNCTION FOO(R)
20 | Foo = .true.
21 | END
22 |
23 | PROGRAM test
24 | CALL SUB(F, FOO, FOO)
25 | END
26 |
--------------------------------------------------------------------------------
/test/Sema/characterExpressions.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM charexpressions
3 | IMPLICIT NONE
4 | CHARACTER * 16 C
5 |
6 | C = 'HELLO' // 'WORLD'
7 | C = C // '!'
8 |
9 | C = C // 1 ! expected-error {{invalid operands to a character binary expression ('character (Len=16)' and 'integer')}}
10 | C = .false. // 'TRUE' ! expected-error {{invalid operands to a character binary expression ('logical' and 'character')}}
11 |
12 | ENDPROGRAM charexpressions
13 |
--------------------------------------------------------------------------------
/test/Sema/characterSpec.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | SUBROUTINE SUB(STR, STR2, STR3, STR4, STR5)
4 | CHARACTER STR*(*)
5 | CHARACTER STR2*20
6 | CHARACTER*(*) STR3
7 | CHARACTER*(10) STR4
8 | CHARACTER*(*) STR5*(*) ! expected-error {{duplicate character length declaration specifier}}
9 | END
10 |
11 | PROGRAM test
12 | PARAMETER( FOO = 11+23 )
13 | CHARACTER STR*10
14 | CHARACTER RTS*(FOO)
15 | CHARACTER STRE*(-11) ! expected-error {{expected an integer greater than 0}}
16 | CHARACTER STRING*(STR) ! expected-error {{expected an integer constant expression}}
17 | CHARACTER STR2*(*) ! expected-error {{use of character length declarator '*' for a local variable 'str2'}}
18 | CHARACTER*10 STR3*10 ! expected-error {{duplicate character length declaration specifier}}
19 | END
20 |
--------------------------------------------------------------------------------
/test/Sema/characterSubstring.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM charsubstring
3 | CHARACTER (LEN=16) :: C
4 |
5 | C = 'HELLO'(1:3)
6 | C = 'HELLO'(1:'FALSE') ! expected-error {{expected an expression of integer type ('character' invalid)}}
7 | C = 'HELLO'(1:)
8 | C = 'HELLO'(:) ! expected-error@+1 {{expected an expression of integer type ('real' invalid)}}
9 | C = C( 4.0: 3.0) ! expected-error {{expected an expression of integer type ('real' invalid)}}
10 |
11 | ENDPROGRAM charsubstring
12 |
--------------------------------------------------------------------------------
/test/Sema/common.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | program test
4 | integer x,y,z,w
5 | integer i_arr
6 | common x,y, /a/ z,w
7 | common i,r,c
8 | common i_arr(22)
9 |
10 | complex c
11 |
12 | end program
13 |
14 | program sub1
15 | dimension i(10)
16 | ! FIXME: proper diagnostic
17 | common i(10) ! expected-error {{the specification statement 'dimension' cannot be applied to the array variable 'i'}}
18 | end
19 |
20 | subroutine sub2
21 | integer i
22 | common /a/i
23 | save /a/
24 | save /b/ ! expected-error {{use of undeclared common block 'b'}}
25 | end
26 |
27 | subroutine sub3
28 | integer i
29 | common /a/i
30 | save i ! expected-error {{the specification statement 'save' cannot be applied to a variable in common block}}
31 | end
32 |
33 | subroutine sub4
34 | integer i,j
35 | common i
36 | common /a/i,j ! expected-error {{the specification statement 'common' cannot be applied to the variable 'i' more than once}}
37 | common j ! expected-error {{the specification statement 'common' cannot be applied to the variable 'j' more than once}}
38 | common /b/i ! expected-error {{the specification statement 'common' cannot be applied to the variable 'i' more than once}}
39 | end
40 |
--------------------------------------------------------------------------------
/test/Sema/computedGoto.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM gototest
3 | INTEGER I
4 |
5 | 10 I = 0
6 | 20 GOTO(10, 10) I ! expected-warning {{computed goto statement is deprecated}}
7 |
8 | continue ! expected-warning@+1 {{computed goto statement is deprecated}}
9 | GOTO (10, 20) .false. ! expected-error {{statement requires an expression of integer type ('logical' invalid)}}
10 |
11 | continue ! expected-warning@+1 {{computed goto statement is deprecated}}
12 | GOTO (10, 30, 10) 2 ! expected-error {{use of undeclared statement label '30'}}
13 |
14 | END PROGRAM
15 |
--------------------------------------------------------------------------------
/test/Sema/declarationAttributes.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 |
4 | program declAttrTest
5 |
6 | implicit none
7 |
8 | real, external :: sub ! CHECK: real subroutine sub()
9 | logical, intrinsic :: lle
10 |
11 | integer, dimension(10,10) :: i_mat
12 | real, dimension(10) :: m(20), k
13 |
14 | integer, external, external :: foo ! expected-error {{duplicate 'external' attribute specifier}}
15 | integer, dimension(20), &
16 | dimension(40) :: vector ! expected-error {{duplicate 'dimension' attribute specifier}}
17 |
18 | integer, save x ! expected-error {{expected '::'}}
19 |
20 | real :: r = 1.5
21 | save r ! expected-error {{the specification statement 'save' cannot be applied to the variable 'r' more than once}}
22 |
23 | if(lle('a','b')) then
24 | end if
25 |
26 | ! FIXME: support other attributes.
27 |
28 | end
29 |
--------------------------------------------------------------------------------
/test/Sema/dimension.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 |
4 | PROGRAM dimtest
5 | IMPLICIT NONE
6 |
7 | PARAMETER(SCALAR = 1.0) ! expected-note {{'scalar' is a parameter constant defined here}}
8 |
9 | ! FIXME: note as above?
10 | REAL TheArray(10, 20)
11 |
12 | DIMENSION X(1,2,3,4,5)
13 | INTEGER X
14 |
15 | INTEGER Y, Z
16 | DIMENSION Y(20), Z(10)
17 |
18 | DIMENSION ARR(10) ! expected-error {{use of undeclared identifier 'arr'}}
19 | DIMENSION SCALAR(20) ! expected-error {{specification statement requires a local variable or an argument}}
20 |
21 | DIMENSION TheArray(10, 20) ! expected-error {{the specification statement 'dimension' cannot be applied to the array variable 'thearray'}}
22 |
23 | REAL A
24 |
25 | DIMENSION A(10), FOO(5:100) ! expected-error {{use of undeclared identifier 'foo'}}
26 |
27 | ENDPROGRAM
28 |
29 | subroutine sub1
30 | dimension i(10)
31 | i(1) = 2.0 ! CHECK: i(1) = int(2)
32 | end
33 |
34 | subroutine sub2
35 | dimension i(10)
36 | complex i
37 | i(1) = 1 ! CHECK: i(1) = cmplx(1)
38 | end
39 |
40 | subroutine sub3
41 | real i
42 | dimension i(10)
43 | i(1) = 1 ! CHECK: i(1) = real(1)
44 | end
45 |
--------------------------------------------------------------------------------
/test/Sema/double.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 | ! This is more focused on double complex support and some
4 | ! obscure intrinsic overloads used by BLAS
5 | PROGRAM doubletest
6 | IMPLICIT NONE
7 |
8 | DOUBLE PRECISION dbl
9 | DOUBLE COMPLEX dc
10 | COMPLEX*16 dcc
11 |
12 | REAL r
13 | COMPLEX c
14 |
15 | INTRINSIC DCMPLX, CDABS, DCONJG, DIMAG
16 |
17 | r = dbl ! CHECK: r = real(dbl)
18 | c = dc ! CHECK: c = cmplx(dc)
19 | dbl = r ! CHECK: dbl = real(r,Kind=8)
20 | dc = c ! CHECK: dc = cmplx(c,Kind=8)
21 |
22 | dc = (1,2) ! CHECK: dc = cmplx((real(1),real(2)),Kind=8)
23 | ! create a double precision complex when a part has double precision
24 | dc = (1D1,2) ! CHECK: dc = (10,real(2,Kind=8))
25 | dc = (0,20D-1) ! CHECK: dc = (real(0,Kind=8),2)
26 | dc = (1d1, 25d-1) ! CHECK: dc = (10,2.5)
27 |
28 | dc = c + dc + r ! CHECK: dc = ((cmplx(c,Kind=8)+dc)+cmplx(r,Kind=8))
29 | dbl = r + dbl ! CHECK: dbl = (real(r,Kind=8)+dbl)
30 |
31 | dc = DCMPLX(r) ! CHECK: dc = dcmplx(r)
32 | r = CDABS(dc) ! CHECK: r = real(cdabs(dc))
33 | dc = DCONJG(dc) ! CHECK: dc = dconjg(dc)
34 | dc = DCONJG(c) ! expected-error{{passing 'complex' to parameter of incompatible type 'double complex'}}
35 |
36 | dbl = DIMAG(dc) ! CHECK: dbl = dimag(dc)
37 |
38 | dc = dc/dbl ! CHECK: dc = (dc/cmplx(dbl,Kind=8))
39 |
40 | dc = dcc ! CHECK: dc = cmplx(dcc,Kind=8)
41 |
42 | END PROGRAM
43 |
--------------------------------------------------------------------------------
/test/Sema/dowhile.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | PROGRAM dowhiletest
4 | DO WHILE(.true.)
5 | END DO
6 |
7 | DO WHILE(1) ! expected-error {{statement requires an expression of logical type ('integer' invalid)}}
8 | END DO
9 |
10 | IF(.true.) THEN
11 | DO WHILE(.false.) ! expected-note {{to match this 'do'}}
12 |
13 | END IF ! expected-error {{expected 'end do'}}
14 |
15 | END
16 |
--------------------------------------------------------------------------------
/test/Sema/dynamicAssociation.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 | program a
4 | implicit none
5 | integer, allocatable :: a(10), c(5) ! CHECK: integer, allocatable array a
6 | continue ! CHECK: integer, allocatable array c
7 | allocate(b(3)) ! expected-error {{use of undeclared identifier 'b'}}
8 | allocate(a(10), c(5)) ! CHECK: allocate(a(10), c(5))
9 | deallocate(b) ! expected-error {{use of undeclared identifier 'b'}}
10 | deallocate(a,c) ! CHECK: deallocate(a, c)
11 | end program
12 |
--------------------------------------------------------------------------------
/test/Sema/exitCycle.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM test
3 |
4 | do i = 1,10
5 | exit
6 | end do
7 |
8 | x: do while(.false.)
9 | cycle x
10 | end do x
11 |
12 | exit ! expected-error {{'exit' statement not in loop statement}}
13 | cycle ! expected-error {{'cycle' statement not in loop statement}}
14 |
15 | inner: do i = 1, 10
16 | cycle outer ! expected-error {{'cycle' statement not in loop statement named 'outer'}}
17 | end do inner
18 |
19 | outer: if(.false.) then
20 | exit outer ! expected-error {{'exit' statement not in loop statement named 'outer'}}
21 | end if outer
22 |
23 | END
24 |
--------------------------------------------------------------------------------
/test/Sema/external.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 | PROGRAM exttest
4 | EXTERNAL SUB
5 |
6 | INTEGER FUNC
7 | REAL FUNC2
8 | EXTERNAL FUNC, FUNC2
9 |
10 | INTEGER FUNC ! expected-error {{the return type for a function 'func' was already specified}}
11 |
12 | INTEGER F3(10) ! expected-note {{previous definition is here}}
13 | EXTERNAL F3 ! expected-error {{redefinition of 'f3'}}
14 |
15 | EXTERNAL F4
16 | COMPLEX F4
17 | REAL F4 ! expected-error {{the return type for a function 'f4' was already specified}}
18 |
19 | INTEGER I
20 | REAL R
21 | COMPLEX C
22 |
23 | I = FUNC() + FUNC2() ! CHECK: i = int((real(func())+func2()))
24 | C = F4(I) ! CHECK: c = f4(i)
25 |
26 | END PROGRAM
27 |
28 | subroutine abc1()
29 | external a
30 | external a ! expected-error {{duplicate 'external' attribute specifier}}
31 | end
32 |
33 | subroutine abc2()
34 | integer, external :: a
35 | external a ! expected-error {{duplicate 'external' attribute specifier}}
36 | end
37 |
38 | subroutine abc3()
39 | external a
40 | integer a
41 | external a ! expected-error {{duplicate 'external' attribute specifier}}
42 | end
43 |
44 | subroutine abc4()
45 | external a
46 | integer, external :: a ! expected-error {{duplicate 'external' attribute specifier}}
47 | end
48 |
49 | subroutine abc5()
50 | integer, external :: a
51 | integer, external :: a ! expected-error {{duplicate 'external' attribute specifier}}
52 | end
53 |
54 |
55 |
--------------------------------------------------------------------------------
/test/Sema/format.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM formattest
3 |
4 | 1000 FORMAT (A)
5 | FORMAT (A) ! expected-error {{'FORMAT' statement is missing a statement label}}
6 |
7 | END PROGRAM
8 |
--------------------------------------------------------------------------------
/test/Sema/formatSpecifiers.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM test
3 | INTEGER I
4 | REAL RR
5 | CHARACTER(Len = 10) FMTS
6 |
7 | 10 FORMAT('Message= ',A)
8 |
9 | ASSIGN 20 TO I
10 |
11 | FMTS = '(A)'
12 |
13 | WRITE(*,*) 'Kevin'
14 | WRITE(*,10) 'Hello world'
15 | WRITE(*,'(A)') 'World hello'
16 | WRITE(*,FMTS) 'anewstart'
17 | WRITE(*,I) 'Anyong'
18 |
19 | WRITE(*,2.0) 'zz' ! expected-error {{expected a valid format specifier instead of an expression with type 'real'}}
20 | WRITE(*,RR) 'xz' ! expected-error {{expected a valid format specifier instead of an expression with type 'real'}}
21 | WRITE(*,30) 'no' ! expected-error {{use of undeclared statement label '30'}}
22 |
23 | 20 FORMAT('Future is ',A)
24 |
25 | END PROGRAM
26 |
--------------------------------------------------------------------------------
/test/Sema/goto.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM gototest
3 | INTEGER I
4 |
5 | 10 I = 0 ! expected-note {{previous definition is here}}
6 | GO TO 10
7 |
8 | 10 I = 10 ! expected-error {{redefinition of statement label '10'}}
9 | GOTO 20
10 |
11 | 20 I = 20
12 |
13 | GO TO 30 ! expected-error {{use of undeclared statement label '30'}}
14 | END PROGRAM
15 |
--------------------------------------------------------------------------------
/test/Sema/if.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM iftest
3 | INTEGER I
4 |
5 | IF(.TRUE.) I = 0
6 |
7 | IF(2) I = 0 ! expected-error {{statement requires an expression of logical type ('integer' invalid)}}
8 |
9 | IF(.false.) THEN
10 | I = 2
11 | END IF
12 |
13 | ELSE ! expected-error {{use of 'else' outside an if construct}}
14 | ELSE IF(2 == 2) THEN ! expected-error {{use of 'else if' outside an if construct}}
15 | END IF ! FIXME: report as out of place end if?
16 |
17 | IF(2) THEN ! expected-error {{statement requires an expression of logical type ('integer' invalid)}}
18 | I = 3
19 | END IF
20 |
21 | IF(.true.) THEN
22 | I = 1
23 | ELSE IF(3 == 4) THEN
24 | I = 0
25 | ELSE IF(2.0) THEN ! expected-error {{statement requires an expression of logical type ('real' invalid)}}
26 | I = 2
27 | ELSE
28 | I = 3
29 | END IF
30 |
31 | END PROGRAM
32 |
--------------------------------------------------------------------------------
/test/Sema/immutableDoVars.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM dotest
3 | INTEGER II, K
4 |
5 | DO II = 1, 10 ! expected-note {{which is used in a do statement here}}
6 | K = II ! expected-note@-1 {{which is used in a do statement here}}
7 | II = K ! expected-error {{assignment to a do variable 'ii'}}
8 | ASSIGN 100 TO II ! expected-error {{assignment to a do variable 'ii'}}
9 |
10 | DO II = 1,10 ! expected-error {{assignment to a do variable 'ii'}}
11 | END DO ! expected-note@-6 {{which is used in a do statement here}}
12 | 100 END DO
13 |
14 | DO II = 1,10
15 | DO K = 1,10 ! expected-note {{which is used in a do statement here}}
16 | K = II ! expected-error {{assignment to a do variable 'k'}}
17 | END DO
18 | END DO
19 |
20 | I = 1
21 | K = 0
22 |
23 | END PROGRAM
24 |
--------------------------------------------------------------------------------
/test/Sema/implicit.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 | PROGRAM imptest
4 | IMPLICIT INTEGER (A, B)
5 | IMPLICIT REAL (C-E, F)
6 | IMPLICIT REAL (A) ! expected-error {{redefinition of implicit rule 'a'}}
7 | IMPLICIT INTEGER (F-G) ! expected-error {{redefinition of implicit rule in the range 'f' - 'g'}}
8 | IMPLICIT INTEGER (L, P, B) ! expected-error {{redefinition of implicit rule 'b'}}
9 | IMPLICIT INTEGER (Z-X) ! expected-error {{the range 'z' - 'x' isn't alphabetically ordered}}
10 |
11 | A = 1 ! CHECK: a = 1
12 | B = 2.0 ! CHECK: b = int(2)
13 |
14 | C = A ! CHECK: c = real(a)
15 | D = C ! CHECK: d = c
16 | E = -1.0 ! CHECK: e = (-1)
17 | F = C ! CHECK: f = c
18 |
19 | I = 0 ! CHECK: i = 0
20 | END PROGRAM imptest
21 |
--------------------------------------------------------------------------------
/test/Sema/implicitArgumentInArraySpec.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | SUBROUTINE FOO(ISIZEX,X)
4 | REAL X(ISIZEX,*)
5 | END
6 |
7 | SUBROUTINE VAR(A,X)
8 | REAL X(A,*) ! expected-error {{array specifier requires an integer argument ('real' invalid)}}
9 | END
10 |
11 | SUBROUTINE BAR(A,X)
12 | IMPLICIT NONE
13 | REAL X(A,*) ! expected-error {{the argument 'a' requires a type specifier}}
14 | END
15 |
--------------------------------------------------------------------------------
/test/Sema/implicitDefault.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only < %s
2 | ! RUN: %fort -fsyntax-only -ast-print %s 2>&1 | FileCheck %s
3 | PROGRAM imptest
4 | !Unless specified otherwise,
5 | !all variables starting with letters I, J, K, L, M and N are default INTEGERs,
6 | !and all others are default REAL
7 |
8 | I = 22 ! CHECK: i = 22
9 | J = I ! CHECK: j = i
10 | k = J ! CHECK: k = j
11 | M = 0.0 ! CHECK: m = int(0)
12 | n = -1 ! CHECK: n = (-1)
13 |
14 | R = 33.25 ! CHECK: r = 33.25
15 | Z = 1 ! CHECK: z = real(1)
16 | a = -11.23
17 | x = y ! CHECK: x = y
18 | END PROGRAM imptest
19 |
--------------------------------------------------------------------------------
/test/Sema/implicitNone.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM imptest
3 | IMPLICIT NONE
4 | IMPLICIT REAL (Y) ! expected-error {{use of 'IMPLICIT' after 'IMPLICIT NONE'}}
5 | INTEGER X
6 |
7 | X = 1
8 | Y = X ! expected-error {{use of undeclared identifier 'y'}}
9 | I = 0 ! expected-error {{use of undeclared identifier 'i'}}
10 |
11 | END PROGRAM imptest
12 |
--------------------------------------------------------------------------------
/test/Sema/init.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 | PROGRAM init
4 | INTEGER n = 1 ! expected-error {{expected line break or ';' at end of statement}}
5 | INTEGER var ! expected-note@+1 {{this expression is not allowed in a constant expression}}
6 | INTEGER :: a = var + 1 ! expected-error {{'a' must be initialized by a constant expression}}
7 | INTEGER, SAVE :: b = 2
8 | REAL, PARAMETER :: p = 3.5 ! CHECK: real, parameter, save p = 3.5
9 | REAL :: q = .false. ! expected-error {{initializing 'real' with an expression of incompatible type 'logical'}}
10 | REAL, PARAMETER :: r ! expected-error {{'r': 'parameter' attribute requires explicit initializer}}
11 | ! FIXME should this be evaluated to 4.5 at compile time?
12 | REAL, PARAMETER :: s = p + 1 ! CHECK: real, parameter, save s = (p+real(1))
13 | INTEGER :: j = 10, k = 3 + 2 ! CHECK: integer, save j = 10
14 | ! CHECK: integer, save k = (3+2)
15 |
16 | END PROGRAM init
17 |
--------------------------------------------------------------------------------
/test/Sema/intrinsic.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM intrintest
3 | INTRINSIC INT, MOD ! expected-note {{previous definition is here}}
4 |
5 | INTRINSIC FAIL ! expected-error {{invalid function name 'fail' in an intrinsic statement}}
6 | INTRINSIC ABS, SAB ! expected-error {{invalid function name 'sab' in an intrinsic statement}}
7 |
8 | INTRINSIC MOD ! expected-error {{redefinition of 'mod'}}
9 |
10 | INTEGER I
11 |
12 | I = INT(2.0)
13 | I = ABS(-3)
14 |
15 | END PROGRAM
16 |
--------------------------------------------------------------------------------
/test/Sema/logicalExpressions.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM logicalexpressions
3 | IMPLICIT NONE
4 | LOGICAL L
5 |
6 | L = .true.
7 | L = L .AND. L
8 | L = L .OR. .TRUE.
9 | L = L .EQV. L
10 | L = L .NEQV. .FALSE.
11 |
12 | L = .NOT. L
13 | L = .NOT. .TRUE.
14 |
15 | L = .FALSE. .OR. (.TRUE. .AND. .FALSE.)
16 |
17 | L = L .AND. 2 ! expected-error {{invalid operands to a logical binary expression ('logical' and 'integer')}}
18 | L = L .OR. 'HELLO' ! expected-error {{invalid operands to a logical binary expression ('logical' and 'character')}}
19 | L = 3.0 .EQV. 2.0d0 ! expected-error {{invalid operands to a logical binary expression ('real' and 'double precision')}}
20 | L = L .NEQV. (1.0,2.0) ! expected-error {{invalid operands to a logical binary expression ('logical' and 'complex')}}
21 |
22 | L = .NOT. 2 ! expected-error {{invalid operand to a logical unary expression ('integer')}}
23 | L = .NOT. (0,0) ! expected-error {{invalid operand to a logical unary expression ('complex')}}
24 |
25 | END PROGRAM
26 |
--------------------------------------------------------------------------------
/test/Sema/mainProgram.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM Bees
3 |
4 | END PROGRAM Beads ! expected-error {{expected program name 'bees'}}
5 |
--------------------------------------------------------------------------------
/test/Sema/namedConstructs.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -verify -fsyntax-only < %s
2 | PROGRAM test
3 |
4 | a: IF(.false.) THEN ! expected-note {{previous definition is here}}
5 | END IF a
6 |
7 | b: DO I = 1,10
8 | END DO b
9 |
10 | c: DO WHILE(.false.)
11 | END DO c
12 |
13 | d: IF(.true.) THEN
14 | ELSE IF(.false.) THEN d
15 | ELSE d
16 | END IF d
17 |
18 | a: IF(.true.) THEN ! expected-error {{redefinition of named construct 'a'}}
19 | END IF a
20 |
21 | bits: DO I = 1,10 ! expected-note {{to match this 'bits'}}
22 | END DO ! expected-error {{expected construct name 'bits'}}
23 |
24 | CONTINUE ! expected-note@+1 {{to match this 'y'}}
25 | y: IF(.false.) THEN ! expected-note {{to match this 'y'}}
26 | ELSE IF(.true.) THEN ! expected-error {{expected construct name 'y'}}
27 | END IF ! expected-error {{expected construct name 'y'}}
28 |
29 | gg: DO WHILE(.false.) ! expected-note {{to match this 'gg'}}
30 | END DO ha ! expected-error {{expected construct name 'gg'}}
31 |
32 | DO I=1,10
33 | END DO ha ! expected-error {{use of construct name for an unnamed construct}}
34 |
35 | foo: SELECT CASE(1)
36 | CASE (1) foo
37 | CASE DEFAULT foo
38 | END SELECT foo
39 |
40 | bar: SELECT CASE(1) ! expected-note {{to match this 'bar'}}
41 | CASE (1) ! expected-error {{expected construct name 'bar'}}
42 | CASE DEFAULT foo ! expected-error {{expected construct name 'bar'}}
43 | END SELECT bar ! expected-note@-3 {{to match this 'bar'}}
44 |
45 | END
46 |
--------------------------------------------------------------------------------
/test/Sema/parameter.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify %s
2 | PROGRAM paramtest
3 | PARAMETER (x=0, y = 2.5, c = 'A') ! expected-note {{previous definition is here}}
4 | REAL :: z
5 | PARAMETER (z = x / 2.0, w = z .EQ. 0) ! expected-note {{previous definition is here}}
6 | COMPLEX comp
7 | PARAMETER (comp = 0)
8 |
9 | INTEGER NUMBER
10 | PARAMETER (NUMBER = .false.) ! expected-error {{initializing 'integer' with an expression of incompatible type 'logical'}}
11 |
12 | REAL w ! expected-error {{redefinition of 'w'}}
13 |
14 | PARAMETER (exprs = 1 + 2 * 7) ! expected-note@+2 {{this expression is not allowed in a constant expression}}
15 |
16 | PARAMETER (fail = C(1:1)) ! expected-error {{parameter 'fail' must be initialized by a constant expression}}
17 |
18 | INTEGER VAR ! expected-note@+1 {{this expression is not allowed in a constant expression}}
19 | PARAMETER (epicFail = VAR + 1) ! expected-error {{parameter 'epicfail' must be initialized by a constant expression}}
20 |
21 | PARAMETER (x = 22) ! expected-error {{redefinition of 'x'}}
22 |
23 | x = 22 ! expected-error {{Assignment to constant 'x'}}
24 |
25 | END PROGRAM paramtest
26 |
--------------------------------------------------------------------------------
/test/Sema/readWritePrint.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM test
3 |
4 | 10 FORMAT('Message= ',A)
5 | 20 CONTINUE ! expected-note {{statement label was declared here}}
6 |
7 | WRITE (*,10) 'Hello'
8 | WRITE (*,FMT=11) 'Hello' ! expected-error {{use of undeclared statement label '11'}}
9 | WRITE (*,20) 'Hello' ! expected-error {{use of statement label format specifier which doesn't label a 'FORMAT' statement}}
10 | WRITE (*,FMT=30) 'ABC' ! expected-error {{use of statement label format specifier which doesn't label a 'FORMAT' statement}}
11 |
12 | 30 CONTINUE ! expected-note {{statement label was declared here}}
13 |
14 | END PROGRAM
15 |
--------------------------------------------------------------------------------
/test/Sema/recursive.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | RECURSIVE SUBROUTINE FOO()
4 | CALL FOO
5 | END
6 |
7 | RECURSIVE FUNCTION FACTORIAL(X)
8 | INTEGER FACTORIAL, X
9 | IF(X <= 1) THEN
10 | FACTORIAL = 1
11 | ELSE
12 | FACTORIAL = FACTORIAL(X-1)*X
13 | END IF
14 | END
15 |
16 | SUBROUTINE SUB()
17 | CALL SUB ! expected-error {{calling a non-recursive subroutine 'sub'}}
18 | END
19 |
20 | FUNCTION FUNC(I)
21 | REAL FUNC, I
22 | FUNC = FUNC(I) ! expected-error {{calling a non-recursive function 'func'}}
23 | END
24 |
25 | FUNCTION FUNC2(I) RESULT(FUNC)
26 | REAL FUNC, I
27 | FUNC = FUNC2(I) ! expected-error {{calling a non-recursive function 'func2'}}
28 | END
29 |
30 | SUBROUTINE SUB2()
31 | INTEGER I
32 | I = SUB2() ! expected-error {{invalid use of subroutine 'sub2'}}
33 | END
34 |
35 | ! FIXME: ambiguity when a function is returning an array (choose array?)
36 |
--------------------------------------------------------------------------------
/test/Sema/relationalExpressions.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 | PROGRAM relexpressions
4 | IMPLICIT NONE
5 | INTEGER i
6 | REAL r
7 | COMPLEX c
8 | LOGICAL l
9 |
10 | i = 0
11 | r = 2.0
12 | c = (1.0,1.0)
13 |
14 | l = i .LT. i ! CHECK: (ir)
18 | l = i .LE. r ! CHECK: (real(i)<=r)
19 | l = i .GE. i ! CHECK: (i>=i)
20 |
21 | l = r .LT. r ! CHECK: (r2)
23 |
24 | l = c .EQ. c ! CHECK: (c==c)
25 | l = c .NE. c ! CHECK: (c/=c)
26 | l = c .NE. r ! CHECK: (c/=cmplx(r))
27 | l = c .LE. c ! expected-error {{invalid operands to a relational binary expression ('complex' and 'complex')}}
28 | l = c .EQ. 2.0 ! CHECK: (c==cmplx(2))
29 | l = c .EQ. 2.0d-1
30 |
31 | l = 'HELLO' .EQ. 'WORLD'
32 | l = 'HELLO' .NE. 'WORLD'
33 |
34 | i = 1 .NE. 2 ! expected-error {{assigning to 'integer' from incompatible type 'logical'}}
35 | r = 2.0 .LT. 1 ! expected-error {{assigning to 'real' from incompatible type 'logical'}}
36 |
37 | l = l .EQ. l ! expected-error {{invalid operands to a relational binary expression ('logical' and 'logical')}}
38 | l = .TRUE. .NE. l ! expected-error {{invalid operands to a relational binary expression ('logical' and 'logical')}}
39 | l = l .LT. .FALSE. ! expected-error {{invalid operands to a relational binary expression ('logical' and 'logical')}}
40 |
41 | END PROGRAM
42 |
--------------------------------------------------------------------------------
/test/Sema/result.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 |
4 | INTEGER FUNCTION FOO() RESULT(I)
5 | I = 1 ! CHECK: i = 1
6 | END
7 |
8 | FUNCTION BAR() RESULT(X)
9 | X = 0.0 ! CHECK: x = 0
10 | END
11 |
12 | REAL FUNCTION FUNC() RESULT(I)
13 | I = 1.0 ! CHECK: i = 1
14 | END
15 |
16 | FUNCTION RES() RESULT(RESULT)
17 | RESULT = 1
18 | RESULT = RESULT
19 | END
20 |
21 | FUNCTION FUNC5() RESULT (X)
22 | ! CHECK: logical function
23 | LOGICAL X
24 | X = .false.
25 | END
26 |
27 | FUNCTION FUNC6() RESULT (X) ! expected-note {{previous definition is here}}
28 | LOGICAL FUNC6 ! expected-error {{redefinition of 'func6'}}
29 | END
30 |
31 | FUNCTION FUNC2() RESULT(FUNC2) ! expected-error {{use of name 'func2' for the result variable (function uses the same name)}}
32 | END
33 |
34 | FUNCTION FUNC3(RES) RESULT(RES) ! expected-error {{redefinition of 'res'}}
35 | END ! expected-note@-1 {{previous definition is here}}
36 |
37 |
--------------------------------------------------------------------------------
/test/Sema/return.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | SUBROUTINE FOO()
4 | RETURN
5 | END
6 |
7 | FUNCTION BAR()
8 | RETURN
9 | END
10 |
11 | PROGRAM main
12 | RETURN ! expected-error {{'RETURN' statement should be used inside a function or a subroutine}}
13 | END
14 |
--------------------------------------------------------------------------------
/test/Sema/returnVarDo.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 |
3 | INTEGER FUNCTION I()
4 | DO I = 1,10
5 | END DO
6 | DO I = 1,10 ! expected-note {{which is used in a do statement here}}
7 | I = 1 ! expected-error {{assignment to a do variable 'i'}}
8 | END DO
9 | END
10 |
11 | FUNCTION J()
12 | DO J = 1,10
13 | END DO
14 | END
15 |
--------------------------------------------------------------------------------
/test/Sema/save.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -verify -fsyntax-only < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 |
4 | SUBROUTINE FOO
5 | INTEGER I
6 | SAVE
7 | END
8 |
9 | SUBROUTINE BAR
10 | INTEGER I, J
11 | SAVE I, J
12 | END
13 |
14 | SUBROUTINE BAM(KA) ! expected-note {{'ka' is an argument defined here}}
15 | INTEGER KA, L
16 | PARAMETER (MK=1) ! expected-note {{'mk' is a parameter constant defined here}}
17 | SAVE L, KA ! expected-error {{specification statement requires a local variable}}
18 | SAVE MK ! expected-error {{specification statement requires a local variable}}
19 | END
20 |
21 | SUBROUTINE BAZ()
22 | INTEGER I, L
23 | SAVE I, L
24 | SAVE I ! expected-error {{the specification statement 'save' cannot be applied to the variable 'i' more than once}}
25 | END
26 |
27 | SUBROUTINE FEZ()
28 | INTEGER I, var
29 | SAVE var
30 | SAVE ! expected-error {{the specification statement 'save' cannot be applied to the variable 'var' more than once}}
31 | END
32 |
33 | subroutine sub1
34 | save i
35 | i = 1.0 ! CHECK: i = int(1)
36 | end
37 |
38 | subroutine sub2
39 | implicit none
40 | save i ! expected-error {{use of undeclared identifier 'i'}}
41 | end
42 |
--------------------------------------------------------------------------------
/test/Sema/statementFunctions.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 | PROGRAM test
4 | X(I) = I+2 ! CHECK: real((i+2))
5 | Y(A) = 1.0 ! CHECK: 1
6 |
7 | COMPLEX CC
8 | CC(M) = (0.0,1.0)
9 |
10 | CHARACTER*(10) ABC
11 | ABC(I) = 'ABC'
12 |
13 | COMPLEX ZP
14 | BAR(ZP) = AIMAG(ZP)
15 |
16 | INTEGER FOO ! expected-note@+1 {{previous definition is here}}
17 | FOO(I,I) = 1 ! expected-error {{redefinition of 'i'}}
18 |
19 | Z(A) = 'Hello' ! expected-error {{returning 'character' from a function with incompatible result type 'real'}}
20 |
21 | I = X(2) ! CHECK: i = int(x(2))
22 | I = X() ! expected-error {{too few arguments to function call, expected 1, have 0}}
23 |
24 | A = Y(2.0) ! CHECK: a = y(2)
25 |
26 | print *, ABC(1)
27 |
28 | CALL X(3) ! expected-error {{statement requires a subroutine reference (function 'x' invalid)}}
29 |
30 | END PROGRAM test
31 |
--------------------------------------------------------------------------------
/test/Sema/typeKinds.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | ! RUN: %fort -fsyntax-only -verify -ast-print %s 2>&1 | FileCheck %s
3 |
4 | REAL(Kind=8) FUNCTION A()
5 | A = 1.0 ! CHECK: a = real(1,Kind=8)
6 | END
7 |
8 | INTEGER(8) FUNCTION FF(I)
9 | INTEGER I
10 | FF = I ! CHECK: ff = int(i,Kind=8)
11 | END
12 |
13 | PROGRAM vartest
14 |
15 | REAL(Kind = 4) R
16 | REAL(Kind = 8) D
17 | REAL(Kind = 0) A ! expected-error {{invalid kind selector '0' for type 'real'}}
18 |
19 | INTEGER(4) I
20 | INTEGER(8) J
21 |
22 | COMPLEX(4) C
23 | COMPLEX(2) Chalf ! expected-error {{invalid kind selector '2' for type 'complex'}}
24 |
25 | LOGICAL(Kind= 2) L2
26 | LOGICAL(1) L1
27 |
28 | ! FIXME: add character type kinds.
29 |
30 | R = 0.0
31 | J = 1
32 | L2 = .false.
33 |
34 | D = R ! CHECK: d = real(r,Kind=8)
35 | I = J ! CHECK: i = int(j,Kind=4)
36 | L1 = L2 ! CHECK: l1 = logical(l2,Kind=1)
37 |
38 | END PROGRAM
39 |
--------------------------------------------------------------------------------
/test/Sema/use.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify %s
2 | module mod1
3 | integer :: n
4 | integer :: m
5 | integer :: s
6 | end module
7 | program p
8 | use mdl ! expected-error {{unknown module 'mdl'}}
9 | use :: mod1, only: m, grand_total => s
10 | implicit none
11 |
12 | n = 1 ! expected-error {{use of undeclared identifier 'n'}}
13 | s = 5 ! expected-error {{use of undeclared identifier 's'}}
14 | m = 2
15 | grand_total = 5
16 | end program
17 |
--------------------------------------------------------------------------------
/test/Sema/variables.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM vartest
3 | PARAMETER (Y = 2.0) ! expected-note {{previous definition is here}}
4 |
5 | PARAMETER (PI = 3.14) ! expected-note {{previous definition is here}}
6 | PARAMETER (PI = 4.0) ! expected-error {{redefinition of 'pi'}}
7 |
8 | INTEGER :: I ! expected-note {{previous definition is here}}
9 | INTEGER :: I ! expected-error {{redefinition of 'i'}}
10 |
11 | INTEGER :: X ! expected-note {{previous definition is here}}
12 | REAL :: X ! expected-error {{redefinition of 'x'}}
13 |
14 | REAL :: Y ! expected-error {{redefinition of 'y'}}
15 |
16 | i = K
17 |
18 | END PROGRAM
19 |
--------------------------------------------------------------------------------
/test/Sema/where.f95:
--------------------------------------------------------------------------------
1 | ! RUN: %fort -fsyntax-only -verify < %s
2 | PROGRAM wheretest
3 | INTEGER I_ARR(5)
4 | REAL R_ARR(5)
5 |
6 | I_ARR = 0
7 |
8 | WHERE(I_ARR == 0) I_ARR = I_ARR + 1
9 |
10 | WHERE(I_ARR <= 1)
11 | R_ARR = I_ARR * 2.0
12 | ELSE WHERE
13 | R_ARR = 0.0
14 | END WHERE
15 |
16 | WHERE(R_ARR >= 10.0)
17 | R_ARR = I_ARR
18 | END WHERE
19 |
20 | WHERE (.false.) ! expected-error {{statement requires an expression of logical array type ('logical' invalid)}}
21 | R_ARR = -1.0
22 | END WHERE
23 |
24 | WHERE(I_ARR) ! expected-error {{statement requires an expression of logical array type ('integer' invalid)}}
25 | I_ARR = 0
26 | END WHERE
27 |
28 | END WHERE ! expected-error {{use of 'end where' outside a where construct}}
29 | ELSE WHERE ! expected-error {{use of 'else where' outside a where construct}}
30 |
31 | WHERE(I_ARR == 0) PRINT *, 'Hello world' ! expected-error {{expected an assignment statement}}
32 | END WHERE ! expected-error {{use of 'end where' outside a where construct}}
33 |
34 | WHERE(I_ARR /= 0)
35 | I_ARR = 1
36 | PRINT *, 'Hello world' ! expected-error {{expected an assignment statement in a where construct}}
37 | ELSE WHERE
38 | I_ARR = 2
39 | PRINT *, 'Hello world' ! expected-error {{expected an assignment statement in a where construct}}
40 | END WHERE
41 |
42 | PRINT *, 'Hello world'
43 |
44 | WHERE(I_ARR == 0)
45 | WHERE(I_ARR == 0) ! expected-error {{expected an assignment statement in a where construct}}
46 | I_ARR = 1
47 | END WHERE
48 | END WHERE
49 |
50 | WHERE(I_ARR == 0)
51 | WHERE(I_ARR == 0) I_ARR = 1 ! expected-error {{expected an assignment statement in a where construct}}
52 | END WHERE
53 |
54 | END
55 |
--------------------------------------------------------------------------------
/test/TestRunner.sh.in:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # TestRunner.sh - Backward compatible utility for testing an individual file.
4 |
5 | # Find where this script is.
6 | Dir=$(dirname $(which $0))
7 | AbsDir=$(cd $Dir; pwd)
8 |
9 | # Find 'lit', assuming standard layout.
10 | lit=@FORT_PATH_TO_LLVM_LIT@
11 |
12 | # Dispatch to lit.
13 | $lit "$@"
14 |
--------------------------------------------------------------------------------
/test/lit.site.cfg.py.in:
--------------------------------------------------------------------------------
1 | ## Autogenerated by LLVM/Fort configuration.
2 | # Do not edit!
3 | config.llvm_src_root = "@LLVM_SOURCE_DIR@"
4 | config.llvm_obj_root = "@LLVM_BINARY_DIR@"
5 | config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
6 | config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
7 | config.fort_obj_root = "@FORT_BINARY_DIR@"
8 | config.target_triple = "@TARGET_TRIPLE@"
9 |
10 | # Support substitution of the tools and libs dirs with user parameters. This is
11 | # used when we can't determine the tool dir at configuration time.
12 | try:
13 | config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params
14 | config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params
15 | except KeyError:
16 | e = sys.exc_info()[1]
17 | key, = e.args
18 | lit.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
19 |
20 | # Let the main config do the real work.
21 | config.test_dir = "@FORT_SOURCE_DIR@/test"
22 | lit_config.load_config(config, "@FORT_SOURCE_DIR@/test/lit.cfg.py")
23 |
24 |
--------------------------------------------------------------------------------
/tools/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_subdirectory(driver)
2 |
--------------------------------------------------------------------------------
/tools/driver/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set( LLVM_LINK_COMPONENTS
2 | ${LLVM_TARGETS_TO_BUILD}
3 | asmparser
4 | bitreader
5 | bitwriter
6 | codegen
7 | ipo
8 | Option
9 | selectiondag
10 | linker
11 | )
12 |
13 | add_fort_executable(fort
14 | Main.cpp
15 | )
16 |
17 | target_link_libraries(fort
18 | PRIVATE
19 | fortAST
20 | fortFrontend
21 | fortParse
22 | fortSema
23 | fortBasic
24 | fortCodeGen
25 | fortDriver
26 | )
27 |
28 | set_target_properties(fort PROPERTIES VERSION ${FORT_EXECUTABLE_VERSION})
29 |
30 | # TODO open issue
31 | #add_dependencies(fort fort-headers)
32 |
33 | if(UNIX)
34 | set(fort_binary "fort${CMAKE_EXECUTABLE_SUFFIX}")
35 | else()
36 | set(fort_binary "${LLVM_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/fort${CMAKE_EXECUTABLE_SUFFIX}")
37 | endif()
38 |
39 | set_property(DIRECTORY APPEND
40 | PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${fort_pp})
41 |
42 | install(TARGETS fort
43 | RUNTIME DESTINATION bin)
44 |
45 |
--------------------------------------------------------------------------------
/tools/driver/Info.plist.in:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleIdentifier
6 | @TOOL_INFO_UTI@
7 | CFBundleInfoDictionaryVersion
8 | 6.0
9 | CFBundleName
10 | @TOOL_INFO_NAME
11 | CFBundleShortVersionString
12 | @TOOL_INFO_VERSION@
13 | CFBundleVersion
14 | @TOOL_INFO_BUILD_VERSION@
15 | CFBundleSignature
16 | ????
17 |
18 |
19 |
--------------------------------------------------------------------------------
/unittests/AST/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_fort_unittest(exprEvaluatorTest
2 | ExprEvaluator.cpp
3 | )
4 |
5 | target_link_libraries(exprEvaluatorTest
6 | PRIVATE
7 | fortAST
8 | fortFrontend
9 | fortParse
10 | fortSema
11 | fortBasic
12 | fortCodeGen
13 | )
14 |
--------------------------------------------------------------------------------
/unittests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_custom_target(FortUnitTests)
2 | set_target_properties(FortUnitTests PROPERTIES FOLDER "Fort tests")
3 |
4 | # add_fort_unittest(test_dirname file1.cpp file2.cpp)
5 | #
6 | # Will compile the list of files together and link against the fort
7 | # Produces a binary named 'basename(test_dirname)'.
8 | function(add_fort_unittest test_dirname)
9 | add_unittest(FortUnitTests ${test_dirname} ${ARGN})
10 | endfunction()
11 |
12 | add_subdirectory(AST)
13 |
--------------------------------------------------------------------------------
/utils/TableGen/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(LLVM_LINK_COMPONENTS Support)
2 |
3 | add_tablegen(fort-tblgen FORT
4 | FortASTNodesEmitter.cpp
5 | FortDiagnosticsEmitter.cpp
6 | TableGen.cpp
7 | )
8 | set_target_properties(fort-tblgen PROPERTIES FOLDER "Fort tablegenning")
9 |
--------------------------------------------------------------------------------
/utils/TableGen/TableGenBackends.h:
--------------------------------------------------------------------------------
1 | //===- TableGenBackends.h - Declarations for Fort TableGen Backends ------===//
2 | //
3 | // The LLVM Compiler Infrastructure
4 | //
5 | // This file is distributed under the University of Illinois Open Source
6 | // License. See LICENSE.TXT for details.
7 | //
8 | //===----------------------------------------------------------------------===//
9 | //
10 | // This file contains the declarations for all of the Fort TableGen
11 | // backends. A "TableGen backend" is just a function. See
12 | // "$LLVM_ROOT/utils/TableGen/TableGenBackends.h" for more info.
13 | //
14 | //===----------------------------------------------------------------------===//
15 |
16 | #include
17 |
18 | namespace llvm {
19 | class raw_ostream;
20 | class RecordKeeper;
21 | } // namespace llvm
22 |
23 | using llvm::raw_ostream;
24 | using llvm::RecordKeeper;
25 |
26 | namespace fort {
27 |
28 | void EmitFortDeclContext(RecordKeeper &RK, raw_ostream &OS);
29 | void EmitFortASTNodes(RecordKeeper &RK, raw_ostream &OS, const std::string &N,
30 | const std::string &S);
31 |
32 | void EmitFortDiagsDefs(RecordKeeper &Records, raw_ostream &OS,
33 | const std::string &Component);
34 | void EmitFortDiagGroups(RecordKeeper &Records, raw_ostream &OS);
35 | void EmitFortDiagsIndexName(RecordKeeper &Records, raw_ostream &OS);
36 |
37 | } // end namespace fort
38 |
--------------------------------------------------------------------------------