[PATCH] D131526: [OMPIRBuilder] Add support for safelen clause

2022-08-10 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:3045
+  if (!(Simdlen == nullptr && Safelen == nullptr)) {
+ConstantInt *VectorizeWidth = Simdlen == nullptr ? Safelen : Simdlen;
 addLoopMetadata(

psoni2628 wrote:
> domada wrote:
> > Could you add comment which describes how simdlen and safelen clauses work?
> > 
> > BTW. Have you checked invalid test case where safelen < simdlen? 
> Yes, I have checked this case, the case doesn't make it to OMPIRBuilder, 
> because the frontend errors.
> 
> 
> ```
> ./ex2.c:9:38: error: the value of 'simdlen' parameter must be less than or 
> equal to the value of the 'safelen' parameter
> #pragma omp simd safelen(2) simdlen(3)
>  ~  ^
> 1 error generated.
> 
> ```
> 
> I was thinking about adding an assertion to assert that `simdlen < safelen` , 
> but I wasn't sure that it made sense to do so when Clang is checking this 
> anyways, and the existing codegen for simdlen/safelen also doesn't check this.
> 
> 
> ```
> +  // If both simdlen and safelen clauses are specified, the value of the 
> simdlen parameter must be less than or equal to the value of the safelen 
> parameter.
> +  if (Simdlen != nullptr && Safelen != nullptr &&  
> (Simdlen->getValue().ugt(Safelen->getValue( {
> +llvm_unreachable("Simdlen must be less than or to Safelen when both 
> present");
> +  }
> 
> ```
An `assert` is probably not necessary, as this is part of semantic check (as 
you identified to be done by the frontend).  The check is not part of codegen.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131526/new/

https://reviews.llvm.org/D131526

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129149: [OMPIRBuilder] Add support for simdlen clause

2022-07-11 Thread Arnamoy B via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGac892c70a456: [OMPIRBuilder] Add support for simdlen clause 
(authored by psoni2628, committed by arnamoy10).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129149/new/

https://reviews.llvm.org/D129149

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/irbuilder_simd.cpp
  clang/test/OpenMP/irbuilder_simdlen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  llvm/utils/UpdateTestChecks/common.py
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -971,7 +971,7 @@
   llvm::CanonicalLoopInfo *loopInfo =
   ompBuilder->collapseLoops(ompLoc.DL, loopInfos, {});
 
-  ompBuilder->applySimd(ompLoc.DL, loopInfo);
+  ompBuilder->applySimd(loopInfo, nullptr);
 
   builder.restoreIP(afterIP);
   return success();
Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -719,18 +719,19 @@
 # Description of the different "unnamed" values we match in the IR, e.g.,
 # (local) ssa values, (debug) metadata, etc.
 ir_nameless_values = [
-NamelessValue(r'TMP'  , '%' , r'%'   , None, None   , r'[\w$.-]+?' , None , False) ,
-NamelessValue(r'ATTR' , '#' , r'#'   , None, None   , r'[0-9]+', None , False) ,
-NamelessValue(r'ATTR' , '#' , None   , r'attributes #' , r'[0-9]+'  , None , r'{[^}]*}'   , False) ,
-NamelessValue(r'GLOB' , '@' , r'@'   , None, None   , r'[0-9]+', None , False) ,
-NamelessValue(r'GLOB' , '@' , None   , r'@', r'[a-zA-Z0-9_$"\\.-]+' , None , r'.+', True)  ,
-NamelessValue(r'DBG'  , '!' , r'!dbg '   , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'PROF' , '!' , r'!prof '  , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'TBAA' , '!' , r'!tbaa '  , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'RNG'  , '!' , r'!range ' , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'LOOP' , '!' , r'!llvm.loop ' , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'META' , '!' , r'metadata '   , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'META' , '!' , None   , r'' , r'![0-9]+' , None , r'(?:distinct |)!.*' , False) ,
+NamelessValue(r'TMP' , '%' , r'%'   , None, None   , r'[\w$.-]+?' , None , False) ,
+NamelessValue(r'ATTR', '#' , r'#'   , None, None   , r'[0-9]+', None , False) ,
+NamelessValue(r'ATTR', '#' , None   , r'attributes #' , r'[0-9]+'  , None , r'{[^}]*}'   , False) ,
+NamelessValue(r'GLOB', '@' , r'@'   , None, None   , r'[0-9]+', None , False) ,
+NamelessValue(r'GLOB', '@' , None   , r'@', r'[a-zA-Z0-9_$"\\.-]+' , None , r'.+', True)  ,
+NamelessValue(r'DBG' , '!' , r'!dbg '   , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'PROF', '!' , r'!prof '  , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'TBAA', '!' , r'!tbaa '  , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'RNG' , '!' , r'!range ' , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'LOOP', '!' , r'!llvm.loop ' , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'META', '!' , r'metadata '   , 

[PATCH] D129149: [OMPIRBuilder] Add support for simdlen clause

2022-07-05 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:2596
   // Check for unsupported clauses
-  if (!S.clauses().empty()) {
-// Currently no clause is supported
-return false;
+  for (OMPClause *C : S.clauses()) {
+// Currently only simdlen clause is supported

I am just wondering whether we should have a check to make sure that we are 
processing the clauses of only `simd` directive here. Because the function 
takes a general `OMPExecutableDirective` as argument 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129149/new/

https://reviews.llvm.org/D129149

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114379: [OMPIRBuilder] Add support for simd (loop) directive.

2022-01-19 Thread Arnamoy B via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9fbd33ad623d: [OMPIRBuilder] Add support for simd (loop) 
directive. (authored by arnamoy10).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114379/new/

https://reviews.llvm.org/D114379

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/irbuilder_simd.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -1662,6 +1662,37 @@
   EXPECT_FALSE(verifyModule(*M, ()));
 }
 
+TEST_F(OpenMPIRBuilderTest, ApplySimd) {
+  OpenMPIRBuilder OMPBuilder(*M);
+
+  CanonicalLoopInfo *CLI = buildSingleLoopFunction(DL, OMPBuilder);
+
+  // Simd-ize the loop.
+  OMPBuilder.applySimd(DL, CLI);
+
+  OMPBuilder.finalize();
+  EXPECT_FALSE(verifyModule(*M, ()));
+
+  PassBuilder PB;
+  FunctionAnalysisManager FAM;
+  PB.registerFunctionAnalyses(FAM);
+  LoopInfo  = FAM.getResult(*F);
+
+  const std::vector  = LI.getTopLevelLoops();
+  EXPECT_EQ(TopLvl.size(), 1u);
+
+  Loop *L = TopLvl.front();
+  EXPECT_TRUE(findStringMetadataForLoop(L, "llvm.loop.parallel_accesses"));
+  EXPECT_TRUE(getBooleanLoopAttribute(L, "llvm.loop.vectorize.enable"));
+
+  // Check for llvm.access.group metadata attached to the printf
+  // function in the loop body.
+  BasicBlock *LoopBody = CLI->getBody();
+  EXPECT_TRUE(any_of(*LoopBody, [](Instruction ) {
+return I.getMetadata("llvm.access.group") != nullptr;
+  }));
+}
+
 TEST_F(OpenMPIRBuilderTest, UnrollLoopFull) {
   OpenMPIRBuilder OMPBuilder(*M);
 
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/AssumptionCache.h"
@@ -2145,6 +2146,19 @@
   Latch->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopID);
 }
 
+/// Attach llvm.access.group metadata to the memref instructions of \p Block
+static void addSimdMetadata(BasicBlock *Block, MDNode *AccessGroup,
+LoopInfo ) {
+  for (Instruction  : *Block) {
+if (I.mayReadOrWriteMemory()) {
+  // TODO: This instruction may already have access group from
+  // other pragmas e.g. #pragma clang loop vectorize.  Append
+  // so that the existing metadata is not overwritten.
+  I.setMetadata(LLVMContext::MD_access_group, AccessGroup);
+}
+  }
+}
+
 void OpenMPIRBuilder::unrollLoopFull(DebugLoc, CanonicalLoopInfo *Loop) {
   LLVMContext  = Builder.getContext();
   addLoopMetadata(
@@ -2160,6 +2174,53 @@
 });
 }
 
+void OpenMPIRBuilder::applySimd(DebugLoc, CanonicalLoopInfo *CanonicalLoop) {
+  LLVMContext  = Builder.getContext();
+
+  Function *F = CanonicalLoop->getFunction();
+
+  FunctionAnalysisManager FAM;
+  FAM.registerPass([]() { return DominatorTreeAnalysis(); });
+  FAM.registerPass([]() { return LoopAnalysis(); });
+  FAM.registerPass([]() { return PassInstrumentationAnalysis(); });
+
+  LoopAnalysis LIA;
+  LoopInfo & = LIA.run(*F, FAM);
+
+  Loop *L = LI.getLoopFor(CanonicalLoop->getHeader());
+
+  SmallSet Reachable;
+
+  // Get the basic blocks from the loop in which memref instructions
+  // can be found.
+  // TODO: Generalize getting all blocks inside a CanonicalizeLoopInfo,
+  // preferably without running any passes.
+  for (BasicBlock *Block : L->getBlocks()) {
+if (Block == CanonicalLoop->getCond() ||
+Block == CanonicalLoop->getHeader())
+  continue;
+Reachable.insert(Block);
+  }
+
+  // Add access group metadata to memory-access instructions.
+  MDNode *AccessGroup = MDNode::getDistinct(Ctx, {});
+  for (BasicBlock *BB : Reachable)
+addSimdMetadata(BB, AccessGroup, LI);
+
+  // Use the above access group metadata to create loop level
+  // metadata, which should be distinct for each loop.
+  ConstantAsMetadata *BoolConst =
+  ConstantAsMetadata::get(ConstantInt::getTrue(Type::getInt1Ty(Ctx)));
+  // TODO:  If the loop has existing parallel access metadata, have
+  // to combine two lists.
+  addLoopMetadata(
+  CanonicalLoop,
+  {MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.parallel_accesses"),
+ AccessGroup}),
+   MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.vectorize.enable"),
+ BoolConst})});
+}
+
 /// Create the TargetMachine object to query the backend for optimization
 /// 

[PATCH] D114379: [OMPIRBuilder] Add support for simd (loop) directive.

2022-01-18 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 400958.
arnamoy10 added a comment.

Making any_of one-liner.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114379/new/

https://reviews.llvm.org/D114379

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/irbuilder_simd.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -1662,6 +1662,37 @@
   EXPECT_FALSE(verifyModule(*M, ()));
 }
 
+TEST_F(OpenMPIRBuilderTest, ApplySimd) {
+  OpenMPIRBuilder OMPBuilder(*M);
+
+  CanonicalLoopInfo *CLI = buildSingleLoopFunction(DL, OMPBuilder);
+
+  // Simd-ize the loop.
+  OMPBuilder.applySimd(DL, CLI);
+
+  OMPBuilder.finalize();
+  EXPECT_FALSE(verifyModule(*M, ()));
+
+  PassBuilder PB;
+  FunctionAnalysisManager FAM;
+  PB.registerFunctionAnalyses(FAM);
+  LoopInfo  = FAM.getResult(*F);
+
+  const std::vector  = LI.getTopLevelLoops();
+  EXPECT_EQ(TopLvl.size(), 1u);
+
+  Loop *L = TopLvl.front();
+  EXPECT_TRUE(findStringMetadataForLoop(L, "llvm.loop.parallel_accesses"));
+  EXPECT_TRUE(getBooleanLoopAttribute(L, "llvm.loop.vectorize.enable"));
+
+  // Check for llvm.access.group metadata attached to the printf
+  // function in the loop body.
+  BasicBlock *LoopBody = CLI->getBody();
+  EXPECT_TRUE(any_of(*LoopBody, [](Instruction ) {
+return I.getMetadata("llvm.access.group") != nullptr;
+  }));
+}
+
 TEST_F(OpenMPIRBuilderTest, UnrollLoopFull) {
   OpenMPIRBuilder OMPBuilder(*M);
 
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/AssumptionCache.h"
@@ -2145,6 +2146,19 @@
   Latch->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopID);
 }
 
+/// Attach llvm.access.group metadata to the memref instructions of \p Block
+static void addSimdMetadata(BasicBlock *Block, MDNode *AccessGroup,
+LoopInfo ) {
+  for (Instruction  : *Block) {
+if (I.mayReadOrWriteMemory()) {
+  // TODO: This instruction may already have access group from
+  // other pragmas e.g. #pragma clang loop vectorize.  Append
+  // so that the existing metadata is not overwritten.
+  I.setMetadata(LLVMContext::MD_access_group, AccessGroup);
+}
+  }
+}
+
 void OpenMPIRBuilder::unrollLoopFull(DebugLoc, CanonicalLoopInfo *Loop) {
   LLVMContext  = Builder.getContext();
   addLoopMetadata(
@@ -2160,6 +2174,53 @@
 });
 }
 
+void OpenMPIRBuilder::applySimd(DebugLoc, CanonicalLoopInfo *CanonicalLoop) {
+  LLVMContext  = Builder.getContext();
+
+  Function *F = CanonicalLoop->getFunction();
+
+  FunctionAnalysisManager FAM;
+  FAM.registerPass([]() { return DominatorTreeAnalysis(); });
+  FAM.registerPass([]() { return LoopAnalysis(); });
+  FAM.registerPass([]() { return PassInstrumentationAnalysis(); });
+
+  LoopAnalysis LIA;
+  LoopInfo & = LIA.run(*F, FAM);
+
+  Loop *L = LI.getLoopFor(CanonicalLoop->getHeader());
+
+  SmallSet Reachable;
+
+  // Get the basic blocks from the loop in which memref instructions
+  // can be found.
+  // TODO: Generalize getting all blocks inside a CanonicalizeLoopInfo,
+  // preferably without running any passes.
+  for (BasicBlock *Block : L->getBlocks()) {
+if (Block == CanonicalLoop->getCond() ||
+Block == CanonicalLoop->getHeader())
+  continue;
+Reachable.insert(Block);
+  }
+
+  // Add access group metadata to memory-access instructions.
+  MDNode *AccessGroup = MDNode::getDistinct(Ctx, {});
+  for (BasicBlock *BB : Reachable)
+addSimdMetadata(BB, AccessGroup, LI);
+
+  // Use the above access group metadata to create loop level
+  // metadata, which should be distinct for each loop.
+  ConstantAsMetadata *BoolConst =
+  ConstantAsMetadata::get(ConstantInt::getTrue(Type::getInt1Ty(Ctx)));
+  // TODO:  If the loop has existing parallel access metadata, have
+  // to combine two lists.
+  addLoopMetadata(
+  CanonicalLoop,
+  {MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.parallel_accesses"),
+ AccessGroup}),
+   MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.vectorize.enable"),
+ BoolConst})});
+}
+
 /// Create the TargetMachine object to query the backend for optimization
 /// preferences.
 ///
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

[PATCH] D114379: [OMPIRBuilder] Add support for simd (loop) directive.

2022-01-18 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 400830.
arnamoy10 added a comment.

1. Trying to tackle a test failure
2. Adding `any_of()` as per reviewer's suggestion.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114379/new/

https://reviews.llvm.org/D114379

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/irbuilder_simd.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -1662,6 +1662,40 @@
   EXPECT_FALSE(verifyModule(*M, ()));
 }
 
+TEST_F(OpenMPIRBuilderTest, ApplySimd) {
+  OpenMPIRBuilder OMPBuilder(*M);
+
+  CanonicalLoopInfo *CLI = buildSingleLoopFunction(DL, OMPBuilder);
+
+  // Simd-ize the loop.
+  OMPBuilder.applySimd(DL, CLI);
+
+  OMPBuilder.finalize();
+  EXPECT_FALSE(verifyModule(*M, ()));
+
+  PassBuilder PB;
+  FunctionAnalysisManager FAM;
+  PB.registerFunctionAnalyses(FAM);
+  LoopInfo  = FAM.getResult(*F);
+
+  const std::vector  = LI.getTopLevelLoops();
+  EXPECT_EQ(TopLvl.size(), 1u);
+
+  Loop *L = TopLvl.front();
+  EXPECT_TRUE(findStringMetadataForLoop(L, "llvm.loop.parallel_accesses"));
+  EXPECT_TRUE(getBooleanLoopAttribute(L, "llvm.loop.vectorize.enable"));
+
+  // Check for llvm.access.group metadata attached to the printf
+  // function in the loop body.
+  BasicBlock *LoopBody = CLI->getBody();
+  bool Found = false;
+  if (llvm::any_of(*LoopBody, [](Instruction ) {
+return I.getMetadata("llvm.access.group") != nullptr;
+  }))
+Found = true;
+  EXPECT_TRUE(Found);
+}
+
 TEST_F(OpenMPIRBuilderTest, UnrollLoopFull) {
   OpenMPIRBuilder OMPBuilder(*M);
 
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/AssumptionCache.h"
@@ -2144,6 +2145,19 @@
   Latch->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopID);
 }
 
+/// Attach llvm.access.group metadata to the memref instructions of \p Block
+static void addSimdMetadata(BasicBlock *Block, MDNode *AccessGroup,
+LoopInfo ) {
+  for (Instruction  : *Block) {
+if (I.mayReadOrWriteMemory()) {
+  // TODO: This instruction may already have access group from
+  // other pragmas e.g. #pragma clang loop vectorize.  Append
+  // so that the existing metadata is not overwritten.
+  I.setMetadata(LLVMContext::MD_access_group, AccessGroup);
+}
+  }
+}
+
 void OpenMPIRBuilder::unrollLoopFull(DebugLoc, CanonicalLoopInfo *Loop) {
   LLVMContext  = Builder.getContext();
   addLoopMetadata(
@@ -2159,6 +2173,53 @@
 });
 }
 
+void OpenMPIRBuilder::applySimd(DebugLoc, CanonicalLoopInfo *CanonicalLoop) {
+  LLVMContext  = Builder.getContext();
+
+  Function *F = CanonicalLoop->getFunction();
+
+  FunctionAnalysisManager FAM;
+  FAM.registerPass([]() { return DominatorTreeAnalysis(); });
+  FAM.registerPass([]() { return LoopAnalysis(); });
+  FAM.registerPass([]() { return PassInstrumentationAnalysis(); });
+
+  LoopAnalysis LIA;
+  LoopInfo & = LIA.run(*F, FAM);
+
+  Loop *L = LI.getLoopFor(CanonicalLoop->getHeader());
+
+  SmallSet Reachable;
+
+  // Get the basic blocks from the loop in which memref instructions
+  // can be found.
+  // TODO: Generalize getting all blocks inside a CanonicalizeLoopInfo,
+  // preferably without running any passes.
+  for (BasicBlock *Block : L->getBlocks()) {
+if (Block == CanonicalLoop->getCond() ||
+Block == CanonicalLoop->getHeader())
+  continue;
+Reachable.insert(Block);
+  }
+
+  // Add access group metadata to memory-access instructions.
+  MDNode *AccessGroup = MDNode::getDistinct(Ctx, {});
+  for (BasicBlock *BB : Reachable)
+addSimdMetadata(BB, AccessGroup, LI);
+
+  // Use the above access group metadata to create loop level
+  // metadata, which should be distinct for each loop.
+  ConstantAsMetadata *BoolConst =
+  ConstantAsMetadata::get(ConstantInt::getTrue(Type::getInt1Ty(Ctx)));
+  // TODO:  If the loop has existing parallel access metadata, have
+  // to combine two lists.
+  addLoopMetadata(
+  CanonicalLoop,
+  {MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.parallel_accesses"),
+ AccessGroup}),
+   MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.vectorize.enable"),
+ BoolConst})});
+}
+
 /// Create the TargetMachine object to query the backend for optimization
 

[PATCH] D114379: [OMPIRBuilder] Add support for simd (loop) directive.

2022-01-17 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 400631.
arnamoy10 added a comment.

Updating as per reviewers comments.

Adding a test case in `OpenMPIRBuilderTest.cpp`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114379/new/

https://reviews.llvm.org/D114379

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/irbuilder_simd.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -1662,6 +1662,40 @@
   EXPECT_FALSE(verifyModule(*M, ()));
 }
 
+TEST_F(OpenMPIRBuilderTest, ApplySimd) {
+  OpenMPIRBuilder OMPBuilder(*M);
+
+  CanonicalLoopInfo *CLI = buildSingleLoopFunction(DL, OMPBuilder);
+
+  // Simd-ize the loop.
+  OMPBuilder.applySimd(DL, CLI);
+
+  OMPBuilder.finalize();
+  EXPECT_FALSE(verifyModule(*M, ()));
+
+  PassBuilder PB;
+  FunctionAnalysisManager FAM;
+  PB.registerFunctionAnalyses(FAM);
+  LoopInfo  = FAM.getResult(*F);
+
+  const std::vector  = LI.getTopLevelLoops();
+  EXPECT_EQ(TopLvl.size(), 1u);
+
+  Loop *L = TopLvl.front();
+  EXPECT_TRUE(getBooleanLoopAttribute(L, "llvm.loop.parallel_accesses"));
+  EXPECT_TRUE(getBooleanLoopAttribute(L, "llvm.loop.vectorize.enable"));
+
+  // Check for llvm.access.group metadata attached to the printf
+  // function in the loop body.
+  BasicBlock *LoopBody = CLI->getBody();
+  bool Found = false;
+  for (Instruction  : *LoopBody) {
+if (I.getMetadata("llvm.access.group"))
+  Found = true;
+  }
+  EXPECT_EQ(Found, true);
+}
+
 TEST_F(OpenMPIRBuilderTest, UnrollLoopFull) {
   OpenMPIRBuilder OMPBuilder(*M);
 
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/AssumptionCache.h"
@@ -2144,6 +2145,19 @@
   Latch->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopID);
 }
 
+/// Attach llvm.access.group metadata to the memref instructions of \p Block
+static void addSimdMetadata(BasicBlock *Block, MDNode *AccessGroup,
+LoopInfo ) {
+  for (Instruction  : *Block) {
+if (I.mayReadOrWriteMemory()) {
+  // TODO: This instruction may already have access group from
+  // other pragmas e.g. #pragma clang loop vectorize.  Append
+  // so that the existing metadata is not overwritten.
+  I.setMetadata(LLVMContext::MD_access_group, AccessGroup);
+}
+  }
+}
+
 void OpenMPIRBuilder::unrollLoopFull(DebugLoc, CanonicalLoopInfo *Loop) {
   LLVMContext  = Builder.getContext();
   addLoopMetadata(
@@ -2159,6 +2173,53 @@
 });
 }
 
+void OpenMPIRBuilder::applySimd(DebugLoc, CanonicalLoopInfo *CanonicalLoop) {
+  LLVMContext  = Builder.getContext();
+
+  Function *F = CanonicalLoop->getFunction();
+
+  FunctionAnalysisManager FAM;
+  FAM.registerPass([]() { return DominatorTreeAnalysis(); });
+  FAM.registerPass([]() { return LoopAnalysis(); });
+  FAM.registerPass([]() { return PassInstrumentationAnalysis(); });
+
+  LoopAnalysis LIA;
+  LoopInfo & = LIA.run(*F, FAM);
+
+  Loop *L = LI.getLoopFor(CanonicalLoop->getHeader());
+
+  SmallSet Reachable;
+
+  // Get the basic blocks from the loop in which memref instructions
+  // can be found.
+  // TODO: Generalize getting all blocks inside a CanonicalizeLoopInfo,
+  // preferably without running any passes.
+  for (BasicBlock *Block : L->getBlocks()) {
+if (Block == CanonicalLoop->getCond() ||
+Block == CanonicalLoop->getHeader())
+  continue;
+Reachable.insert(Block);
+  }
+
+  // Add access group metadata to memory-access instructions.
+  MDNode *AccessGroup = MDNode::getDistinct(Ctx, {});
+  for (BasicBlock *BB : Reachable)
+addSimdMetadata(BB, AccessGroup, LI);
+
+  // Use the above access group metadata to create loop level
+  // metadata, which should be distinct for each loop.
+  ConstantAsMetadata *BoolConst =
+  ConstantAsMetadata::get(ConstantInt::getTrue(Type::getInt1Ty(Ctx)));
+  // TODO:  If the loop has existing parallel access metadata, have
+  // to combine two lists.
+  addLoopMetadata(
+  CanonicalLoop,
+  {MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.parallel_accesses"),
+ AccessGroup}),
+   MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.vectorize.enable"),
+ BoolConst})});
+}
+
 /// Create the TargetMachine object to query the backend for optimization
 /// preferences.
 ///
Index: 

[PATCH] D114379: [OMPIRBuilder] Add support for simd (loop) directive.

2021-12-13 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 394046.
arnamoy10 added a comment.

Thanks @Meinersbur  for the comments.  Addressing reviewers comments:

1. Update code to make the matadata addition correct, as per reviewers comments.
2. Using `LoopInfo` to identify BasicBlocks to iterate through.
3. Updating the test case.
4. Following coding standard.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114379/new/

https://reviews.llvm.org/D114379

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/irbuilder_simd.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/AssumptionCache.h"
@@ -2116,6 +2117,16 @@
   Latch->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopID);
 }
 
+/// Attach metadata llvm.access.group to the memref instructions of \p block
+static void addSimdMetadata(BasicBlock *Block,
+MDNode * AccessGroup) {
+  for (Instruction  : *Block) {
+if (I.mayReadFromMemory() || I.mayWriteToMemory()) {
+  I.setMetadata(LLVMContext::MD_access_group, AccessGroup);
+}
+  }
+}
+
 void OpenMPIRBuilder::unrollLoopFull(DebugLoc, CanonicalLoopInfo *Loop) {
   LLVMContext  = Builder.getContext();
   addLoopMetadata(
@@ -2131,6 +2142,48 @@
 });
 }
 
+void OpenMPIRBuilder::applySimd(DebugLoc, CanonicalLoopInfo *CanonicalLoop) {
+  LLVMContext  = Builder.getContext();  
+
+  Function *F = CanonicalLoop->getFunction(); 
+
+  FunctionAnalysisManager FAM; 
+  FAM.registerPass([]() { return DominatorTreeAnalysis(); });
+  FAM.registerPass([]() { return LoopAnalysis(); });
+  FAM.registerPass([]() { return PassInstrumentationAnalysis(); });
+
+  DominatorTreeAnalysis DTA;
+  DominatorTree & = DTA.run(*F, FAM);
+  LoopAnalysis LIA;
+  LoopInfo & = LIA.run(*F, FAM);
+
+  Loop *L = LI.getLoopFor(CanonicalLoop->getHeader());
+
+  llvm::SmallSet Reachable; 
+
+  // Get the basic blocks from the loop in which memref instructions
+  // can be found.
+  for (BasicBlock *Block:L->getBlocks()) {
+if (Block == CanonicalLoop->getCond() || Block == CanonicalLoop->getHeader()) continue;
+Reachable.insert(Block);
+  }
+
+  // Add access group metadata to memory-access instructions.
+  MDNode *AccessGroup = MDNode::getDistinct(Ctx, {});
+  for (BasicBlock *BB : Reachable) {
+addSimdMetadata(BB, AccessGroup);
+  }
+
+  // Use the above access group metadata to create loop level
+  // metadata, which should be distinct for each loop. 
+  ConstantAsMetadata *BoolConst = ConstantAsMetadata::get(
+  ConstantInt::getTrue(Type::getInt1Ty(Ctx)));
+  addLoopMetadata(
+  CanonicalLoop,
+  {MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.parallel_accesses"), AccessGroup}),
+  MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.vectorize.enable"), BoolConst})});
+}
+
 /// Create the TargetMachine object to query the backend for optimization
 /// preferences.
 ///
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -517,6 +517,12 @@
   void unrollLoopPartial(DebugLoc DL, CanonicalLoopInfo *Loop, int32_t Factor,
  CanonicalLoopInfo **UnrolledCLI);
 
+  /// Add metadata to simd-ize a loop.
+  ///
+  /// \param DL   Debug location for instructions added by unrolling.
+  /// \param Loop The loop to simd-ize.
+  void applySimd(DebugLoc DL, CanonicalLoopInfo *Loop);
+
   /// Generator for '#omp flush'
   ///
   /// \param Loc The location where the flush directive was encountered
Index: clang/test/OpenMP/irbuilder_simd.cpp
===
--- /dev/null
+++ clang/test/OpenMP/irbuilder_simd.cpp
@@ -0,0 +1,76 @@
+// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s 
+// expected-no-diagnostics 
+// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECKTWOLOOPS 
+// expected-no-diagnostics
+
+struct S {
+  int a, b;
+};
+
+struct P {
+  int a, b;
+};
+
+void simple(float *a, float *b, int *c) {
+  S s, *p;
+  P pp;
+#pragma omp simd
+  for (int i = 3; i < 32; i += 5) {
+// llvm.access.group test
+// CHECK: %[[A_ADDR:.+]] = alloca float*, align 8
+// CHECK: 

[PATCH] D114379: [OMPIRBuilder] Add support for simd (loop) directive.

2021-12-06 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 392189.
arnamoy10 added a comment.

Addressing reviewers comments  Major changes are as follows:

1. Skipping unsupported clauses and skip the case when there is an ordered 
directive inside the simd construct
2. Traversing all the blocks in the Canonical loop body (not only the first 
block of the loop body) to look for locations to insert metadata
3. Making metadata unique for each Canonical loop
4. Update test case to reflect changes.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114379/new/

https://reviews.llvm.org/D114379

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/irbuilder_simd.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/AssumptionCache.h"
@@ -2116,6 +2117,19 @@
   Latch->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopID);
 }
 
+/// Attach metadata access.group to the load and store instructions of \p block
+static void addSimdMetadata(BasicBlock *Block,
+ArrayRef Properties) {
+  for (auto  : *Block) {
+if (I.mayReadFromMemory() || I.mayWriteToMemory()) {
+  Instruction *instr = dyn_cast();
+  LLVMContext  = instr->getContext();
+  MDNode *LoopID = MDNode::get(C, Properties);
+  instr->setMetadata("llvm.access.group", LoopID);
+}
+  }
+}
+
 void OpenMPIRBuilder::unrollLoopFull(DebugLoc, CanonicalLoopInfo *Loop) {
   LLVMContext  = Builder.getContext();
   addLoopMetadata(
@@ -2131,6 +2145,52 @@
 });
 }
 
+void OpenMPIRBuilder::applySimd(DebugLoc, CanonicalLoopInfo *Loop) {
+  LLVMContext  = Builder.getContext();
+  addLoopMetadata(
+  Loop,
+  {MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.parallel_accesses")),
+   MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.vectorize.enable"))});
+
+  // Find the set of basic blocks reachable from the body unto the
+  // exit block.  May have to enhance this collection for nested loops.
+  BasicBlock *body = Loop->getBody();
+  BasicBlock *exit = Loop->getExit();
+
+  FunctionAnalysisManager FAM;
+  FAM.registerPass([]() { return DominatorTreeAnalysis(); });
+  DominatorTreeAnalysis DTA;
+  DominatorTree & = DTA.run(*(Loop->getBody()->getParent()), FAM);
+
+  llvm::SmallSet reachable;
+  llvm::SmallVector worklist;
+
+  llvm::SmallSet skipBBs;
+  skipBBs.insert(Loop->getCond());
+  skipBBs.insert(Loop->getHeader());
+
+  worklist.push_back(body);
+  reachable.insert(body);
+  while (!worklist.empty()) {
+BasicBlock *front = worklist.pop_back_val();
+for (BasicBlock *succ : successors(front)) {
+  if (reachable.count(succ) == 0) {
+/// We need the check here to ensure that we don't run
+/// infinitely if the CFG has a loop in it
+/// i.e. the BB reaches itself directly or indirectly
+worklist.push_back(succ);
+if (!DT.dominates(exit, succ) && skipBBs.count(succ) == 0)
+  reachable.insert(succ);
+  }
+}
+  }
+
+  MDNode *N = MDNode::getDistinct(Ctx, MDString::get(Ctx, "llvm.access.group"));
+  for (auto BB : reachable) {
+addSimdMetadata(BB, {N});
+  }
+}
+
 /// Create the TargetMachine object to query the backend for optimization
 /// preferences.
 ///
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -517,6 +517,12 @@
   void unrollLoopPartial(DebugLoc DL, CanonicalLoopInfo *Loop, int32_t Factor,
  CanonicalLoopInfo **UnrolledCLI);
 
+  /// Add metadata to simd-ize a loop.
+  ///
+  /// \param DL   Debug location for instructions added by unrolling.
+  /// \param Loop The loop to simd-ize.
+  void applySimd(DebugLoc DL, CanonicalLoopInfo *Loop);
+
   /// Generator for '#omp flush'
   ///
   /// \param Loc The location where the flush directive was encountered
Index: clang/test/OpenMP/irbuilder_simd.cpp
===
--- /dev/null
+++ clang/test/OpenMP/irbuilder_simd.cpp
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s 
+// expected-no-diagnostics 
+// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECKTWOLOOPS 
+// 

[PATCH] D114379: [OMPIRBuilder] Add support for simd (loop) directive.

2021-12-01 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:2586-2587
 void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective ) {
+
+  bool UseOMPIRBuilder = CGM.getLangOpts().OpenMPIRBuilder;
+  if (UseOMPIRBuilder) {

Meinersbur wrote:
> [nit] Unnecessary whitespace
I took a look at `isSupportedByOpenMPIRBuilder()` and seems like it is more 
suitable for a check against work-sharing loop construct, not for `simd`.  

And for `simd`, I am not sure what features I should be checking for.  One 
check I can think of is checking whether any of the not-yet-supported clauses 
is present in the simd directive or not.  Am I on the right track?  



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:2594
+// Emit the associated statement and get its loop representation.
+auto DL = SourceLocToDebugLoc(S.getBeginLoc());
+const Stmt *Inner = S.getRawStmt();

Meinersbur wrote:
> [style] According to the [[ 
> https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable
>  | LLVM coding standard ]], `auto` is only used in specific cases.
I am inspired by [[ 
https://github.com/llvm/llvm-project/blob/003c9c7457d0be5deeca7eee84ab5f110bf6/clang/lib/CodeGen/CGStmtOpenMP.cpp#L2611
 | existing code ]] though


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114379/new/

https://reviews.llvm.org/D114379

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114379: [OMPIRBuilder] Add support for simd (loop) directive.

2021-11-22 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 created this revision.
arnamoy10 added reviewers: kiranchandramohan, peixin, bryanpkc, Meinersbur.
Herald added a subscriber: hiraditya.
arnamoy10 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114379

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/simd_codegen_irbuilder.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2116,6 +2116,19 @@
   Latch->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopID);
 }
 
+/// Attach metadata access.group to the load and store instructions of \p block
+static void addSIMDMetadata(BasicBlock *block,
+ArrayRef Properties) {
+  for (auto  : *block) {
+if (isa() || isa()) {
+  Instruction *instr = dyn_cast();
+  LLVMContext  = instr->getContext();
+  MDNode *N = MDNode::get(C, MDString::get(C, ""));
+  instr->setMetadata("llvm.access.group", N);
+}
+  }
+}
+
 void OpenMPIRBuilder::unrollLoopFull(DebugLoc, CanonicalLoopInfo *Loop) {
   LLVMContext  = Builder.getContext();
   addLoopMetadata(
@@ -2131,6 +2144,30 @@
 });
 }
 
+void OpenMPIRBuilder::createSIMDLoop(DebugLoc, CanonicalLoopInfo *Loop) {
+  LLVMContext  = Builder.getContext();
+  addLoopMetadata(
+  Loop,
+  {MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.parallel_accesses")),
+   MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.vectorize.enable"))});
+  BasicBlock *header = Loop->getHeader();
+  BasicBlock *cond = Loop->getCond();
+  BasicBlock *body = Loop->getBody();
+
+  addSIMDMetadata(header,
+  {
+  MDNode::get(Ctx, MDString::get(Ctx, "llvm.access.group")),
+  });
+  addSIMDMetadata(cond,
+  {
+  MDNode::get(Ctx, MDString::get(Ctx, "llvm.access.group")),
+  });
+  addSIMDMetadata(body,
+  {
+  MDNode::get(Ctx, MDString::get(Ctx, "llvm.access.group")),
+  });
+}
+
 /// Create the TargetMachine object to query the backend for optimization
 /// preferences.
 ///
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -517,6 +517,12 @@
   void unrollLoopPartial(DebugLoc DL, CanonicalLoopInfo *Loop, int32_t Factor,
  CanonicalLoopInfo **UnrolledCLI);
 
+  /// Add metadata to simd-ise a loop.
+  ///
+  /// \param DL   Debug location for instructions added by unrolling.
+  /// \param Loop The loop to simd-ise.
+  void createSIMDLoop(DebugLoc DL, CanonicalLoopInfo *Loop);
+
   /// Generator for '#omp flush'
   ///
   /// \param Loc The location where the flush directive was encountered
Index: clang/test/OpenMP/simd_codegen_irbuilder.cpp
===
--- /dev/null
+++ clang/test/OpenMP/simd_codegen_irbuilder.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+struct S {
+  int a, b;
+};
+
+void simple(float *a, float *b) {
+  S s, *p;
+  int j = 0;
+#pragma omp simd
+  for (int i = 3; i < 32; i += 5) {
+// llvm.access.group test
+// CHECK: omp_loop.body:; preds = %omp_loop.cond
+// CHECK-NEXT: call void @__captured_stmt.1(i32* %i, i32 %omp_loop.iv, %struct.anon.0* %agg.captured1)
+// CHECK-NEXT: %3 = load float*, float** %b.addr, align 8, !llvm.access.group !3
+// CHECK-NEXT: %4 = load i32, i32* %i, align 4, !llvm.access.group !3
+// CHECK-NEXT: %idxprom = sext i32 %4 to i64
+// CHECK-NEXT: %arrayidx = getelementptr inbounds float, float* %3, i64 %idxprom
+// CHECK-NEXT: %5 = load float, float* %arrayidx, align 4, !llvm.access.group !3
+// CHECK-NEXT: %a2 = getelementptr inbounds %struct.S, %struct.S* %s, i32 0, i32 0
+// CHECK-NEXT: %6 = load i32, i32* %a2, align 4, !llvm.access.group !3
+// CHECK-NEXT: %conv = sitofp i32 %6 to float
+// CHECK-NEXT: %add = fadd float %5, %conv
+// CHECK-NEXT: %7 = load %struct.S*, %struct.S** %p, align 8, !llvm.access.group !3
+// CHECK-NEXT: %a3 = getelementptr inbounds %struct.S, %struct.S* %7, i32 0, i32 0
+// CHECK-NEXT: %8 = load i32, i32* %a3, align 4, !llvm.access.group !3
+// CHECK-NEXT: %conv4 = sitofp i32 %8 to float
+// CHECK-NEXT: %add5 = fadd float %add, %conv4
+   

[PATCH] D98657: [flang][driver] Add options for -Werror

2021-04-25 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added a comment.

In D98657#2701673 , @crownyanguan 
wrote:

> How about -Wl option, it will cause link error  like " Only `-Werror` is 
> supported currently"

Thanks for pointing it out.  The issue was due to restricting -W` options in 
`f18` as well, this has been fixed with `4299ab6c5daf`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98657/new/

https://reviews.llvm.org/D98657

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98657: [flang][driver] Add options for -Werror

2021-04-05 Thread Arnamoy B via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7416e8a8431a: [flang][driver] Add options for -Werror 
(authored by arnamoy10).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98657/new/

https://reviews.llvm.org/D98657

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/werror_parse.f
  flang/test/Driver/werror_scan.f
  flang/test/Driver/werror_sema.f90
  flang/test/Driver/werror_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -511,8 +511,14 @@
 } else if (arg == "-fopenmp") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenMP);
   predefinitions.emplace_back("_OPENMP", "201511");
-} else if (arg == "-Werror") {
-  driver.warningsAreErrors = true;
+} else if (arg.find("-W") != std::string::npos) {
+  if (arg == "-Werror")
+driver.warningsAreErrors = true;
+  else {
+// Only -Werror is supported currently
+llvm::errs() << "Only `-Werror` is supported currently.\n";
+return EXIT_FAILURE;
+  }
 } else if (arg == "-ed") {
   options.features.Enable(Fortran::common::LanguageFeature::OldDebugLines);
 } else if (arg == "-E") {
Index: flang/test/Driver/werror_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/werror_wrong.f90
@@ -0,0 +1,9 @@
+! Ensure that only argument -Werror is supported.
+
+! RUN: not %flang_fc1 -fsyntax-only -Wall %s  2>&1 | FileCheck %s --check-prefix=WRONG
+! RUN: not %flang_fc1 -fsyntax-only -WX %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH -W
+!-
+! WRONG: Only `-Werror` is supported currently.
Index: flang/test/Driver/werror_sema.f90
===
--- /dev/null
+++ flang/test/Driver/werror_sema.f90
@@ -0,0 +1,31 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAndSemaAction, particularly for Semantic warnings/errors.
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+
+
+! RUN: %flang_fc1 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+
+!-
+! EXPECTED OUTPUT WITH -Werror
+!-
+! WITH: Semantic errors in
+
+!-
+! EXPECTED OUTPUT WITHOUT -Werror
+!-
+! WITHOUT-NOT: Semantic errors in
+
+PROGRAM werror
+REAL, DIMENSION(20, 10) :: A
+FORALL (J=1:N)  A(I, I) = 1
+END PROGRAM werror
Index: flang/test/Driver/werror_scan.f
===
--- /dev/null
+++ flang/test/Driver/werror_scan.f
@@ -0,0 +1,25 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAction
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -E -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-parsing-log -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-provenance -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not 

[PATCH] D98657: [flang][driver] Add options for -Werror

2021-04-05 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 335255.
arnamoy10 added a comment.

Adding newline at the end of a test case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98657/new/

https://reviews.llvm.org/D98657

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/werror_parse.f
  flang/test/Driver/werror_scan.f
  flang/test/Driver/werror_sema.f90
  flang/test/Driver/werror_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -511,8 +511,14 @@
 } else if (arg == "-fopenmp") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenMP);
   predefinitions.emplace_back("_OPENMP", "201511");
-} else if (arg == "-Werror") {
-  driver.warningsAreErrors = true;
+} else if (arg.find("-W") != std::string::npos) {
+  if (arg == "-Werror")
+driver.warningsAreErrors = true;
+  else {
+// Only -Werror is supported currently
+llvm::errs() << "Only `-Werror` is supported currently.\n";
+return EXIT_FAILURE;
+  }
 } else if (arg == "-ed") {
   options.features.Enable(Fortran::common::LanguageFeature::OldDebugLines);
 } else if (arg == "-E") {
Index: flang/test/Driver/werror_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/werror_wrong.f90
@@ -0,0 +1,9 @@
+! Ensure that only argument -Werror is supported.
+
+! RUN: not %flang_fc1 -fsyntax-only -Wall %s  2>&1 | FileCheck %s --check-prefix=WRONG
+! RUN: not %flang_fc1 -fsyntax-only -WX %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH -W
+!-
+! WRONG: Only `-Werror` is supported currently.
Index: flang/test/Driver/werror_sema.f90
===
--- /dev/null
+++ flang/test/Driver/werror_sema.f90
@@ -0,0 +1,31 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAndSemaAction, particularly for Semantic warnings/errors.
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+
+
+! RUN: %flang_fc1 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+
+!-
+! EXPECTED OUTPUT WITH -Werror
+!-
+! WITH: Semantic errors in
+
+!-
+! EXPECTED OUTPUT WITHOUT -Werror
+!-
+! WITHOUT-NOT: Semantic errors in
+
+PROGRAM werror
+REAL, DIMENSION(20, 10) :: A
+FORALL (J=1:N)  A(I, I) = 1
+END PROGRAM werror
Index: flang/test/Driver/werror_scan.f
===
--- /dev/null
+++ flang/test/Driver/werror_scan.f
@@ -0,0 +1,25 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAction
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -E -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-parsing-log -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-provenance -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-measure-parse-tree -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: %flang_fc1 -fsyntax-only -E %s  2>&1 | 

[PATCH] D98657: [flang][driver] Add options for -Werror

2021-04-05 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 335246.
arnamoy10 added a comment.

1. Separated test cases to check prescan, parse and sema differently.
2. Diagnostics is thrown when anything other that `error` is given for `-W`.  
This behaviour is reflected in `f18


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98657/new/

https://reviews.llvm.org/D98657

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/werror_parse.f
  flang/test/Driver/werror_scan.f
  flang/test/Driver/werror_sema.f90
  flang/test/Driver/werror_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -511,8 +511,14 @@
 } else if (arg == "-fopenmp") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenMP);
   predefinitions.emplace_back("_OPENMP", "201511");
-} else if (arg == "-Werror") {
-  driver.warningsAreErrors = true;
+} else if (arg.find("-W") != std::string::npos) {
+  if (arg == "-Werror")
+driver.warningsAreErrors = true;
+  else {
+// Only -Werror is supported currently
+llvm::errs() << "Only `-Werror` is supported currently.\n";
+return EXIT_FAILURE;
+  }
 } else if (arg == "-ed") {
   options.features.Enable(Fortran::common::LanguageFeature::OldDebugLines);
 } else if (arg == "-E") {
Index: flang/test/Driver/werror_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/werror_wrong.f90
@@ -0,0 +1,9 @@
+! Ensure that only argument -Werror is supported.
+
+! RUN: not %flang_fc1 -fsyntax-only -Wall %s  2>&1 | FileCheck %s --check-prefix=WRONG
+! RUN: not %flang_fc1 -fsyntax-only -WX %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH -W
+!-
+! WRONG: Only `-Werror` is supported currently.
\ No newline at end of file
Index: flang/test/Driver/werror_sema.f90
===
--- /dev/null
+++ flang/test/Driver/werror_sema.f90
@@ -0,0 +1,31 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAndSemaAction, particularly for Semantic warnings/errors.
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+
+
+! RUN: %flang_fc1 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+
+!-
+! EXPECTED OUTPUT WITH -Werror
+!-
+! WITH: Semantic errors in
+
+!-
+! EXPECTED OUTPUT WITHOUT -Werror
+!-
+! WITHOUT-NOT: Semantic errors in
+
+PROGRAM werror
+REAL, DIMENSION(20, 10) :: A
+FORALL (J=1:N)  A(I, I) = 1
+END PROGRAM werror
Index: flang/test/Driver/werror_scan.f
===
--- /dev/null
+++ flang/test/Driver/werror_scan.f
@@ -0,0 +1,25 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAction
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -E -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-parsing-log -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-provenance -Werror %s  2>&1 | FileCheck %s 

[PATCH] D99645: [flang][driver] Add debug options not requiring semantic checks

2021-03-31 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/test/Parser/omp-allocate-unparse.f90:1
-! RUN: %f18 -fdebug-no-semantics -funparse -fopenmp %s | FileCheck %s
+! RUN: %flang_fc1 -fdebug-unparse-no-sema -fopenmp %s | FileCheck %s
 ! Check Unparsing of OpenMP Allocate directive

We probably need to add an alias to `f18` to make the two tests succeed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99645/new/

https://reviews.llvm.org/D99645

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98657: [flang][driver] Add options for -Werror

2021-03-29 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 333843.
arnamoy10 added a comment.

Modifying the test cases to:

1. Make it work for `f18` (when `flang-new` is not installed)
2. Adding more options and one test case to check correct functionality with 
`PrescanAction` and `PrescanAndSemaAction`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98657/new/

https://reviews.llvm.org/D98657

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/werror.f90
  flang/test/Driver/werror_scan.f

Index: flang/test/Driver/werror_scan.f
===
--- /dev/null
+++ flang/test/Driver/werror_scan.f
@@ -0,0 +1,32 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAction
+! TODO: Modify test cases in test/Semantics/ related to f18 when -std= is upstreamed
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang_fc1 -fsyntax-only -E -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-parsing-log -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-provenance -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-measure-parse-tree -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: %flang_fc1 -fsyntax-only -E %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-parsing-log %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-provenance %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-measure-parse-tree %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+
+!-
+! EXPECTED OUTPUT WITH -Werror
+!-
+! WITH: Could not scan
+
+!-
+! EXPECTED OUTPUT WITHOUT -Werror
+!-
+! WITHOUT-NOT: Could not scan
+
+1 continue
+end
Index: flang/test/Driver/werror.f90
===
--- /dev/null
+++ flang/test/Driver/werror.f90
@@ -0,0 +1,37 @@
+! Ensure argument -Werror work as expected.
+! TODO: Modify test cases in test/Semantics/ related to f18 when -std= is upstreamed
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang_fc1 -fsyntax-only -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+
+
+! RUN: %flang_fc1 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+
+!-
+! EXPECTED OUTPUT WITH -Werror
+!-
+! WITH: Semantic errors in
+
+!-
+! EXPECTED OUTPUT WITHOUT -Werror
+!-
+! WITHOUT-NOT: Semantic errors in
+
+PROGRAM werror
+REAL, DIMENSION(20, 10) :: A
+FORALL (J=1:N)  A(I, I) = 1
+END PROGRAM werror
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -51,6 +51,7 @@
 ! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
+! HELP-NEXT: -WEnable the specified 

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-25 Thread Arnamoy B via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4c7ebf79e923: [flang][driver] Add options for -std=f2018 
(authored by arnamoy10).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/std2018.f90
  flang/test/Driver/std2018_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -487,7 +487,8 @@
   options.features.Enable(
   Fortran::common::LanguageFeature::BackslashEscapes, true);
 } else if (arg == "-Mstandard" || arg == "-std=f95" ||
-arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy") {
+arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy" ||
+arg == "-std=f2018" || arg == "-pedantic") {
   driver.warnOnNonstandardUsage = true;
 } else if (arg == "-fopenacc") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenACC);
Index: flang/test/Driver/std2018_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/std2018_wrong.f90
@@ -0,0 +1,12 @@
+! REQUIRES: new-flang-driver
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang_fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=f2018 is allowed currently.
Index: flang/test/Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Driver/std2018.f90
@@ -0,0 +1,28 @@
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang_fc1 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang_fc1 -fsyntax-only -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -47,6 +47,8 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
@@ -96,6 +98,8 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -pedantic  Warn on language extensions
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -47,6 +47,8 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -pedantic  Warn on language 

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-25 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 11.
arnamoy10 added a comment.

Updating test case to add `-fsyntax-only` to share with `f18 `


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/std2018.f90
  flang/test/Driver/std2018_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -487,7 +487,8 @@
   options.features.Enable(
   Fortran::common::LanguageFeature::BackslashEscapes, true);
 } else if (arg == "-Mstandard" || arg == "-std=f95" ||
-arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy") {
+arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy" ||
+arg == "-std=f2018" || arg == "-pedantic") {
   driver.warnOnNonstandardUsage = true;
 } else if (arg == "-fopenacc") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenACC);
Index: flang/test/Driver/std2018_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/std2018_wrong.f90
@@ -0,0 +1,12 @@
+! REQUIRES: new-flang-driver
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang_fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=f2018 is allowed currently.
Index: flang/test/Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Driver/std2018.f90
@@ -0,0 +1,28 @@
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang_fc1 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang_fc1 -fsyntax-only -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -47,6 +47,8 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
@@ -96,6 +98,8 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -pedantic  Warn on language extensions
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -47,6 +47,8 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -pedantic  Warn on language extensions
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: 

[PATCH] D98657: [flang][driver] Add options for -Werror

2021-03-24 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 332997.
arnamoy10 added a comment.

rebasing on top of main


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98657/new/

https://reviews.llvm.org/D98657

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/werror.f90

Index: flang/test/Driver/werror.f90
===
--- /dev/null
+++ flang/test/Driver/werror.f90
@@ -0,0 +1,27 @@
+! Ensure argument -Werror work as expected.
+! TODO: Modify test cases in test/Semantics/ related to f18 when -std= is upstreamed
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang_fc1 -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: %flang_fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+
+!-
+! EXPECTED OUTPUT WITH -Werror
+!-
+! WITH: Semantic errors in
+
+!-
+! EXPECTED OUTPUT WITHOUT -Werror
+!-
+! WITHOUT-NOT: Semantic errors in
+
+PROGRAM werror
+REAL, DIMENSION(20, 10) :: A
+FORALL (J=1:N)  A(I, I) = 1
+END PROGRAM werror
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -49,6 +49,7 @@
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
+! HELP-NEXT: -WEnable the specified warning
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
 
 !-
@@ -99,6 +100,7 @@
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
+! HELP-FC1-NEXT: -WEnable the specified warning
 
 !---
 ! EXPECTED ERROR
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -49,6 +49,7 @@
 ! CHECK-NEXT: -o  Write output to 
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
+! CHECK-NEXT: -WEnable the specified warning
 ! CHECK-NEXT: -Xflang   Pass  to the flang compiler
 
 !-
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -64,7 +64,9 @@
   // Prescan. In case of failure, report and return.
   ci.parsing().Prescan(currentInputPath, parserOptions);
 
-  if (ci.parsing().messages().AnyFatalError()) {
+  if (!ci.parsing().messages().empty() &&
+  (ci.invocation().warnAsErr() ||
+  ci.parsing().messages().AnyFatalError())) {
 const unsigned diagID = ci.diagnostics().getCustomDiagID(
 clang::DiagnosticsEngine::Error, "Could not scan %0");
 ci.diagnostics().Report(diagID) << GetCurrentFileOrBufferName();
@@ -97,7 +99,9 @@
   // Prescan. In case of failure, report and return.
   ci.parsing().Prescan(currentInputPath, parserOptions);
 
-  if (ci.parsing().messages().AnyFatalError()) {
+  if (!ci.parsing().messages().empty() &&
+  (ci.invocation().warnAsErr() ||
+  ci.parsing().messages().AnyFatalError())) {
 const unsigned diagID = ci.diagnostics().getCustomDiagID(
 clang::DiagnosticsEngine::Error, "Could not scan %0");
 ci.diagnostics().Report(diagID) << GetCurrentFileOrBufferName();
@@ -109,7 +113,9 @@
   // Parse. In case of failure, report and return.
   ci.parsing().Parse(llvm::outs());
 
-  if (ci.parsing().messages().AnyFatalError()) {
+  if (!ci.parsing().messages().empty() &&
+  (ci.invocation().warnAsErr() ||
+  ci.parsing().messages().AnyFatalError())) {
 unsigned diagID = ci.diagnostics().getCustomDiagID(
 clang::DiagnosticsEngine::Error, "Could not parse %0");
 ci.diagnostics().Report(diagID) << GetCurrentFileOrBufferName();
@@ -264,7 +270,9 @@
   // Parse. In case of failure, report and return.
   ci.parsing().Parse(llvm::outs());
 
-  if (ci.parsing().messages().AnyFatalError()) {
+  if (!ci.parsing().messages().empty() &&
+  

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-24 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 332991.
arnamoy10 added a comment.

Rebasing on top of main


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/std2018.f90
  flang/test/Driver/std2018_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -487,7 +487,8 @@
   options.features.Enable(
   Fortran::common::LanguageFeature::BackslashEscapes, true);
 } else if (arg == "-Mstandard" || arg == "-std=f95" ||
-arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy") {
+arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy" ||
+arg == "-std=f2018" || arg == "-pedantic") {
   driver.warnOnNonstandardUsage = true;
 } else if (arg == "-fopenacc") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenACC);
Index: flang/test/Driver/std2018_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/std2018_wrong.f90
@@ -0,0 +1,12 @@
+! REQUIRES: new-flang-driver
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang_fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=f2018 is allowed currently.
Index: flang/test/Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Driver/std2018.f90
@@ -0,0 +1,28 @@
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang_fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang_fc1 -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -47,6 +47,8 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
@@ -96,6 +98,8 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -pedantic  Warn on language extensions
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -47,6 +47,8 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -pedantic  Warn on language extensions
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
 ! CHECK-NEXT: -Xflang   Pass  to the 

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-23 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 332703.
arnamoy10 added a comment.

1. Leaning out the "wrong-option" test case
2. Adding aliases in f18 (`-pedantic` and `-std=2018` for `-Mstandard`)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/std2018.f90
  flang/test/Driver/std2018_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -487,7 +487,8 @@
   options.features.Enable(
   Fortran::common::LanguageFeature::BackslashEscapes, true);
 } else if (arg == "-Mstandard" || arg == "-std=f95" ||
-arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy") {
+arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy" ||
+arg == "-std=f2018" || arg == "-pedantic") {
   driver.warnOnNonstandardUsage = true;
 } else if (arg == "-fopenacc") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenACC);
Index: flang/test/Driver/std2018_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/std2018_wrong.f90
@@ -0,0 +1,12 @@
+! REQUIRES: new-flang-driver
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang_fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=f2018 is allowed currently.
Index: flang/test/Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Driver/std2018.f90
@@ -0,0 +1,28 @@
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang_fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang_fc1 -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -45,6 +45,8 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
@@ -92,6 +94,8 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -pedantic  Warn on language extensions
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -45,6 +45,8 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -pedantic  Warn on language extensions
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -U  Undefine macro 
 ! 

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-23 Thread Arnamoy B via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd4abc5242c0: [flang][driver] Add -fintrinsic-modules-path 
option (authored by Arnamoy Bhattacharyya 
arnamoy.bhattachar...@huawei.com, committed by arnamoy10).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/Inputs/ieee_arithmetic.mod
  flang/test/Driver/Inputs/iso_fortran_env.mod
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/intrinsic_module_path.f90

Index: flang/test/Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Driver/intrinsic_module_path.f90
@@ -0,0 +1,37 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+! WITHOUT the option, the default location for the module is checked and no error generated.
+! With the option GIVEN, the module with the same name is PREPENDED, and considered over the
+! default one, causing a CHECKSUM error.
+
+! REQUIRES: new-flang-driver
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
+! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -83,6 +85,8 @@
 ! HELP-FC1-NEXT: -fget-symbols-sources   Dump symbols and their source code locations
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! 

[PATCH] D98657: [flang][driver] Add options for -Werror

2021-03-23 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 332692.
arnamoy10 added a comment.

Thanks @awarzynski for the comments.

1. Moving diagnostics options parsing to a separate function
2. Adding a check so that `-Wblah` does not trigger the treatment of warnings 
as werrors, only `-Werror` triggers it
3. Adding a new test case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98657/new/

https://reviews.llvm.org/D98657

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/werror.f90

Index: flang/test/Driver/werror.f90
===
--- /dev/null
+++ flang/test/Driver/werror.f90
@@ -0,0 +1,27 @@
+! Ensure argument -Werror work as expected.
+! TODO: Modify test cases in test/Semantics/ related to f18 when -std= is upstreamed
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang_fc1 -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: %flang_fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+
+!-
+! EXPECTED OUTPUT WITH -Werror
+!-
+! WITH: Semantic errors in
+
+!-
+! EXPECTED OUTPUT WITHOUT -Werror
+!-
+! WITHOUT-NOT: Semantic errors in
+
+PROGRAM werror
+REAL, DIMENSION(20, 10) :: A
+FORALL (J=1:N)  A(I, I) = 1
+END PROGRAM werror
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -47,6 +47,7 @@
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
+! HELP-NEXT: -WEnable the specified warning
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
 
 !-
@@ -95,6 +96,7 @@
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
+! HELP-FC1-NEXT: -WEnable the specified warning
 
 !---
 ! EXPECTED ERROR
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -47,6 +47,7 @@
 ! CHECK-NEXT: -o  Write output to 
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
+! CHECK-NEXT: -WEnable the specified warning
 ! CHECK-NEXT: -Xflang   Pass  to the flang compiler
 
 !-
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -64,7 +64,9 @@
   // Prescan. In case of failure, report and return.
   ci.parsing().Prescan(currentInputPath, parserOptions);
 
-  if (ci.parsing().messages().AnyFatalError()) {
+  if (!ci.parsing().messages().empty() &&
+  (ci.invocation().warnAsErr() ||
+  ci.parsing().messages().AnyFatalError())) {
 const unsigned diagID = ci.diagnostics().getCustomDiagID(
 clang::DiagnosticsEngine::Error, "Could not scan %0");
 ci.diagnostics().Report(diagID) << GetCurrentFileOrBufferName();
@@ -97,7 +99,9 @@
   // Prescan. In case of failure, report and return.
   ci.parsing().Prescan(currentInputPath, parserOptions);
 
-  if (ci.parsing().messages().AnyFatalError()) {
+  if (!ci.parsing().messages().empty() &&
+  (ci.invocation().warnAsErr() ||
+  ci.parsing().messages().AnyFatalError())) {
 const unsigned diagID = ci.diagnostics().getCustomDiagID(
 clang::DiagnosticsEngine::Error, "Could not scan %0");
 ci.diagnostics().Report(diagID) << GetCurrentFileOrBufferName();
@@ -109,7 +113,9 @@
   // Parse. In case of failure, report and return.
   ci.parsing().Parse(llvm::outs());
 
-  if (ci.parsing().messages().AnyFatalError()) {
+  if (!ci.parsing().messages().empty() &&
+  (ci.invocation().warnAsErr() ||
+  ci.parsing().messages().AnyFatalError())) {
 unsigned diagID = ci.diagnostics().getCustomDiagID(
 clang::DiagnosticsEngine::Error, "Could not parse %0");
 ci.diagnostics().Report(diagID) << GetCurrentFileOrBufferName();
@@ -264,7 

[PATCH] D98657: [flang][driver] Add options for -Werror

2021-03-23 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/test/Semantics/dosemantics03.f90:1-2
 ! RUN: %S/test_errors.sh %s %t %f18 -Mstandard -Werror
+! RUN: %S/test_errors.sh %s %t %flang_fc1 -Werror
 

awarzynski wrote:
> Rather than adding the 2nd line, could you update the first line to use 
> `%flang_fc1` instead of `%f18`?
I am not modifying this test case, as it would create a dependency on 
`-std=f2018` up-streamed (due to this particular test case having dependency on 
language standard).  I create a new test case, we can come back to it later.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98657/new/

https://reviews.llvm.org/D98657

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-23 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 332649.
arnamoy10 added a comment.

Addressing minor issues


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/Inputs/ieee_arithmetic.mod
  flang/test/Driver/Inputs/iso_fortran_env.mod
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/intrinsic_module_path.f90

Index: flang/test/Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Driver/intrinsic_module_path.f90
@@ -0,0 +1,37 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+! WITHOUT the option, the default location for the module is checked and no error generated.
+! With the option GIVEN, the module with the same name is PREPENDED, and considered over the
+! default one, causing a CHECKSUM error.
+
+! REQUIRES: new-flang-driver
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
+! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -83,6 +85,8 @@
 ! HELP-FC1-NEXT: -fget-symbols-sources   Dump symbols and their source code locations
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
Index: flang/test/Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null
+++ flang/test/Driver/Inputs/iso_fortran_env.mod
@@ 

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-19 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:298
+  driverPath.append("/../include/flang/");
+  return driverPath.str().str();
+}

awarzynski wrote:
> Given this [[ 
> https://github.com/llvm/llvm-project/blob/987ee6e3cc1fb672b3ed201e72a5281c2ec88c99/llvm/include/llvm/ADT/SmallString.h#L271-L273
>  | conversion operator ]], wouldn't `return std::string(driverPath);` be more 
> efficient? 
Done, thanks


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-19 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 331984.
arnamoy10 added a comment.

Addressing reviewers' comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/Inputs/ieee_arithmetic.mod
  flang/test/Driver/Inputs/iso_fortran_env.mod
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/intrinsic_module_path.f90

Index: flang/test/Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Driver/intrinsic_module_path.f90
@@ -0,0 +1,37 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+! WITHOUT the option, the default location for the module is checked and no error generated.
+! With the option GIVEN, the module with the same name is PREPENDED, and considered over the
+! default one, causing a CHECKSUM error.
+
+! REQUIRES: new-flang-driver
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
+! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -83,6 +85,8 @@
 ! HELP-FC1-NEXT: -fget-symbols-sources   Dump symbols and their source code locations
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
Index: flang/test/Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null
+++ flang/test/Driver/Inputs/iso_fortran_env.mod

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-19 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/test/Driver/std2018.f90:1
+! REQUIRES: new-flang-driver
+! Ensure argument -std=f2018 works as expected.

awarzynski wrote:
> Would it be possible to share this test with `f18`?
Would you please elaborate on how do want the sharing to happen (same test 
file/different test file)?  I think in a previous comment you mentioned that it 
is sufficient to test the frontend driver for this patch?



Comment at: flang/test/Driver/std2018_wrong.f90:14-22
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"

awarzynski wrote:
> No input is needed for this test, is it? IIUC, this bit can be deleted to 
> make the test leaner.
Sure, will do.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-19 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:292
+  std::string driverPath = llvm::sys::fs::getMainExecutable(nullptr, nullptr);
+  driverPath = driverPath.substr(0, driverPath.size() - 9);
+  return driverPath.append("/../include/flang/");

awarzynski wrote:
> arnamoy10 wrote:
> > bryanpkc wrote:
> > > Can you use `llvm::sys::path::remove_filename` here?
> > Thank you.  This seems like a better option, but I could not make it work.  
> > For the sake of time I am keeping this hard coded manipulation.  It can be 
> > improved in a later revision.
> It would be really nice to use `llvm::sys::path::remove_filename` instead. 
> Perhaps something like this:
> ```
> llvm::SmallString<128> driverPath;
> driverPath.assign(llvm::sys::fs::getMainExecutable(nullptr, nullptr));
> llvm::sys::path::remove_filename(driverPath);
> ```
> ?
This works, thanks for the code!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-19 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 331888.
arnamoy10 added a comment.

Using `llvm::sys::path::remove_filename` as per suggestion.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/Inputs/ieee_arithmetic.mod
  flang/test/Driver/Inputs/iso_fortran_env.mod
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/intrinsic_module_path.f90

Index: flang/test/Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Driver/intrinsic_module_path.f90
@@ -0,0 +1,37 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+! WITHOUT the option, the default location for the module is checked and no error generated.
+! With the option GIVEN, the module with the same name is PREPENDED, and considered over the
+! default one, causing a CHECKSUM error.
+
+! REQUIRES: new-flang-driver
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
+! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -83,6 +85,8 @@
 ! HELP-FC1-NEXT: -fget-symbols-sources   Dump symbols and their source code locations
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
Index: flang/test/Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null
+++ 

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-19 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 331871.
arnamoy10 added a comment.

Separating test cases for accepted input option and not accepted input option.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/std2018.f90
  flang/test/Driver/std2018_wrong.f90

Index: flang/test/Driver/std2018_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/std2018_wrong.f90
@@ -0,0 +1,22 @@
+! REQUIRES: new-flang-driver
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang_fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=f2018 is allowed currently.
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Driver/std2018.f90
@@ -0,0 +1,29 @@
+! REQUIRES: new-flang-driver
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang_fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang_fc1 -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -45,6 +45,8 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
@@ -92,6 +94,8 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -pedantic  Warn on language extensions
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -45,6 +45,8 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -pedantic  Warn on language extensions
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
 ! CHECK-NEXT: -Xflang   Pass  to the flang compiler
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -371,6 +371,26 @@
 res.frontendOpts().features_.Enable(
 Fortran::common::LanguageFeature::OpenMP);
   }
+
+  //-fpedantic
+  if (args.hasArg(clang::driver::options::OPT_pedantic)) {
+res.set_EnableConformanceChecks();

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-18 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:292
+  std::string driverPath = llvm::sys::fs::getMainExecutable(nullptr, nullptr);
+  driverPath = driverPath.substr(0, driverPath.size() - 9);
+  return driverPath.append("/../include/flang/");

bryanpkc wrote:
> Can you use `llvm::sys::path::remove_filename` here?
Thank you.  This seems like a better option, but I could not make it work.  For 
the sake of time I am keeping this hard coded manipulation.  It can be improved 
in a later revision.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-18 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 331528.
arnamoy10 added a comment.

Fixing bug in test case


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/Inputs/ieee_arithmetic.mod
  flang/test/Driver/Inputs/iso_fortran_env.mod
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/intrinsic_module_path.f90

Index: flang/test/Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Driver/intrinsic_module_path.f90
@@ -0,0 +1,37 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+! WITHOUT the option, the default location for the module is checked and no error generated.
+! With the option GIVEN, the module with the same name is PREPENDED, and considered over the
+! default one, causing a CHECKSUM error.
+
+! REQUIRES: new-flang-driver
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
+! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -82,6 +84,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
Index: flang/test/Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null
+++ flang/test/Driver/Inputs/iso_fortran_env.mod
@@ -0,0 +1,7 @@
+! 

[PATCH] D98657: [flang][driver] Add options for -Werror

2021-03-16 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 331009.
arnamoy10 added a comment.

Updating to use available option from `Options.td` instead of creating a new 
option for `-Werror`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98657/new/

https://reviews.llvm.org/D98657

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Semantics/dosemantics03.f90

Index: flang/test/Semantics/dosemantics03.f90
===
--- flang/test/Semantics/dosemantics03.f90
+++ flang/test/Semantics/dosemantics03.f90
@@ -1,4 +1,5 @@
 ! RUN: %S/test_errors.sh %s %t %f18 -Mstandard -Werror
+! RUN: %S/test_errors.sh %s %t %flang_fc1 -Werror
 
 ! Issue 458 -- semantic checks for a normal DO loop.  The DO variable
 ! and the initial, final, and step expressions must be INTEGER if the
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -47,6 +47,7 @@
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
+! HELP-NEXT: -WEnable the specified warning
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
 
 !-
@@ -94,6 +95,7 @@
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
+! HELP-FC1-NEXT: -WEnable the specified warning
 
 !---
 ! EXPECTED ERROR
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -47,6 +47,7 @@
 ! CHECK-NEXT: -o  Write output to 
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
+! CHECK-NEXT: -WEnable the specified warning
 ! CHECK-NEXT: -Xflang   Pass  to the flang compiler
 
 !-
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -327,6 +327,11 @@
   if (args.hasArg(clang::driver::options::OPT_fdebug_module_writer)) {
 res.SetDebugModuleDir(true);
   }
+
+  // -Werror option
+  if (args.hasArg(clang::driver::options::OPT_W_Joined)) {
+res.SetWarnAsErr(true);
+  }
 }
 
 /// Parses all Dialect related arguments and populates the variables
@@ -518,5 +523,6 @@
   defaultKinds(), fortranOptions.features, allCookedSources);
 
   semanticsContext_->set_moduleDirectory(moduleDir())
-  .set_searchDirectories(fortranOptions.searchDirectories);
+  .set_searchDirectories(fortranOptions.searchDirectories)
+  .set_warningsAreErrors(warnAsErr());
 }
Index: flang/include/flang/Frontend/CompilerInvocation.h
===
--- flang/include/flang/Frontend/CompilerInvocation.h
+++ flang/include/flang/Frontend/CompilerInvocation.h
@@ -71,6 +71,8 @@
 
   bool debugModuleDir_ = false;
 
+  bool warnAsErr_ = false;
+
   // Fortran Dialect options
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
 
@@ -96,6 +98,9 @@
   bool () { return debugModuleDir_; }
   const bool () const { return debugModuleDir_; }
 
+  bool () { return warnAsErr_; }
+  const bool () const { return warnAsErr_; }
+
   Fortran::common::IntrinsicTypeDefaultKinds () {
 return defaultKinds_;
   }
@@ -116,6 +121,8 @@
 
   void SetDebugModuleDir(bool flag) { debugModuleDir_ = flag; }
 
+  void SetWarnAsErr(bool flag) { warnAsErr_ = flag; }
+
   /// Set the Fortran options to predifined defaults. These defaults are
   /// consistend with f18/f18.cpp.
   // TODO: We should map frontendOpts_ to parserOpts_ instead. For that, we
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -42,7 +42,8 @@
 
 void Flang::AddOtherOptions(const ArgList , ArgStringList ) const {
   Args.AddAllArgs(CmdArgs,
-  {options::OPT_module_dir, options::OPT_fdebug_module_writer});
+  {options::OPT_module_dir, options::OPT_fdebug_module_writer,
+   options::OPT_W_Joined});
 }
 
 void Flang::ConstructJob(Compilation , const JobAction ,
Index: clang/include/clang/Driver/Options.td

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-16 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 330973.
arnamoy10 added a comment.

Moving -std to non-dialect option


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/std2018.f90

Index: flang/test/Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Driver/std2018.f90
@@ -0,0 +1,35 @@
+! REQUIRES: new-flang-driver
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang_fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang_fc1 -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: not %flang_fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=f2018 is allowed currently.
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -45,6 +45,8 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
@@ -91,6 +93,8 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -pedantic  Warn on language extensions
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -45,6 +45,8 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -pedantic  Warn on language extensions
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
 ! CHECK-NEXT: -Xflang   Pass  to the flang compiler
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -368,6 +368,26 @@
 res.frontendOpts().features_.Enable(
 Fortran::common::LanguageFeature::OpenMP);
   }
+
+  //-fpedantic
+  if (args.hasArg(clang::driver::options::OPT_pedantic)) {
+res.set_EnableConformanceChecks();
+  }
+  // -std=f2018.  Current behaviour is same as -fpedantic
+  // TODO: Set proper options when more fortran standards
+  // are supported.
+  if (args.hasArg(clang::driver::options::OPT_std_EQ)) {
+auto standard = args.getLastArgValue(clang::driver::options::OPT_std_EQ);
+// We only allow f2018 as the given standard
+if (standard.equals("f2018")) {
+  res.set_EnableConformanceChecks();
+} else {
+  const unsigned diagID =
+  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only -std=f2018 is allowed currently.");
+  diags.Report(diagID);
+}
+  }
   return;
 }
 
@@ -508,6 +528,11 @@
 
   

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-16 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 330968.
arnamoy10 added a comment.

Adding the test file


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/Inputs/ieee_arithmetic.mod
  flang/test/Driver/Inputs/iso_fortran_env.mod
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/intrinsic_module_path.f90

Index: flang/test/Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Driver/intrinsic_module_path.f90
@@ -0,0 +1,35 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+! WITHOUT the option, the default location for the module is checked and no error generated.
+! With the option GIVEN, the module with the same name is PREPENDED, and considered over the
+! default one, causing a CHECKSUM error.
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
+! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -82,6 +84,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
Index: flang/test/Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null
+++ flang/test/Driver/Inputs/iso_fortran_env.mod
@@ -0,0 +1,7 @@
+! DUMMY module
+! Added for testing 

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-15 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 330823.
arnamoy10 added a comment.

Adding one more update that is probably required in semanticContext (inspired 
by f18), also updated test case to require flang-driver


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/std2018.f90

Index: flang/test/Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Driver/std2018.f90
@@ -0,0 +1,35 @@
+! REQUIRES: new-flang-driver
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang_fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang_fc1 -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: not %flang_fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=f2018 is allowed currently.
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -45,6 +45,8 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
@@ -91,6 +93,8 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -pedantic  Warn on language extensions
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -45,6 +45,8 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -pedantic  Warn on language extensions
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
 ! CHECK-NEXT: -Xflang   Pass  to the flang compiler
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -368,6 +368,26 @@
 res.frontendOpts().features_.Enable(
 Fortran::common::LanguageFeature::OpenMP);
   }
+
+  //-fpedantic
+  if (args.hasArg(clang::driver::options::OPT_pedantic)) {
+res.set_EnableConformanceChecks();
+  }
+  // -std=f2018.  Current behaviour is same as -fpedantic
+  // TODO: Set proper options when more fortran standards
+  // are supported.
+  if (args.hasArg(clang::driver::options::OPT_std_EQ)) {
+auto standard = args.getLastArgValue(clang::driver::options::OPT_std_EQ);
+// We only allow f2018 as the given standard
+if (standard.equals("f2018")) {
+  res.set_EnableConformanceChecks();
+} else {
+  const unsigned diagID =
+  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only -std=f2018 is 

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-15 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 330785.
arnamoy10 added a comment.

Adding the dummy modules


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/Inputs/ieee_arithmetic.mod
  flang/test/Driver/Inputs/iso_fortran_env.mod
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90

Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -82,6 +84,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
Index: flang/test/Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null
+++ flang/test/Driver/Inputs/iso_fortran_env.mod
@@ -0,0 +1,7 @@
+! DUMMY module
+! Added for testing purposes. The contents of this file are currently not relevant.
+module iso_fortran_env
+use __fortran_builtins,only:event_type=>__builtin_event_type
+use __fortran_builtins,only:lock_type=>__builtin_lock_type
+use __fortran_builtins,only:team_type=>__builtin_team_type
+end
Index: flang/test/Driver/Inputs/ieee_arithmetic.mod
===
--- /dev/null
+++ flang/test/Driver/Inputs/ieee_arithmetic.mod
@@ -0,0 +1,7 @@
+! DUMMY module
+! Added for testing purposes. The contents of this file are currently not relevant.
+module ieee_arithmetic
+type::ieee_round_type
+integer(1),private::mode=0_1
+end type
+end
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -21,8 +21,11 @@
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/OptTable.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/raw_ostream.h"
+
 #include 
 
 using namespace Fortran::frontend;
@@ -282,6 +285,14 @@
   return dashX;
 }
 
+// Generate the path to look for intrinsic modules
+static std::string getIntrinsicDir() {
+  // TODO: Find a system independent API
+  std::string driverPath = llvm::sys::fs::getMainExecutable(nullptr, nullptr);
+  driverPath = driverPath.substr(0, driverPath.size() - 9);
+  return driverPath.append("/../include/flang/");
+}
+
 /// Parses all preprocessor input arguments and populates the preprocessor
 /// options accordingly.
 ///
@@ -302,6 +313,12 @@
   // Add the ordered list of -I's.
   for (const auto *currentArg : args.filtered(clang::driver::options::OPT_I))
 

[PATCH] D98657: [flang][driver] Add options for -Werror

2021-03-15 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 created this revision.
arnamoy10 added reviewers: awarzynski, SouraVX, tskeith, AMDChirag, sscalpone, 
bryanpkc.
Herald added subscribers: jansvoboda11, dang.
arnamoy10 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add the following option for the flang-driver

`-Werror`

With the option given, warnings are treated as error.

Relevant f18 test file is also updated to include `flang-new`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98657

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Semantics/dosemantics03.f90


Index: flang/test/Semantics/dosemantics03.f90
===
--- flang/test/Semantics/dosemantics03.f90
+++ flang/test/Semantics/dosemantics03.f90
@@ -1,4 +1,5 @@
 ! RUN: %S/test_errors.sh %s %t %f18 -Mstandard -Werror
+! RUN: %S/test_errors.sh %s %t %flang_fc1 -Werror
 
 ! Issue 458 -- semantic checks for a normal DO loop.  The DO variable
 ! and the initial, final, and step expressions must be INTEGER if the
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -327,6 +327,11 @@
   if (args.hasArg(clang::driver::options::OPT_fdebug_module_writer)) {
 res.SetDebugModuleDir(true);
   }
+
+  // -Werror option
+  if (args.hasArg(clang::driver::options::OPT_werror)) {
+res.SetWarnAsErr(true);
+  }
 }
 
 /// Parses all Dialect related arguments and populates the variables
@@ -518,5 +523,6 @@
   defaultKinds(), fortranOptions.features, allCookedSources);
 
   semanticsContext_->set_moduleDirectory(moduleDir())
-  .set_searchDirectories(fortranOptions.searchDirectories);
+  .set_searchDirectories(fortranOptions.searchDirectories)
+  .set_warningsAreErrors(warnAsErr());
 }
Index: flang/include/flang/Frontend/CompilerInvocation.h
===
--- flang/include/flang/Frontend/CompilerInvocation.h
+++ flang/include/flang/Frontend/CompilerInvocation.h
@@ -71,6 +71,8 @@
 
   bool debugModuleDir_ = false;
 
+  bool warnAsErr_ = false;
+
   // Fortran Dialect options
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
 
@@ -96,6 +98,9 @@
   bool () { return debugModuleDir_; }
   const bool () const { return debugModuleDir_; }
 
+  bool () { return warnAsErr_; }
+  const bool () const { return warnAsErr_; }
+
   Fortran::common::IntrinsicTypeDefaultKinds () {
 return defaultKinds_;
   }
@@ -116,6 +121,8 @@
 
   void SetDebugModuleDir(bool flag) { debugModuleDir_ = flag; }
 
+  void SetWarnAsErr(bool flag) { warnAsErr_ = flag; }
+
   /// Set the Fortran options to predifined defaults. These defaults are
   /// consistend with f18/f18.cpp.
   // TODO: We should map frontendOpts_ to parserOpts_ instead. For that, we
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -42,7 +42,8 @@
 
 void Flang::AddOtherOptions(const ArgList , ArgStringList ) const 
{
   Args.AddAllArgs(CmdArgs,
-  {options::OPT_module_dir, 
options::OPT_fdebug_module_writer});
+  {options::OPT_module_dir, options::OPT_fdebug_module_writer,
+   options::OPT_werror});
 }
 
 void Flang::ConstructJob(Compilation , const JobAction ,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4342,6 +4342,8 @@
 def fno_implicit_none : Flag<["-"], "fno-implicit-none">, Group;
 def falternative_parameter_statement : Flag<["-"], 
"falternative-parameter-statement">, Group,
   HelpText<"Enable the old style PARAMETER statement">;
+def werror : Flag<["-"], "Werror">, Group,
+  HelpText<"Make all warnings into errors">;
 }
 
 
//===--===//


Index: flang/test/Semantics/dosemantics03.f90
===
--- flang/test/Semantics/dosemantics03.f90
+++ flang/test/Semantics/dosemantics03.f90
@@ -1,4 +1,5 @@
 ! RUN: %S/test_errors.sh %s %t %f18 -Mstandard -Werror
+! RUN: %S/test_errors.sh %s %t %flang_fc1 -Werror
 
 ! Issue 458 -- semantic checks for a normal DO loop.  The DO variable
 ! and the initial, final, and step expressions must be INTEGER if the
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -327,6 +327,11 @@
 

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-15 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 330762.
arnamoy10 added a comment.

1. Update the test case to only test `flang-new -fc1`
2. Updated help text
3. Clang-formatted and also removed redundant code


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/std2018.f90

Index: flang/test/Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Driver/std2018.f90
@@ -0,0 +1,34 @@
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang_fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang_fc1 -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: not %flang_fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=f2018 is allowed currently.
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -45,6 +45,8 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
@@ -91,6 +93,8 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -pedantic  Warn on language extensions
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -45,6 +45,8 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -pedantic  Warn on language extensions
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
 ! CHECK-NEXT: -Xflang   Pass  to the flang compiler
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -368,6 +368,26 @@
 res.frontendOpts().features_.Enable(
 Fortran::common::LanguageFeature::OpenMP);
   }
+
+  //-fpedantic
+  if (args.hasArg(clang::driver::options::OPT_pedantic)) {
+res.set_EnableConformanceChecks();
+  }
+  // -std=f2018.  Current behaviour is same as -fpedantic
+  // TODO: Set proper options when more fortran standards
+  // are supported.
+  if (args.hasArg(clang::driver::options::OPT_std_EQ)) {
+auto standard = args.getLastArgValue(clang::driver::options::OPT_std_EQ);
+// We only allow f2018 as the given standard
+if (standard.equals("f2018")) {
+  res.set_EnableConformanceChecks();
+} else {
+  const unsigned diagID =
+  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only -std=f2018 is allowed currently.");
+  

[PATCH] D96875: [flang][driver] Add -fdebug-module-writer option

2021-03-15 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added a comment.

Abandon


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96875/new/

https://reviews.llvm.org/D96875

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96875: [flang][driver] Add -fdebug-module-writer option

2021-03-15 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added a comment.

This has been merged, closing it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96875/new/

https://reviews.llvm.org/D96875

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-15 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 330711.
arnamoy10 added a comment.

Clang-formatting and addressing reviewers' comments:

Moved the default directory append to `setFortranOpts()`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/intrinsic_module_path.f90

Index: flang/test/Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Driver/intrinsic_module_path.f90
@@ -0,0 +1,35 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+! WITHOUT the option, the default location for the module is checked and no error generated.
+! With the option GIVEN, the module with the same name is PREPENDED, and considered over the
+! default one, causing a CHECKSUM error.
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
+! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -82,6 +84,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -21,8 +21,11 @@
 #include 

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-12 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 330337.
arnamoy10 edited the summary of this revision.
arnamoy10 added a comment.

Update the path based on the patch D98522 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/Inputs/ieee_arithmetic.mod
  flang/test/Driver/Inputs/iso_fortran_env.mod
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/intrinsic_module_path.f90

Index: flang/test/Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Driver/intrinsic_module_path.f90
@@ -0,0 +1,35 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+! WITHOUT the option, the default location for the module is checked and no error generated.
+! With the option GIVEN, the module with the same name is PREPENDED, and considered over the
+! default one, causing a CHECKSUM error.
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
+! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -82,6 +84,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
Index: flang/test/Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-12 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:293
+  driverPath = driverPath.substr(0, driverPath.size() - 9);
+  return driverPath.append("/../tools/flang/include/flang/");
+}

tskeith wrote:
> tskeith wrote:
> > arnamoy10 wrote:
> > > tskeith wrote:
> > > > Does this work for an install? I think there the path would be 
> > > > `include/flang` rather than `tools/flang/include/flang`.
> > > You are probably right, I am giving the path w.r.t a build.  Can we make 
> > > the assumption that there should be always an install?  Or do we 
> > > determine if we flang-new is coming from build or install (by checking if 
> > > a module file is present through ls)  and then set the path accordingly?
> > I think it should work in a build or an install. The 
> > `flang/tools/f18/flang` script checks for `include/flang` first and if that 
> > doesn't exist it uses `tools/flang/include/flang` so you could do the same. 
> > It would be good if we could fix the build or install so that the location 
> > is consistent.
> I've created D98522 to make the relative path be `include/flang` in both 
> build and install. If no one objects, that should make it so you don't need 
> conditional code here, just use `"/../include/flang"`.
Thanks for doing this


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-11 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:293
+  driverPath = driverPath.substr(0, driverPath.size() - 9);
+  return driverPath.append("/../tools/flang/include/flang/");
+}

tskeith wrote:
> Does this work for an install? I think there the path would be 
> `include/flang` rather than `tools/flang/include/flang`.
You are probably right, I am giving the path w.r.t a build.  Can we make the 
assumption that there should be always an install?  Or do we determine if we 
flang-new is coming from build or install (by checking if a module file is 
present through ls)  and then set the path accordingly?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-11 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 330049.
arnamoy10 added a comment.

Modifying the algo of default search path extraction for supporting Windows 
platforms.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/Inputs/ieee_arithmetic.mod
  flang/test/Driver/Inputs/iso_fortran_env.mod
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/intrinsic_module_path.f90

Index: flang/test/Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Driver/intrinsic_module_path.f90
@@ -0,0 +1,35 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+! WITHOUT the option, the default location for the module is checked and no error generated.
+! With the option GIVEN, the module with the same name is PREPENDED, and considered over the
+! default one, causing a CHECKSUM error.
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
+! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -82,6 +84,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
Index: flang/test/Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null
+++ 

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-11 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 330023.
arnamoy10 added a comment.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Updating the patch to make -pedantic and -f2018 behave the same way, also 
updated the test case accordingly.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/std2018.f90

Index: flang/test/Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Driver/std2018.f90
@@ -0,0 +1,44 @@
+! Ensure argument -std=f2018 works as expected.
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang-new -fsyntax-only -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang-new -fsyntax-only -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %f18 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %f18 -fsyntax-only -Mstandard %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: not %flang-new -fsyntax-only -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang_fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang_fc1 -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: not %flang_fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=f2018 is allowed currently.
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -368,6 +368,30 @@
 res.frontendOpts().features_.Enable(
 Fortran::common::LanguageFeature::OpenMP);
   }
+  if (args.hasArg(clang::driver::options::OPT_fopenmp)) {
+res.frontendOpts().features_.Enable(
+Fortran::common::LanguageFeature::OpenMP);
+  }
+
+  //-fpedantic
+  if (args.hasArg(clang::driver::options::OPT_pedantic)) {
+res.set_EnableConformanceChecks();
+  }
+  // -std=f2018.  Current behaviour is same as -fpedantic
+  // TODO: Set proper options when more fortran standards
+  // are supported.
+  if (args.hasArg(clang::driver::options::OPT_std_EQ)) {
+auto standard = args.getLastArgValue(clang::driver::options::OPT_std_EQ);
+// We only allow f2018 as the given standard
+if (standard.equals("f2018")) {
+  res.set_EnableConformanceChecks();
+} else {
+  const unsigned diagID =
+  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only -std=f2018 is allowed currently.");
+  diags.Report(diagID);
+}
+  }
   return;
 }
 
@@ -508,6 +532,11 @@
 
   if (frontendOptions.instrumentedParse_)
 fortranOptions.instrumentedParse = true;
+
+  // Set the standard
+  if (EnableConformanceChecks_) {
+fortranOptions.features.WarnOnAllNonstandard();
+  }
 }
 
 void CompilerInvocation::setSemanticsOpts(
Index: flang/include/flang/Frontend/CompilerInvocation.h
===
--- flang/include/flang/Frontend/CompilerInvocation.h
+++ flang/include/flang/Frontend/CompilerInvocation.h
@@ -74,6 +74,8 @@
   // Fortran Dialect options
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
 
+  bool EnableConformanceChecks_ = false;
+
 public:
   CompilerInvocation() = default;
 
@@ -111,6 +113,9 @@
   llvm::ArrayRef commandLineArgs,
   clang::DiagnosticsEngine );
 
+  // Enables the std=f2018 conformance check
+  void set_EnableConformanceChecks() { EnableConformanceChecks_ = true; }
+
   /// Useful setters
   void SetModuleDir(std::string ) { moduleDir_ = moduleDir; }
 
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ 

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-11 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 329976.
arnamoy10 added a comment.

Clang-formatting


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/Inputs/ieee_arithmetic.mod
  flang/test/Driver/Inputs/iso_fortran_env.mod
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/intrinsic_module_path.f90

Index: flang/test/Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Driver/intrinsic_module_path.f90
@@ -0,0 +1,35 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+! WITHOUT the option, the default location for the module is checked and no error generated.
+! With the option GIVEN, the module with the same name is PREPENDED, and considered over the
+! default one, causing a CHECKSUM error.
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
+! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -82,6 +84,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
Index: flang/test/Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null
+++ flang/test/Driver/Inputs/iso_fortran_env.mod
@@ -0,0 +1,6 @@
+! DUMMY module
+module iso_fortran_env

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-11 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 329970.
arnamoy10 added a comment.
Herald added a subscriber: ormris.

1. Updated to set the default search directory for the intrinsic module
2. Modified the test case to check the prepend behavior


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/Inputs/ieee_arithmetic.mod
  flang/test/Driver/Inputs/iso_fortran_env.mod
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/intrinsic_module_path.f90

Index: flang/test/Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Driver/intrinsic_module_path.f90
@@ -0,0 +1,35 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+! WITHOUT the option, the default location for the module is checked and no error generated.
+! With the option GIVEN, the module with the same name is PREPENDED, and considered over the
+! default one, causing a CHECKSUM error.
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: 'ieee_arithmetic.mod' was not found
+! WITHOUT-NOT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: error: Cannot read module file for module 'ieee_arithmetic': File has invalid checksum
+! GIVEN: error: Cannot read module file for module 'iso_fortran_env': File has invalid checksum
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -35,6 +35,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
@@ -82,6 +84,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -35,6 +35,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
Index: flang/test/Driver/Inputs/iso_fortran_env.mod

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-03-10 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added a comment.

Thank you so much for this experiment @awarzynski .  I will modify the code 
accordingly.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96875: [flang][driver] Add -fdebug-module-writer option

2021-03-08 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 329100.
arnamoy10 added a comment.

Rebasing on main


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96875/new/

https://reviews.llvm.org/D96875

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Semantics/mod-file-rewriter.f90

Index: flang/test/Semantics/mod-file-rewriter.f90
===
--- flang/test/Semantics/mod-file-rewriter.f90
+++ flang/test/Semantics/mod-file-rewriter.f90
@@ -1,8 +1,8 @@
 ! RUN: rm -fr %t && mkdir %t && cd %t
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
 
 module m
   real :: x(10)
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -66,6 +66,7 @@
 ! HELP-FC1-NEXT: -fdebug-dump-symbolsDump symbols after the semantic analysis
 ! HELP-FC1-NEXT: -fdebug-measure-parse-tree
 ! HELP-FC1-NEXT: Measure the parse tree
+! HELP-FC1-NEXT: -fdebug-module-writer   Enable debug messages while writing module files
 ! HELP-FC1-NEXT: -fdebug-pre-fir-treeDump the pre-FIR tree
 ! HELP-FC1-NEXT: -fdebug-unparse-with-symbols
 ! HELP-FC1-NEXT:Unparse and stop.
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -126,7 +126,8 @@
   // Prepare semantics
   setSemantics(std::make_unique(
   ci.invocation().semanticsContext(), parseTree,
-  ci.parsing().cooked().AsCharBlock()));
+  ci.parsing().cooked().AsCharBlock(),
+  ci.invocation().debugModuleDir()));
   auto  = this->semantics();
 
   // Run semantic checks
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -291,9 +291,10 @@
 
 /// Parses all semantic related arguments and populates the variables
 /// options accordingly.
-static void parseSemaArgs(std::string , llvm::opt::ArgList ,
+static void parseSemaArgs(CompilerInvocation , llvm::opt::ArgList ,
 clang::DiagnosticsEngine ) {
 
+  // -J/module-dir option
   auto moduleDirList =
   args.getAllArgValues(clang::driver::options::OPT_module_dir);
   // User can only specify -J/-module-dir once
@@ -305,7 +306,12 @@
 diags.Report(diagID);
   }
   if (moduleDirList.size() == 1)
-moduleDir = moduleDirList[0];
+res.SetModuleDir(moduleDirList[0]);
+
+  // -fdebug-module-writer option
+  if (args.hasArg(clang::driver::options::OPT_fdebug_module_writer)) {
+res.SetDebugModuleDir(true);
+  }
 }
 
 /// Parses all Dialect related arguments and populates the variables
@@ -380,7 +386,7 @@
   // Parse the preprocessor args
   parsePreprocessorArgs(res.preprocessorOpts(), args);
   // Parse semantic args
-  parseSemaArgs(res.moduleDir(), args, diags);
+  parseSemaArgs(res, args, diags);
   // Parse dialect arguments
   parseDialectArgs(res, args, diags);
 
@@ -493,7 +499,6 @@
   semanticsContext_ = std::make_unique(
   defaultKinds(), fortranOptions.features, allCookedSources);
 
-  auto  = moduleDir();
-  semanticsContext_->set_moduleDirectory(moduleDirJ)
+  semanticsContext_->set_moduleDirectory(moduleDir())
   .set_searchDirectories(fortranOptions.searchDirectories);
 }
Index: flang/include/flang/Frontend/CompilerInvocation.h
===
--- flang/include/flang/Frontend/CompilerInvocation.h
+++ flang/include/flang/Frontend/CompilerInvocation.h
@@ -69,6 +69,8 @@
   // of options.
   std::string moduleDir_ = ".";
 
+  bool debugModuleDir_ = false;
+
   // Fortran Dialect options
  

[PATCH] D98191: [flang][driver] Add support for `-fdebug-dump-symbols-sources`

2021-03-08 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98191/new/

https://reviews.llvm.org/D98191

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96875: [flang][driver] Add -fdebug-module-writer option

2021-03-05 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added a comment.

OK, I will merge it on Monday unless @tskeith has any other comments.




Comment at: clang/include/clang/Driver/Options.td:4232-4233
   HelpText<"Use INTEGER(KIND=8) for the result type in size-related 
intrinsics.">;
+def fdebug_module_writer : Flag<["-"],"fdebug-module-writer">, Group, 
+  HelpText<"Enables showing debug messages while writing module files.">;
 }

arnamoy10 wrote:
> awarzynski wrote:
> > IMO this should be a frontend-only option. Compiler end-users are unlikely 
> > to need this in their regular workflows, right?  I recommend moving it [[ 
> > https://github.com/llvm/llvm-project/blob/adfd3c7083f9808d145239153c10f72eece485d8/clang/include/clang/Driver/Options.td#L4262-L4272
> >  | here ]].
> Yes, it makes sense to keep it as frontend-only option, let me submit an 
> updated patch.
> IMO this should be a frontend-only option. Compiler end-users are unlikely to 
> need this in their regular workflows, right?  I recommend moving it [[ 
> https://github.com/llvm/llvm-project/blob/adfd3c7083f9808d145239153c10f72eece485d8/clang/include/clang/Driver/Options.td#L4262-L4272
>  | here ]].




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96875/new/

https://reviews.llvm.org/D96875

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-03-03 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 327789.
arnamoy10 added a comment.
Herald added a subscriber: mgorny.

Fixing build failures, also moved the pipeline check to an existing file.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fdefault.f90
  flang/test/Flang-Driver/flarge_sizes.f90
  flang/test/Flang-Driver/frontend-forwarding.f90
  flang/unittests/Frontend/CMakeLists.txt

Index: flang/unittests/Frontend/CMakeLists.txt
===
--- flang/unittests/Frontend/CMakeLists.txt
+++ flang/unittests/Frontend/CMakeLists.txt
@@ -10,4 +10,5 @@
   flangFrontendTool
   FortranParser
   FortranSemantics
+  FortranCommon
 )
Index: flang/test/Flang-Driver/frontend-forwarding.f90
===
--- flang/test/Flang-Driver/frontend-forwarding.f90
+++ flang/test/Flang-Driver/frontend-forwarding.f90
@@ -5,6 +5,14 @@
 
 ! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
 ! RUN: -finput-charset=utf-8 \
+! RUN: -fdefault-double-8 \
+! RUN: -fdefault-integer-8 \
+! RUN: -fdefault-real-8 \
+! RUN: -flarge-sizes \
 ! RUN:   | FileCheck %s
 
 ! CHECK: "-finput-charset=utf-8"
+! CHECK: "-fdefault-double-8"
+! CHECK: "-fdefault-integer-8"
+! CHECK: "-fdefault-real-8"
+! CHECK: "-flarge-sizes"
Index: flang/test/Flang-Driver/flarge_sizes.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/flarge_sizes.f90
@@ -0,0 +1,36 @@
+! Ensure argument -flarge-sizes works as expected.
+! TODO: Add checks when actual codegen is possible.
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOLARGE
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOLARGE
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
+
+!-
+! EXPECTED OUTPUT WITHOUT -flarge-sizes
+!-
+! NOLARGE: real(4)::z(1_8:10_8)
+! NOLARGE-NEXT: integer(4),parameter::size_kind=4_4
+
+!-
+! EXPECTED OUTPUT FOR -flarge-sizes
+!-
+! LARGE: real(4)::z(1_8:10_8)
+! LARGE-NEXT: integer(4),parameter::size_kind=8_4
+
+module m
+  implicit none
+  real :: z(10)
+  integer, parameter :: size_kind = kind(ubound(z, 1)) !-flarge-sizes
+end
Index: flang/test/Flang-Driver/fdefault.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fdefault.f90
@@ -0,0 +1,61 @@
+! Ensure argument -fdefault* work as expected.
+! TODO: Add checks when actual codegen is possible for this family
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -fdefault-double-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=DOUBLE8
+! RUN: not %flang -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=ERROR
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s 

[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-03-02 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 327572.
arnamoy10 added a comment.

Rebased on main


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fdefault.f90
  flang/test/Flang-Driver/flarge_sizes.f90
  flang/test/Flang-Driver/pipeline.f90

Index: flang/test/Flang-Driver/pipeline.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/pipeline.f90
@@ -0,0 +1,17 @@
+! This file tests that flang-new forwards 
+! all Flang frontend options to flang-new -fc1
+! as expected.
+!
+! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fdefault-double-8 \
+! RUN: -fdefault-integer-8 \
+! RUN: -fdefault-real-8 \
+! RUN: -flarge-sizes \
+! RUN:   | FileCheck %s
+!
+!
+! CHECK: "-fdefault-double-8"
+! CHECK: "-fdefault-integer-8"
+! CHECK: "-fdefault-real-8"
+! CHECK: "-flarge-sizes"
+
Index: flang/test/Flang-Driver/flarge_sizes.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/flarge_sizes.f90
@@ -0,0 +1,36 @@
+! Ensure argument -flarge-sizes works as expected.
+! TODO: Add checks when actual codegen is possible.
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOLARGE
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOLARGE
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
+
+!-
+! EXPECTED OUTPUT WITHOUT -flarge-sizes
+!-
+! NOLARGE: real(4)::z(1_8:10_8)
+! NOLARGE-NEXT: integer(4),parameter::size_kind=4_4
+
+!-
+! EXPECTED OUTPUT FOR -flarge-sizes
+!-
+! LARGE: real(4)::z(1_8:10_8)
+! LARGE-NEXT: integer(4),parameter::size_kind=8_4
+
+module m
+  implicit none
+  real :: z(10)
+  integer, parameter :: size_kind = kind(ubound(z, 1)) !-flarge-sizes
+end
Index: flang/test/Flang-Driver/fdefault.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fdefault.f90
@@ -0,0 +1,61 @@
+! Ensure argument -fdefault* work as expected.
+! TODO: Add checks when actual codegen is possible for this family
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -fdefault-double-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=DOUBLE8
+! RUN: not %flang -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=ERROR
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -fdefault-real-8 -fdefault-double-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s 

[PATCH] D97457: [flang][driver] Add `-fdebug-dump-parsing-log`

2021-03-01 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97457/new/

https://reviews.llvm.org/D97457

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96875: [flang][driver] Add -fdebug-module-writer option

2021-03-01 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 327230.
arnamoy10 added a comment.

Minor changes as per comments, also updated commit message to include 
description of changes related to Setters.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96875/new/

https://reviews.llvm.org/D96875

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Semantics/mod-file-rewriter.f90

Index: flang/test/Semantics/mod-file-rewriter.f90
===
--- flang/test/Semantics/mod-file-rewriter.f90
+++ flang/test/Semantics/mod-file-rewriter.f90
@@ -1,8 +1,8 @@
 ! RUN: rm -fr %t && mkdir %t && cd %t
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
 
 module m
   real :: x(10)
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -59,6 +59,7 @@
 ! HELP-FC1-NEXT: -fdebug-dump-parse-tree Dump the parse tree
 ! HELP-FC1-NEXT: -fdebug-dump-provenance Dump provenance
 ! HELP-FC1-NEXT: -fdebug-dump-symbolsDump symbols after the semantic analysis
+! HELP-FC1-NEXT: -fdebug-module-writer   Enables showing debug messages while writing module files.
 ! HELP-FC1-NEXT: -fdebug-unparse-with-symbols
 ! HELP-FC1-NEXT:Unparse and stop.
 ! HELP-FC1-NEXT: -fdebug-unparseUnparse and stop.
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -116,7 +116,7 @@
   // Prepare semantics
   setSemantics(std::make_unique(
   ci.invocation().semanticsContext(), parseTree,
-  ci.parsing().cooked().AsCharBlock()));
+  ci.parsing().cooked().AsCharBlock(), ci.invocation().debugModuleDir()));
   auto  = this->semantics();
 
   // Run semantic checks
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -292,9 +292,10 @@
 
 /// Parses all semantic related arguments and populates the variables
 /// options accordingly.
-static void parseSemaArgs(std::string , llvm::opt::ArgList ,
+static void parseSemaArgs(CompilerInvocation , llvm::opt::ArgList ,
 clang::DiagnosticsEngine ) {
 
+  // -J/module-dir option
   auto moduleDirList =
   args.getAllArgValues(clang::driver::options::OPT_module_dir);
   // User can only specify -J/-module-dir once
@@ -306,7 +307,12 @@
 diags.Report(diagID);
   }
   if (moduleDirList.size() == 1)
-moduleDir = moduleDirList[0];
+res.SetModuleDir(moduleDirList[0]);
+
+  // -fdebug-module-writer option
+  if (args.hasArg(clang::driver::options::OPT_fdebug_module_writer)) {
+res.SetDebugModuleDir(true);
+  }
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation ,
@@ -339,7 +345,7 @@
   // Parse the preprocessor args
   parsePreprocessorArgs(res.preprocessorOpts(), args);
   // Parse semantic args
-  parseSemaArgs(res.moduleDir(), args, diags);
+  parseSemaArgs(res, args, diags);
 
   return success;
 }
@@ -451,7 +457,6 @@
   *(new Fortran::common::IntrinsicTypeDefaultKinds()),
   fortranOptions.features, allCookedSources);
 
-  auto  = moduleDir();
-  semanticsContext_->set_moduleDirectory(moduleDirJ)
+  semanticsContext_->set_moduleDirectory(moduleDir())
   .set_searchDirectories(fortranOptions.searchDirectories);
 }
Index: flang/include/flang/Frontend/CompilerInvocation.h
===
--- flang/include/flang/Frontend/CompilerInvocation.h
+++ flang/include/flang/Frontend/CompilerInvocation.h
@@ -69,6 +69,8 @@
   // of options.
   std::string moduleDir_ = ".";
 
+  bool 

[PATCH] D97119: [flang][driver] Add options for -std=2018

2021-02-26 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 326760.
arnamoy10 added a comment.

1. Updated the test case to include a check when the option is not given and 
make sure works with f18 as well (with `Mstandard`)
2. Changed variable names as suggested.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/std2018.f90

Index: flang/test/Flang-Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/std2018.f90
@@ -0,0 +1,42 @@
+! Ensure argument -std=f2018 works as expected.
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang-new -fsyntax-only -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %f18 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %f18 -fsyntax-only -Mstandard %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: not %flang-new -fsyntax-only -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+!  RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+!  RUN: %flang-new -fc1 -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+!  RUN: not %flang-new -fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=2018 is allowed currently.
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -38,6 +38,7 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 
@@ -64,6 +65,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
 
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -38,6 +38,7 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -test-io  Run the InputOuputTest action. Use for development and testing only.
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -286,6 +286,21 @@
 res.frontendOpts().features_.Enable(
 Fortran::common::LanguageFeature::OpenMP);
   }
+
+  //-std=f2018
+  if (args.hasArg(clang::driver::options::OPT_std_EQ)) {
+auto standard = args.getLastArgValue(clang::driver::options::OPT_std_EQ);
+// We only allow 2018 as the given standard
+if (standard.equals("f2018")) {
+  res.set_EnableConformanceChecks();
+}
+else {
+  const unsigned diagID =
+  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only -std=f2018 is allowed currently.");
+  

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-02-24 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 326234.
arnamoy10 edited the summary of this revision.
arnamoy10 added a comment.

Addressing comments, by separating the search directories from 
`fintrinsic-modules-path` in a separate variables.  Also added dummy modules 
for the test case, as using `%llvmshlibdir` did not work out.

Also, not sure what to set as the default directory, as gfortran uses a 
specific installation location.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/ieee_arithmetic.mod
  flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/intrinsic_module_path.f90

Index: flang/test/Flang-Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/intrinsic_module_path.f90
@@ -0,0 +1,32 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang-new -fc1 %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT: 'ieee_arithmetic.mod' was not found
+! WITHOUT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN-NOT: 'ieee_arithmetic.mod' was not found
+! GIVEN-NOT: 'iso_fortran_env.mod' was not found
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -32,6 +32,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify where to find the compiled intrinsic modules.
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -fopenacc  Enable OpenACC
@@ -72,6 +74,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules.
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -32,6 +32,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify where to find the compiled intrinsic modules.
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null
+++ flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
@@ -0,0 +1,6 @@
+! DUMMY module
+module iso_fortran_env
+use 

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-02-20 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 325208.
arnamoy10 added a comment.

Updating the test case to include `-fc1` as well


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/ieee_arithmetic.mod
  flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/intrinsic_module_path.f90

Index: flang/test/Flang-Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/intrinsic_module_path.f90
@@ -0,0 +1,33 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang-new -fc1 -fsyntax-only %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT: 'ieee_arithmetic.mod' was not found
+! WITHOUT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN-NOT: 'ieee_arithmetic.mod' was not found
+! GIVEN-NOT: 'iso_fortran_env.mod' was not found
+
+
+program test_intrinsic_module_path
+   use,intrinsic :: ieee_arithmetic
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
+  
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -32,6 +32,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify the location of pre-compiled intrinsic modules.
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -fopenacc  Enable OpenACC
@@ -71,6 +73,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify the location of pre-compiled intrinsic modules.
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -32,6 +32,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify the location of pre-compiled intrinsic modules.
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
===
--- /dev/null
+++ flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
@@ -0,0 +1,87 @@
+!mod$ v1 sum:2bc045d927f2d22c
+module iso_fortran_env
+use __fortran_builtins,only:event_type=>__builtin_event_type
+use __fortran_builtins,only:lock_type=>__builtin_lock_type
+use __fortran_builtins,only:team_type=>__builtin_team_type
+integer(4),parameter::atomic_int_kind=8_4
+intrinsic::selected_int_kind
+integer(4),parameter::atomic_logical_kind=8_4

[PATCH] D97119: [flang][driver] Add options for -std=2018

2021-02-20 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 created this revision.
arnamoy10 added reviewers: awarzynski, sscalpone, clementval, tskeith.
Herald added subscribers: jansvoboda11, dang.
arnamoy10 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add support for the following Fortran dialect options:

-std=2018

It also adds one test cases.  Currently only `2018` is allowed as the standard.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/std2018.f90

Index: flang/test/Flang-Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/std2018.f90
@@ -0,0 +1,33 @@
+! Ensure argument -std=2018 works as expected.
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only -std=2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: not %flang-new -fsyntax-only -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+!  RUN: %flang-new -fc1 -fsyntax-only -std=2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+!  RUN: not %flang-new -fc1 -fsyntax-only -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=2018 is allowed currently.
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -38,6 +38,7 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 
@@ -64,6 +65,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
 
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -38,6 +38,7 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -test-io  Run the InputOuputTest action. Use for development and testing only.
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -286,6 +286,21 @@
 res.frontendOpts().features_.Enable(
 Fortran::common::LanguageFeature::OpenMP);
   }
+
+  //-std=2018
+  if (args.hasArg(clang::driver::options::OPT_std_EQ)) {
+auto standard = args.getLastArgValue(clang::driver::options::OPT_std_EQ);
+// We only allow 2018 as the given standard
+if (standard.equals("2018")) {
+  res.SetStandard();
+}
+else {
+  const unsigned diagID =
+  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only -std=2018 is allowed currently.");
+  diags.Report(diagID);
+}
+  }
   return;
 }
 
@@ -423,6 +438,11 @@
   // directories
   if (moduleDirJ.compare(".") != 0)
 fortranOptions.searchDirectories.emplace_back(moduleDirJ);
+
+  // Set the standard
+  if (standard_) {
+fortranOptions.features.WarnOnAllNonstandard();
+  }
 }
 
 void CompilerInvocation::setSemanticsOpts(
Index: 

[PATCH] D97080: [flang][driver] Add -fintrinsic-modules-path option

2021-02-19 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 created this revision.
arnamoy10 added reviewers: awarzynski, tskeith, sscalpone, clementval, 
AMDChirag, SouraVX.
Herald added subscribers: jansvoboda11, dang, jfb.
arnamoy10 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add support for the following f18 options:

-fdebug-module-writer

Also the following changes:

1. Capture the intrinsic directory supplied in the same variable that captures 
the directories from `-I` in `PreprocessorOptions.h`, thus renaming the variable
2. Create a new test case
3. Adding intrinsic module files in the test directory


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97080

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/ieee_arithmetic.mod
  flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/intrinsic_module_path.f90

Index: flang/test/Flang-Driver/intrinsic_module_path.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/intrinsic_module_path.f90
@@ -0,0 +1,33 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT: 'ieee_arithmetic.mod' was not found
+! WITHOUT: 'iso_fortran_env.mod' was not found
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN-NOT: 'ieee_arithmetic.mod' was not found
+! GIVEN-NOT: 'iso_fortran_env.mod' was not found
+
+
+program test_intrinsic_module_path
+   use,intrinsic :: ieee_arithmetic
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
+  
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -32,6 +32,8 @@
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path 
+! HELP-NEXT:Specify the location of pre-compiled intrinsic modules.
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -fopenacc  Enable OpenACC
@@ -71,6 +73,8 @@
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path 
+! HELP-FC1-NEXT:Specify the location of pre-compiled intrinsic modules.
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -32,6 +32,8 @@
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path 
+! CHECK-NEXT:Specify the location of pre-compiled intrinsic modules.
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
Index: flang/test/Flang-Driver/Inputs/iso_fortran_env.mod

[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-19 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/test/Flang-Driver/flarge_sizes.f90:1
+! Ensure argument -flarge-sizes works as expected.
+! TODO: Add checks when actual codegen is possible for this family

awarzynski wrote:
> Could you add a `NOOPTION` variant like you did in fdefault.f90?
Done!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-19 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 324997.
arnamoy10 added a comment.

Added a missing option test for `-flarge-sizes`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fdefault.f90
  flang/test/Flang-Driver/flarge_sizes.f90
  flang/test/Flang-Driver/pipeline.f90

Index: flang/test/Flang-Driver/pipeline.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/pipeline.f90
@@ -0,0 +1,17 @@
+! This file tests that flang-new forwards 
+! all Flang frontend options to flang-new -fc1
+! as expected.
+!
+! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fdefault-double-8 \
+! RUN: -fdefault-integer-8 \
+! RUN: -fdefault-real-8 \
+! RUN: -flarge-sizes \
+! RUN:   | FileCheck %s
+!
+!
+! CHECK: "-fdefault-double-8"
+! CHECK: "-fdefault-integer-8"
+! CHECK: "-fdefault-real-8"
+! CHECK: "-flarge-sizes"
+
Index: flang/test/Flang-Driver/flarge_sizes.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/flarge_sizes.f90
@@ -0,0 +1,37 @@
+! Ensure argument -flarge-sizes works as expected.
+! TODO: Add checks when actual codegen is possible.
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOLARGE
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOLARGE
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
+
+!-
+! EXPECTED OUTPUT WITHOUT -flarge-sizes
+!-
+! NOLARGE: real(4)::z(1_8:10_8)
+! NOLARGE-NEXT: integer(4),parameter::size_kind=4_4
+
+!-
+! EXPECTED OUTPUT FOR -flarge-sizes
+!-
+! LARGE: real(4)::z(1_8:10_8)
+! LARGE-NEXT: integer(4),parameter::size_kind=8_4
+
+module m
+  implicit none
+  real :: z(10)
+  integer, parameter :: size_kind = kind(ubound(z, 1)) !-flarge-sizes
+end
Index: flang/test/Flang-Driver/fdefault.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fdefault.f90
@@ -0,0 +1,62 @@
+! Ensure argument -fdefault* work as expected.
+! TODO: Add checks when actual codegen is possible for this family
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -fdefault-double-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=DOUBLE8
+! RUN: not %flang -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=ERROR
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -fdefault-real-8 

[PATCH] D96875: [flang][driver] Add -fdebug-module-writer option

2021-02-19 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 324949.
arnamoy10 added a comment.

Set the option as a frontend-only option, also modified the test case 
accordingly.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96875/new/

https://reviews.llvm.org/D96875

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Semantics/mod-file-rewriter.f90

Index: flang/test/Semantics/mod-file-rewriter.f90
===
--- flang/test/Semantics/mod-file-rewriter.f90
+++ flang/test/Semantics/mod-file-rewriter.f90
@@ -1,8 +1,8 @@
 ! RUN: rm -fr %t && mkdir %t && cd %t
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
-! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang_fc1 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
 
 module m
   real :: x(10)
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -59,6 +59,7 @@
 ! HELP-FC1-NEXT: -fdebug-dump-parse-tree Dump the parse tree
 ! HELP-FC1-NEXT: -fdebug-dump-provenance Dump provenance
 ! HELP-FC1-NEXT: -fdebug-dump-symbolsDump symbols after the semantic analysis
+! HELP-FC1-NEXT: -fdebug-module-writer   Enables showing debug messages while writing module files.
 ! HELP-FC1-NEXT: -fdebug-unparse-with-symbols
 ! HELP-FC1-NEXT:Unparse and stop.
 ! HELP-FC1-NEXT: -fdebug-unparseUnparse and stop.
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -116,7 +116,7 @@
   // Prepare semantics
   setSemantics(std::make_unique(
   ci.invocation().semanticsContext(), parseTree,
-  ci.parsing().cooked().AsCharBlock()));
+  ci.parsing().cooked().AsCharBlock(), ci.invocation().debugModuleDir()));
   auto  = this->semantics();
 
   // Run semantic checks
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -292,9 +292,10 @@
 
 /// Parses all semantic related arguments and populates the variables
 /// options accordingly.
-static void parseSemaArgs(std::string , llvm::opt::ArgList ,
+static void parseSemaArgs(CompilerInvocation , llvm::opt::ArgList ,
 clang::DiagnosticsEngine ) {
-
+  
+  // -J/module-dir option
   auto moduleDirList =
   args.getAllArgValues(clang::driver::options::OPT_module_dir);
   // User can only specify -J/-module-dir once
@@ -306,7 +307,12 @@
 diags.Report(diagID);
   }
   if (moduleDirList.size() == 1)
-moduleDir = moduleDirList[0];
+res.SetModuleDir(moduleDirList[0]);
+
+  // -fdebug-module-writer option
+  if (args.hasArg(clang::driver::options::OPT_fdebug_module_writer)) {
+res.SetDebugModuleDir(true);
+  }
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation ,
@@ -339,7 +345,7 @@
   // Parse the preprocessor args
   parsePreprocessorArgs(res.preprocessorOpts(), args);
   // Parse semantic args
-  parseSemaArgs(res.moduleDir(), args, diags);
+  parseSemaArgs(res, args, diags);
 
   return success;
 }
@@ -451,7 +457,6 @@
   *(new Fortran::common::IntrinsicTypeDefaultKinds()),
   fortranOptions.features, allCookedSources);
 
-  auto  = moduleDir();
-  semanticsContext_->set_moduleDirectory(moduleDirJ)
+  semanticsContext_->set_moduleDirectory(moduleDir())
   .set_searchDirectories(fortranOptions.searchDirectories);
 }
Index: flang/include/flang/Frontend/CompilerInvocation.h
===
--- flang/include/flang/Frontend/CompilerInvocation.h
+++ flang/include/flang/Frontend/CompilerInvocation.h
@@ -69,6 +69,9 @@
   // of options.
   std::string moduleDir_ = ".";
 
+  bool debugModuleDir_ = false;
+
+
 

[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-18 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 324785.
arnamoy10 marked an inline comment as not done.
arnamoy10 added a comment.

- Rewritten the test cases
- Moved `flarge-sizes` to a standalone test file




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fdefault.f90
  flang/test/Flang-Driver/flarge_sizes.f90
  flang/test/Flang-Driver/pipeline.f90

Index: flang/test/Flang-Driver/pipeline.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/pipeline.f90
@@ -0,0 +1,17 @@
+! This file tests that flang-new forwards 
+! all Flang frontend options to flang-new -fc1
+! as expected.
+!
+! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fdefault-double-8 \
+! RUN: -fdefault-integer-8 \
+! RUN: -fdefault-real-8 \
+! RUN: -flarge-sizes \
+! RUN:   | FileCheck %s
+!
+!
+! CHECK: "-fdefault-double-8"
+! CHECK: "-fdefault-integer-8"
+! CHECK: "-fdefault-real-8"
+! CHECK: "-flarge-sizes"
+
Index: flang/test/Flang-Driver/flarge_sizes.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/flarge_sizes.f90
@@ -0,0 +1,27 @@
+! Ensure argument -flarge-sizes works as expected.
+! TODO: Add checks when actual codegen is possible for this family
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
+
+!-
+! EXPECTED OUTPUT FOR -flarge-sizes
+!-
+! LARGE: real(4)::z(1_8:10_8)
+! LARGE-NEXT: integer(4),parameter::size_kind=8_4
+
+module m
+  implicit none
+  real :: z(10)
+  integer, parameter :: size_kind = kind(ubound(z, 1)) !-flarge-sizes
+end
Index: flang/test/Flang-Driver/fdefault.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fdefault.f90
@@ -0,0 +1,62 @@
+! Ensure argument -fdefault* work as expected.
+! TODO: Add checks when actual codegen is possible for this family
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -fdefault-double-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=DOUBLE8
+! RUN: not %flang -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=ERROR
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8
+! RUN: rm -rf %t/dir-flang-new  && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -fdefault-real-8 -fdefault-double-8 -module-dir %t/dir-flang-new %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=DOUBLE8
+! RUN: not %flang -fc1 -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=ERROR
+
+
+
+
+!-
+! EXPECTED OUTPUT FOR NO SPECIFICATION
+!-
+! NOOPTION: integer(4),parameter::real_kind=4_4
+! NOOPTION-NEXT: intrinsic::kind
+! NOOPTION-NEXT: integer(4),parameter::double_kind=8_4
+

[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-18 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 324673.
arnamoy10 added a comment.

Updated test case to check module content


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fdefault.f90
  flang/test/Flang-Driver/pipeline.f90

Index: flang/test/Flang-Driver/pipeline.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/pipeline.f90
@@ -0,0 +1,17 @@
+! This file tests that flang-new forwards 
+! all Flang frontend options to flang-new -fc1
+! as expected.
+!
+! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fdefault-double-8 \
+! RUN: -fdefault-integer-8 \
+! RUN: -fdefault-real-8 \
+! RUN: -flarge-sizes \
+! RUN:   | FileCheck %s
+!
+!
+! CHECK: "-fdefault-double-8"
+! CHECK: "-fdefault-integer-8"
+! CHECK: "-fdefault-real-8"
+! CHECK: "-flarge-sizes"
+
Index: flang/test/Flang-Driver/fdefault.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fdefault.f90
@@ -0,0 +1,35 @@
+! Ensure argument -fdefault* works as expected.
+! TODO: Add checks when actual codegen is possible for this family
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=DOUBLE
+! RUN: mkdir -p %t/dir-flang-new && %flang-new -fsyntax-only -module-dir %t/dir-flang-new -fdefault-real-8 %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | grep 'real_kind=8_4'
+! RUN: mkdir -p %t/dir-flang-new && %flang-new -fsyntax-only -module-dir %t/dir-flang-new -fdefault-real-8 -flarge-sizes %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | grep 'size_kind=8_4'
+! RUN: mkdir -p %t/dir-flang-new && %flang-new -fsyntax-only -module-dir %t/dir-flang-new -fdefault-double-8 -fdefault-real-8 -flarge-sizes %s  2>&1
+! RUN: cat %t/dir-flang-new/m.mod | grep 'double_kind=8_4'
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang-new -fc1 -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=DOUBLE
+
+!-
+! EXPECTED OUTPUT FOR PROVIDING ONLY -fdefault-double-8 
+!-
+! DOUBLE:error: Use of `-fdefault-double-8` requires `-fdefault-real-8`
+
+module m
+  implicit none
+  real :: x
+  double precision :: y
+  real :: z(10)
+  integer, parameter :: size_kind = kind(ubound(z, 1)) !-flarge-sizes
+  integer, parameter :: real_kind = kind(x)!-fdefault-real-8
+  integer, parameter :: double_kind = kind(y)  !-fdefault-double-8
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -23,10 +23,14 @@
 ! HELP-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-NEXT: -E Only run the preprocessor
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
+! HELP-NEXT: -fdefault-double-8 Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type.
+! HELP-NEXT: -fdefault-integer-8Set the default integer and logical types to an 8 byte wide type.
+! HELP-NEXT: -fdefault-real-8   Set the default real type to an 8 byte wide type.
 ! HELP-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-NEXT: -ffixed-line-length=
 ! HELP-NEXT: Use  as character line width in fixed mode
 ! HELP-NEXT: -ffree-formProcess source files in free form
+! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics.
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
@@ -46,10 +50,14 @@
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
 ! HELP-FC1-NEXT: -E Only run the preprocessor
+! HELP-FC1-NEXT: -fdefault-double-8  Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type.
+! HELP-FC1-NEXT: -fdefault-integer-8 Set the default integer and logical types to an 8 byte wide type.
+! HELP-FC1-NEXT: -fdefault-real-8Set the default real type to an 8 byte wide type.
 ! HELP-FC1-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-FC1-NEXT: -ffixed-line-length=
 ! 

[PATCH] D96875: [flang][driver] Add -fdebug-module-writer option

2021-02-18 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: clang/include/clang/Driver/Options.td:4232-4233
   HelpText<"Use INTEGER(KIND=8) for the result type in size-related 
intrinsics.">;
+def fdebug_module_writer : Flag<["-"],"fdebug-module-writer">, Group, 
+  HelpText<"Enables showing debug messages while writing module files.">;
 }

awarzynski wrote:
> IMO this should be a frontend-only option. Compiler end-users are unlikely to 
> need this in their regular workflows, right?  I recommend moving it [[ 
> https://github.com/llvm/llvm-project/blob/adfd3c7083f9808d145239153c10f72eece485d8/clang/include/clang/Driver/Options.td#L4262-L4272
>  | here ]].
Yes, it makes sense to keep it as frontend-only option, let me submit an 
updated patch.



Comment at: flang/test/Semantics/mod-file-rewriter.f90:9
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer 
%p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix 
CHECK_UNCHANGED
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer 
%p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
 

awarzynski wrote:
> arnamoy10 wrote:
> > tskeith wrote:
> > > Why do you need to duplicate these lines? Doesn't it work to use `%flang`?
> > `%flang` will unfortunately invoke `f18` currently.
> That depends on the value of `FLANG_BUILD_NEW_DRIVER`, which is translated 
> into `include_flang_new_driver_test` [[ 
> https://github.com/llvm/llvm-project/blob/adfd3c7083f9808d145239153c10f72eece485d8/flang/test/lit.cfg.py#L74-L85
>  | here ]]. I also think that this should work fine with `%flang`.
> 
> Also, I suggest that we only have tests with `flang_fc1` and keep this as a 
> frontend-only option.
Sounds good.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96875/new/

https://reviews.llvm.org/D96875

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96875: [flang][driver] Add -fdebug-module-writer option

2021-02-18 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/test/Semantics/mod-file-rewriter.f90:9
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer 
%p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix 
CHECK_UNCHANGED
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer 
%p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
 

tskeith wrote:
> Why do you need to duplicate these lines? Doesn't it work to use `%flang`?
`%flang` will unfortunately invoke `f18` currently.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96875/new/

https://reviews.llvm.org/D96875

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96875: [flang][driver] Add -fdebug-module-writer option

2021-02-18 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 324606.
arnamoy10 added a comment.

Added some setters to work with.

Modified the test case to include `flang-new -fc1` as well.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96875/new/

https://reviews.llvm.org/D96875

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Semantics/mod-file-rewriter.f90

Index: flang/test/Semantics/mod-file-rewriter.f90
===
--- flang/test/Semantics/mod-file-rewriter.f90
+++ flang/test/Semantics/mod-file-rewriter.f90
@@ -3,6 +3,14 @@
 ! RUN: %f18 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
 ! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
 ! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang-new -fc1 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang-new -fc1 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang-new -fc1 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang-new -fc1 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
 
 module m
   real :: x(10)
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -134,7 +134,7 @@
 
   // Prepare semantics
   Fortran::semantics::Semantics semantics{ci.invocation().semanticsContext(),
-  parseTree, ci.parsing().cooked().AsCharBlock()};
+  parseTree, ci.parsing().cooked().AsCharBlock(),ci.invocation().debugModuleDir()};
 
   // Run semantic checks
   semantics.Perform();
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -227,9 +227,10 @@
 
 /// Parses all semantic related arguments and populates the variables
 /// options accordingly.
-static void parseSemaArgs(std::string , llvm::opt::ArgList ,
+static void parseSemaArgs(CompilerInvocation , llvm::opt::ArgList ,
 clang::DiagnosticsEngine ) {
 
+  // -J/module-dir option
   auto moduleDirList =
   args.getAllArgValues(clang::driver::options::OPT_module_dir);
   // User can only specify -J/-module-dir once
@@ -241,7 +242,12 @@
 diags.Report(diagID);
   }
   if (moduleDirList.size() == 1)
-moduleDir = moduleDirList[0];
+res.SetModuleDir(moduleDirList[0]);
+
+  // -fdebug-module-writer option
+  if (args.hasArg(clang::driver::options::OPT_fdebug_module_writer)) {
+res.SetDebugModuleDir(true);
+  }
 }
 
 /// Parses all Dialect related arguments and populates the variables
@@ -316,7 +322,7 @@
   // Parse the preprocessor args
   parsePreprocessorArgs(res.preprocessorOpts(), args);
   // Parse semantic args
-  parseSemaArgs(res.moduleDir(), args, diags);
+  parseSemaArgs(res, args, diags);
   // Parse dialect arguments
   parseDialectArgs(res, args, diags);
 
@@ -429,7 +435,6 @@
   semanticsContext_ = std::make_unique(
   defaultKinds(), fortranOptions.features, allCookedSources);
 
-  auto  = moduleDir();
-  semanticsContext_->set_moduleDirectory(moduleDirJ)
+  semanticsContext_->set_moduleDirectory(moduleDir())
   .set_searchDirectories(fortranOptions.searchDirectories);
 }
Index: flang/include/flang/Frontend/CompilerInvocation.h
===
--- flang/include/flang/Frontend/CompilerInvocation.h
+++ flang/include/flang/Frontend/CompilerInvocation.h
@@ -69,6 +69,8 @@
   // of options.
   std::string moduleDir_ = ".";
 
+  bool debugModuleDir_ = false;
+
   // Fortran Dialect options
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
 
@@ -91,6 +93,9 @@
   std::string () { return moduleDir_; }
   const std::string () const { return moduleDir_; }
 
+  bool () { return debugModuleDir_; }
+  const bool () const { return debugModuleDir_; }
+
   

[PATCH] D96875: [flang][driver] Add -fdebug-module-writer option

2021-02-17 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 created this revision.
arnamoy10 added reviewers: awarzynski, tskeith, sscalpone, clementval, 
AMDChirag, SouraVX.
Herald added subscribers: jansvoboda11, dang.
arnamoy10 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add support for the following f18 options:

- -fdebug-module-writer

Depends on: D96344 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96875

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Semantics/mod-file-rewriter.f90

Index: flang/test/Semantics/mod-file-rewriter.f90
===
--- flang/test/Semantics/mod-file-rewriter.f90
+++ flang/test/Semantics/mod-file-rewriter.f90
@@ -3,6 +3,10 @@
 ! RUN: %f18 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
 ! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
 ! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED
+! RUN: %flang-new -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED
 
 module m
   real :: x(10)
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -134,7 +134,7 @@
 
   // Prepare semantics
   Fortran::semantics::Semantics semantics{ci.invocation().semanticsContext(),
-  parseTree, ci.parsing().cooked().AsCharBlock()};
+  parseTree, ci.parsing().cooked().AsCharBlock(),ci.invocation().debugModuleDir()};
 
   // Run semantic checks
   semantics.Perform();
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -227,9 +227,11 @@
 
 /// Parses all semantic related arguments and populates the variables
 /// options accordingly.
-static void parseSemaArgs(std::string , llvm::opt::ArgList ,
+static void parseSemaArgs(CompilerInvocation , llvm::opt::ArgList ,
 clang::DiagnosticsEngine ) {
 
+  // -J/module-dir option
+  auto  = res.moduleDir();
   auto moduleDirList =
   args.getAllArgValues(clang::driver::options::OPT_module_dir);
   // User can only specify -J/-module-dir once
@@ -242,6 +244,12 @@
   }
   if (moduleDirList.size() == 1)
 moduleDir = moduleDirList[0];
+
+  // -fdebug-module-writer option
+  auto  = res.debugModuleDir();
+  if (args.hasArg(clang::driver::options::OPT_fdebug_module_writer)) {
+debugModuleDir = true;
+  }
 }
 
 /// Parses all Dialect related arguments and populates the variables
@@ -316,7 +324,7 @@
   // Parse the preprocessor args
   parsePreprocessorArgs(res.preprocessorOpts(), args);
   // Parse semantic args
-  parseSemaArgs(res.moduleDir(), args, diags);
+  parseSemaArgs(res, args, diags);
   // Parse dialect arguments
   parseDialectArgs(res, args, diags);
 
Index: flang/include/flang/Frontend/CompilerInvocation.h
===
--- flang/include/flang/Frontend/CompilerInvocation.h
+++ flang/include/flang/Frontend/CompilerInvocation.h
@@ -69,6 +69,8 @@
   // of options.
   std::string moduleDir_ = ".";
 
+  bool debugModuleDir_ = false;
+
   // Fortran Dialect options
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
 
@@ -91,6 +93,9 @@
   std::string () { return moduleDir_; }
   const std::string () const { return moduleDir_; }
 
+  bool () { return debugModuleDir_; }
+  const bool () const { return debugModuleDir_; }
+
   Fortran::common::IntrinsicTypeDefaultKinds () {
 return defaultKinds_;
   }
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -35,7 +35,7 @@
 }
 
 void Flang::AddOtherOptions(const ArgList , ArgStringList ) const {
-  Args.AddAllArgs(CmdArgs, options::OPT_module_dir);
+  Args.AddAllArgs(CmdArgs, {options::OPT_module_dir,options::OPT_fdebug_module_writer});
 }
 
 void Flang::ConstructJob(Compilation , const JobAction ,
Index: clang/include/clang/Driver/Options.td

[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-17 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 324334.
arnamoy10 added a comment.

- Added option for setting DOUBLE PRECISION when `fdefault-real-8` is given
- Also added link to relevant gfortran doc


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fdefault.f90
  flang/test/Flang-Driver/pipeline.f90

Index: flang/test/Flang-Driver/pipeline.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/pipeline.f90
@@ -0,0 +1,17 @@
+! This file tests that flang-new forwards 
+! all Flang frontend options to flang-new -fc1
+! as expected.
+!
+! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fdefault-double-8 \
+! RUN: -fdefault-integer-8 \
+! RUN: -fdefault-real-8 \
+! RUN: -flarge-sizes \
+! RUN:   | FileCheck %s
+!
+!
+! CHECK: "-fdefault-double-8"
+! CHECK: "-fdefault-integer-8"
+! CHECK: "-fdefault-real-8"
+! CHECK: "-flarge-sizes"
+
Index: flang/test/Flang-Driver/fdefault.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fdefault.f90
@@ -0,0 +1,26 @@
+! Ensure argument -fdefault* works as expected.
+! TODO: Add checks when actual codegen is possible for this family
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=DOUBLE
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang-new -fc1 -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=DOUBLE
+
+!-
+! EXPECTED OUTPUT FOR PROVIDING ONLY -fdefault-double-8 
+!-
+! DOUBLE:error: Use of `-fdefault-double-8` requires `-fdefault-real-8`
+
+PROGRAM test
+  implicit none
+  real :: x! note kind is not specified
+  x = 3.4
+  print *, "x = ", x
+END PROGRAM
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -23,10 +23,14 @@
 ! HELP-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-NEXT: -E Only run the preprocessor
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
+! HELP-NEXT: -fdefault-double-8 Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type.
+! HELP-NEXT: -fdefault-integer-8Set the default integer and logical types to an 8 byte wide type.
+! HELP-NEXT: -fdefault-real-8   Set the default real type to an 8 byte wide type.
 ! HELP-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-NEXT: -ffixed-line-length=
 ! HELP-NEXT: Use  as character line width in fixed mode
 ! HELP-NEXT: -ffree-formProcess source files in free form
+! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics.
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
@@ -46,10 +50,14 @@
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
 ! HELP-FC1-NEXT: -E Only run the preprocessor
+! HELP-FC1-NEXT: -fdefault-double-8  Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type.
+! HELP-FC1-NEXT: -fdefault-integer-8 Set the default integer and logical types to an 8 byte wide type.
+! HELP-FC1-NEXT: -fdefault-real-8Set the default real type to an 8 byte wide type.
 ! HELP-FC1-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-FC1-NEXT: -ffixed-line-length=
 ! HELP-FC1-NEXT: Use  as character line width in fixed mode
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
+! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics.
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-FC1-NEXT: -help  Display available options
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -23,10 +23,14 @@
 ! 

[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-17 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:254
+  if (args.hasArg(clang::driver::options::OPT_fdefault_real_8))
+res.defaultKinds().set_defaultRealKind(8);
+  if (args.hasArg(clang::driver::options::OPT_fdefault_integer_8)) {

awarzynski wrote:
> From `gfortran` [[ 
> https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html | 
> documentation ]]:
> 
> ```
> This option promotes the default width of DOUBLE PRECISION and double real 
> constants like 1.d0 to 16 bytes if possible.
> ```
> 
> So I believe that you are missing:
> ```
> res.defaultKinds().set_doublePrecisionKind(16);
> ```
I thought it is not necessary because `doublePrecisionKind` is automatically 
initialized to double the size of `defaultRealKind_` in [[ 
https://github.com/llvm/llvm-project/blob/adfd3c7083f9808d145239153c10f72eece485d8/flang/include/flang/Common/default-kinds.h#L51-L58
 | here ]]--> `int doublePrecisionKind_{2 * defaultRealKind_};`. 





Comment at: flang/lib/Frontend/CompilerInvocation.cpp:269-271
+// For -fdefault-double-8 + -fdefault-real-8, only the size of
+// DOUBLE PRECISION type changes, the size of default real type stays
+// the same

awarzynski wrote:
> I think that it's more like:
> ```
> // -fdefault-real-8 alone promotes the width for DOUBLE PRECISION to 16 
> bytes. -fdefault-double-8 overwrites that and sets the width back to 8 bytes.
> ```
> Since this patch adds `gfortran` style semantics, it would be worth adding a 
> link to the docs somewhere at the top.
Sure, will do!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-17 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 324296.
arnamoy10 added a comment.

Addresses proper handling of sizes


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fdefault.f90
  flang/test/Flang-Driver/pipeline.f90

Index: flang/test/Flang-Driver/pipeline.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/pipeline.f90
@@ -0,0 +1,17 @@
+! This file tests that flang-new forwards 
+! all Flang frontend options to flang-new -fc1
+! as expected.
+!
+! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fdefault-double-8 \
+! RUN: -fdefault-integer-8 \
+! RUN: -fdefault-real-8 \
+! RUN: -flarge-sizes \
+! RUN:   | FileCheck %s
+!
+!
+! CHECK: "-fdefault-double-8"
+! CHECK: "-fdefault-integer-8"
+! CHECK: "-fdefault-real-8"
+! CHECK: "-flarge-sizes"
+
Index: flang/test/Flang-Driver/fdefault.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fdefault.f90
@@ -0,0 +1,26 @@
+! Ensure argument -fdefault* works as expected.
+! TODO: Add checks when actual codegen is possible for this family
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=DOUBLE
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang-new -fc1 -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=DOUBLE
+
+!-
+! EXPECTED OUTPUT FOR PROVIDING ONLY -fdefault-double-8 
+!-
+! DOUBLE:error: Use of `-fdefault-double-8` requires `-fdefault-real-8`
+
+PROGRAM test
+  implicit none
+  real :: x! note kind is not specified
+  x = 3.4
+  print *, "x = ", x
+END PROGRAM
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -23,10 +23,14 @@
 ! HELP-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-NEXT: -E Only run the preprocessor
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
+! HELP-NEXT: -fdefault-double-8 Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type.
+! HELP-NEXT: -fdefault-integer-8Set the default integer and logical types to an 8 byte wide type.
+! HELP-NEXT: -fdefault-real-8   Set the default real type to an 8 byte wide type.
 ! HELP-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-NEXT: -ffixed-line-length=
 ! HELP-NEXT: Use  as character line width in fixed mode
 ! HELP-NEXT: -ffree-formProcess source files in free form
+! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics.
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
@@ -46,10 +50,14 @@
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
 ! HELP-FC1-NEXT: -E Only run the preprocessor
+! HELP-FC1-NEXT: -fdefault-double-8  Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type.
+! HELP-FC1-NEXT: -fdefault-integer-8 Set the default integer and logical types to an 8 byte wide type.
+! HELP-FC1-NEXT: -fdefault-real-8Set the default real type to an 8 byte wide type.
 ! HELP-FC1-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-FC1-NEXT: -ffixed-line-length=
 ! HELP-FC1-NEXT: Use  as character line width in fixed mode
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
+! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics.
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-FC1-NEXT: -help  Display available options
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -23,10 +23,14 @@
 ! CHECK-NEXT: -D = Define  to  (or 1 if  omitted)
 ! CHECK-NEXT: -EOnly run the 

[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-15 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 323746.
arnamoy10 added a comment.

Addressed latest reviewer's comments, no longer using a pointer for 
`defaultKinds`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fdefault.f90
  flang/test/Flang-Driver/pipeline.f90

Index: flang/test/Flang-Driver/pipeline.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/pipeline.f90
@@ -0,0 +1,17 @@
+! This file tests that flang-new forwards 
+! all Flang frontend options to flang-new -fc1
+! as expected.
+!
+! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fdefault-double-8 \
+! RUN: -fdefault-integer-8 \
+! RUN: -fdefault-real-8 \
+! RUN: -flarge-sizes \
+! RUN:   | FileCheck %s
+!
+!
+! CHECK: "-fdefault-double-8"
+! CHECK: "-fdefault-integer-8"
+! CHECK: "-fdefault-real-8"
+! CHECK: "-flarge-sizes"
+
Index: flang/test/Flang-Driver/fdefault.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fdefault.f90
@@ -0,0 +1,26 @@
+! Ensure argument -fdefault* works as expected.
+! TODO: Add checks when actual codegen is possible for this family
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=DOUBLE
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang-new -fc1 -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=DOUBLE
+
+!-
+! EXPECTED OUTPUT FOR PROVIDING ONLY -fdefault-double-8 
+!-
+! DOUBLE:error: Use of `-fdefault-double-8` requires `-fdefault-real-8`
+
+PROGRAM test
+  implicit none
+  real :: x! note kind is not specified
+  x = 3.4
+  print *, "x = ", x
+END PROGRAM
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -23,10 +23,14 @@
 ! HELP-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-NEXT: -E Only run the preprocessor
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
+! HELP-NEXT: -fdefault-double-8 Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type.
+! HELP-NEXT: -fdefault-integer-8Set the default integer and logical types to an 8 byte wide type.
+! HELP-NEXT: -fdefault-real-8   Set the default real type to an 8 byte wide type.
 ! HELP-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-NEXT: -ffixed-line-length=
 ! HELP-NEXT: Use  as character line width in fixed mode
 ! HELP-NEXT: -ffree-formProcess source files in free form
+! HELP-NEXT: -flarge-sizes  Set the default KIND for INTEGER to 8.
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
@@ -46,10 +50,14 @@
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
 ! HELP-FC1-NEXT: -E Only run the preprocessor
+! HELP-FC1-NEXT: -fdefault-double-8  Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type.
+! HELP-FC1-NEXT: -fdefault-integer-8 Set the default integer and logical types to an 8 byte wide type.
+! HELP-FC1-NEXT: -fdefault-real-8Set the default real type to an 8 byte wide type.
 ! HELP-FC1-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-FC1-NEXT: -ffixed-line-length=
 ! HELP-FC1-NEXT: Use  as character line width in fixed mode
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
+! HELP-FC1-NEXT: -flarge-sizes  Set the default KIND for INTEGER to 8.
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-FC1-NEXT: -help  Display available options
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -23,10 +23,14 @@
 ! CHECK-NEXT: -D = Define  to  (or 1 if  omitted)
 ! CHECK-NEXT: -EOnly run the preprocessor
 

[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-12 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 323480.
arnamoy10 edited the summary of this revision.
arnamoy10 added a comment.

Addressing reviewers' comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fdefault.f90
  flang/test/Flang-Driver/pipeline.f90

Index: flang/test/Flang-Driver/pipeline.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/pipeline.f90
@@ -0,0 +1,17 @@
+! This file tests that flang-new forwards 
+! all Flang frontend options to flang-new -fc1
+! as expected.
+!
+! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fdefault-double-8 \
+! RUN: -fdefault-integer-8 \
+! RUN: -fdefault-real-8 \
+! RUN: -flarge-sizes \
+! RUN:   | FileCheck %s
+!
+!
+! CHECK: "-fdefault-double-8"
+! CHECK: "-fdefault-integer-8"
+! CHECK: "-fdefault-real-8"
+! CHECK: "-flarge-sizes"
+
Index: flang/test/Flang-Driver/fdefault.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fdefault.f90
@@ -0,0 +1,26 @@
+! Ensure argument -fdefault* works as expected.
+! TODO: Add checks when actual codegen is possible for this family
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=DOUBLE
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang-new -fc1 -fsyntax-only -fdefault-double-8 %s  2>&1 | FileCheck %s --check-prefix=DOUBLE
+
+!-
+! EXPECTED OUTPUT FOR PROVIDING ONLY -fdefault-double-8 
+!-
+! DOUBLE:error: Use of `-fdefault-double-8` requires `-fdefault-real-8`
+
+PROGRAM test
+  implicit none
+  real :: x! note kind is not specified
+  x = 3.4
+  print *, "x = ", x
+END PROGRAM
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -23,10 +23,14 @@
 ! HELP-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-NEXT: -E Only run the preprocessor
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
+! HELP-NEXT: -fdefault-double-8 Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type.
+! HELP-NEXT: -fdefault-integer-8Set the default integer and logical types to an 8 byte wide type.
+! HELP-NEXT: -fdefault-real-8   Set the default real type to an 8 byte wide type.
 ! HELP-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-NEXT: -ffixed-line-length=
-! HELP-NEXT: Use  as character line width in fixed mode
+! HELP-NEXT:  Use  as character line width in fixed mode
 ! HELP-NEXT: -ffree-formProcess source files in free form
+! HELP-NEXT: -flarge-sizes  Set the default KIND for INTEGER to 8.
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
@@ -46,10 +50,14 @@
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
 ! HELP-FC1-NEXT: -E Only run the preprocessor
+! HELP-FC1-NEXT: -fdefault-double-8  Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type.
+! HELP-FC1-NEXT: -fdefault-integer-8 Set the default integer and logical types to an 8 byte wide type.
+! HELP-FC1-NEXT: -fdefault-real-8Set the default real type to an 8 byte wide type.
 ! HELP-FC1-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-FC1-NEXT: -ffixed-line-length=
 ! HELP-FC1-NEXT: Use  as character line width in fixed mode
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
+! HELP-FC1-NEXT: -flarge-sizes  Set the default KIND for INTEGER to 8.
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-FC1-NEXT: -help  Display available options
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -23,10 +23,14 @@
 ! CHECK-NEXT: -D = Define  to  (or 1 if  

[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-12 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: clang/include/clang/Driver/Options.td:4163
 defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, 
Group;
-defm default_double_8 : BooleanFFlag<"default-double-8">, 
Group;
-defm default_integer_8 : BooleanFFlag<"default-integer-8">, 
Group;
-defm default_real_8 : BooleanFFlag<"default-real-8">, Group;
+defm default_double_8 : BooleanFFlag<"default-double-8">, 
Group, Flags<[FlangOption,FC1Option]>;
+defm default_integer_8 : BooleanFFlag<"default-integer-8">, 
Group, Flags<[FlangOption,FC1Option]>;

awarzynski wrote:
> Could you add a help text? Note that once you add a help text, you will have 
> to add `FlangOnlyOption` flag to make sure this option doesn't show up in: 
> ```
> clang -help
> ```
> 
> Some for other options here. Also, at that point, I suggest moving these 
> options near other Flang options: 
> https://github.com/llvm/llvm-project/blob/ec4fb5bcd3b92867156a5bd75fa0be4c74084f3c/clang/include/clang/Driver/Options.td#L4224-L4238.
> 
> AFAIK, these options are no longer forwarded to `gfortran` anyway (since this 
> [[ 
> https://github.com/llvm/llvm-project/commit/6a75496836ea14bcfd2f4b59d35a1cad4ac58cee
>  | patch ]]).
What should be the help text for `-flarge-sizes`, given we cannot take 
reference from gfortran


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-11 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:261
+   diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+ "Use of `-fdefault-double-8` requires `-fdefault-real-8`");
+   diags.Report(diagID);

awarzynski wrote:
> Is this requirement document anywhere?
Just found out through running `gfortran`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96344/new/

https://reviews.llvm.org/D96344

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-09 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 created this revision.
arnamoy10 added reviewers: awarzynski, sscalpone, clementval, tskeith, 
AMDChirag, SouraVX.
Herald added a subscriber: dang.
Herald added a reviewer: jansvoboda11.
arnamoy10 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Add support for the following Fortran dialect options:

- -default*
- -flarge-sizes

It also adds a test case for checking whether `flang-new` is passing options 
correctly to `flang-new -fc1`.

Also moves the Dialect related option parsing to a dedicated function.

Depends on: D96032 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96344

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/pipeline.f90

Index: flang/test/Flang-Driver/pipeline.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/pipeline.f90
@@ -0,0 +1,14 @@
+! Test that flang can forward all of the flags which are documented as
+! being supported by gfortran to flang-new for a fortran input file.
+!
+! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fdefault-double-8 \
+! RUN: -fdefault-integer-8 \
+! RUN: -fdefault-real-8 \
+! RUN:   | FileCheck %s
+!
+!
+! CHECK: "-fdefault-double-8"
+! CHECK: "-fdefault-integer-8"
+! CHECK: "-fdefault-real-8"
+
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -200,13 +200,6 @@
 }
   }
 
-  // Extensions
-  if (args.hasArg(clang::driver::options::OPT_fopenacc)) {
-opts.features_.Enable(Fortran::common::LanguageFeature::OpenACC);
-  }
-  if (args.hasArg(clang::driver::options::OPT_fopenmp)) {
-opts.features_.Enable(Fortran::common::LanguageFeature::OpenMP);
-  }
   return dashX;
 }
 
@@ -251,6 +244,38 @@
 moduleDir = moduleDirList[0];
 }
 
+/// Parses all Dialect related arguments and populates the variables
+/// options accordingly.
+static void parseDialectArgs(CompilerInvocation , llvm::opt::ArgList ,
+clang::DiagnosticsEngine ) {
+
+ // -fedefault* family
+ if (args.hasArg(clang::driver::options::OPT_fdefault_real_8))
+ res.dialectOpts().dfltReal = true;
+ if (args.hasArg(clang::driver::options::OPT_fdefault_integer_8))
+ res.dialectOpts().dfltInt = true;
+ if (args.hasArg(clang::driver::options::OPT_fdefault_double_8)) {
+ if (!res.dialectOpts().dfltReal) {
+   const unsigned diagID =
+   diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+ "Use of `-fdefault-double-8` requires `-fdefault-real-8`");
+   diags.Report(diagID);
+ }
+ res.dialectOpts().dfltDouble = true;
+ }
+ if (args.hasArg(clang::driver::options::OPT_flarge_sizes)) 
+ res.dialectOpts().largeSizes = true;
+
+ // -fopenmp and -fopenacc 
+ if (args.hasArg(clang::driver::options::OPT_fopenacc)) {
+   res.frontendOpts().features_.Enable(Fortran::common::LanguageFeature::OpenACC);
+ }
+ if (args.hasArg(clang::driver::options::OPT_fopenmp)) {
+   res.frontendOpts().features_.Enable(Fortran::common::LanguageFeature::OpenMP);
+ }
+ return; 
+}
+
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation ,
 llvm::ArrayRef commandLineArgs,
 clang::DiagnosticsEngine ) {
@@ -282,6 +307,8 @@
   parsePreprocessorArgs(res.preprocessorOpts(), args);
   // Parse semantic args
   parseSemaArgs(res.moduleDir(), args, diags);
+  // Parse dialect arguments
+  parseDialectArgs(res, args, diags);
 
   return success;
 }
@@ -389,8 +416,19 @@
 Fortran::parser::AllCookedSources ) {
   const auto  = fortranOpts();
 
+  defaultKinds_ = std::make_unique();
+  if (this->dialectOpts_.dfltDouble) defaultKinds().set_defaultRealKind(4);
+  if (this->dialectOpts_.dfltReal) defaultKinds().set_defaultRealKind(8); 
+  if (this->dialectOpts_.dfltInt) {
+defaultKinds().set_defaultIntegerKind(8);
+defaultKinds().set_subscriptIntegerKind(8);
+defaultKinds().set_sizeIntegerKind(8);
+// TODO: Set more options based on PGF90
+  }
+  if (this->dialectOpts_.largeSizes) defaultKinds().set_sizeIntegerKind(8); 
+
   semanticsContext_ = std::make_unique(
-  *(new Fortran::common::IntrinsicTypeDefaultKinds()),
+  defaultKinds(),
   fortranOptions.features, allCookedSources);
 
   auto  = moduleDir();
Index: flang/include/flang/Frontend/CompilerInvocation.h
===
--- flang/include/flang/Frontend/CompilerInvocation.h
+++ flang/include/flang/Frontend/CompilerInvocation.h
@@ -19,6 +19,13 @@
 
 namespace Fortran::frontend {
 
+struct DialectOptions {
+DialectOptions() {}
+

[PATCH] D95448: [flang][driver] Add support for `-J/-module-dir`

2021-02-02 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added a comment.

Sounds good to me, thanks for the help.  In the meantime I will work on the 
`fdefault-*` family of flags, which will be dependent on this patch I think.




Comment at: clang/include/clang/Driver/Options.td:4124
 def A_DASH : Joined<["-"], "A-">, Group;
-def J : JoinedOrSeparate<["-"], "J">, Flags<[RenderJoined]>, 
Group;
 def cpp : Flag<["-"], "cpp">, Group;

awarzynski wrote:
> There's no need to move this, is there? I feel that it's better to keep all 
> `gfortran` options together.
This needs to be moved, as we are using Aliases.  The way Aliases work is (in 
this order) (1) you create the base option (that 



Comment at: clang/include/clang/Driver/Options.td:1018
+  an USE statement.  The default is the current 
directory.}]>,Group;
+def module_dir : Separate<["-"], "module-dir">, 
Flags<[FlangOption,FC1Option]>, MetaVarName<"">, Alias;
 def dsym_dir : JoinedOrSeparate<["-"], "dsym-dir">,

tskeith wrote:
> It would be better to make `-module-dir` the main option and `-J` the alias. 
> `-J` is only there for gfortran compatibility, not because it is a good name 
> for the option.
Sure, we can do that.  I just chose -J to be default as it is easier to type 
for the user :)



Comment at: flang/lib/Frontend/CompilerInstance.cpp:29
+  semantics_(new Fortran::semantics::SemanticsContext(*(new  
Fortran::common::IntrinsicTypeDefaultKinds()),*(new 
common::LanguageFeatureControl()),
+ *allCookedSources_)) {
 

tskeith wrote:
> Why is `semantics_` a `shared_ptr` rather than a simple data member of  type 
> `SemanticsContext`? It's owned by only `CompilerInstance`, not shared.
> The same question probably applies to the other fields too.
No idea about this design decision.  I have not found any other DS that is 
"sharing" these pointers.  I can take them out.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:302
+
+void CompilerInvocation::setSemanticsOpts(Fortran::semantics::SemanticsContext 
) {
+  auto  = fortranOpts();

awarzynski wrote:
> The argument is not needed here, is it? You could just write:
> ```
> auto  = semanticsContext()
> ```
> Or am I missing something?
`semanticsContext_` belongs to `CompilerInstance`, not `CompilerInvocation`, so 
unfortunately that is not possible.



Comment at: flang/test/Flang-Driver/include-module.f90:11
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s 
--check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs -I %S/Inputs/module-dir %s  
2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s 
--check-prefix=SINGLEINCLUDE

awarzynski wrote:
> What about:
> *  `-J %S/Inputs -J %S/Inputs/module-dir` (i.e. `-J` + `-J`)
> * `-J %S/Inputs -module-dir %S/Inputs/module-dir` (i.e. `-J` + `-module-dir`)
> * `-module-dir %S/Inputs -J%S/Inputs/module-dir` (i.e. `-module-dir` + `-J`)
> * `-module-dir %S/Inputs -I%S/Inputs/module-dir` (.e. `-module-dir` + `-I`)
> 
> I appreciate that this is a bit tedious, but IMO it is worthwhile to add a 
> few more cases here to avoid any unpleasant breakage in the future. Also - 
> what should the relation between `-I` and `-J` be here? As in, which ought to 
> have higher priority? 
Done


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95448/new/

https://reviews.llvm.org/D95448

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95448: [flang][driver] Add support for `-J/-module-dir`

2021-02-01 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 320617.
arnamoy10 added a comment.

A few more comments addressed and a new test case added for write-module check.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95448/new/

https://reviews.llvm.org/D95448

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/include-module.f90
  flang/test/Flang-Driver/write-module.f90

Index: flang/test/Flang-Driver/write-module.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/write-module.f90
@@ -0,0 +1,10 @@
+! RUN: mkdir -p %t/dir-f18 && %f18 -fparse-only -I tools/flang/include/flang -module %t/dir-f18 %s  2>&1
+! RUN: ls %t/dir-f18/testmodule.mod && not ls %t/testmodule.mod
+
+! RUN: mkdir -p %t/dir-flang-new && %flang-new -fsyntax-only -module-dir %t/dir-flang-new %s  2>&1
+! RUN: ls %t/dir-flang-new/testmodule.mod && not ls %t/testmodule.mod
+
+module testmodule
+  type::t2
+  end type
+end
Index: flang/test/Flang-Driver/include-module.f90
===
--- flang/test/Flang-Driver/include-module.f90
+++ flang/test/Flang-Driver/include-module.f90
@@ -7,12 +7,26 @@
 !--
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -I %S/Inputs -J %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -I %S/Inputs -module-dir %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
 
 !-
 ! FRONTEND FLANG DRIVER (flang-new -fc1)
 !-
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -J %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -module-dir %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
 
 !-
 ! EXPECTED OUTPUT FOR MISSING MODULE FILE
@@ -22,6 +36,11 @@
 ! SINGLEINCLUDE-NOT:error: Derived type 't1' not found
 ! SINGLEINCLUDE:error: Derived type 't2' not found
 
+!-
+! EXPECTED OUTPUT FOR MISSING MODULE FILE
+!-
+! DOUBLEINCLUDE:error: Only one '-module-dir/-J' option allowed
+
 !---
 ! EXPECTED OUTPUT FOR ALL MODULES FOUND
 !---
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -26,6 +26,7 @@
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
+! HELP-NEXT: 

[PATCH] D95448: [flang][driver] Add support for `-J/-module-dir`

2021-01-30 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 320306.
arnamoy10 added a comment.

Addressing reviewers' comments, adding `-module-dir` as the default option 
instead of `-J`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95448/new/

https://reviews.llvm.org/D95448

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/include-module.f90

Index: flang/test/Flang-Driver/include-module.f90
===
--- flang/test/Flang-Driver/include-module.f90
+++ flang/test/Flang-Driver/include-module.f90
@@ -8,12 +8,28 @@
 !--
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
 
 !-
 ! FRONTEND FLANG DRIVER (flang-new -fc1)
 !-
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
 
 !-
 ! EXPECTED OUTPUT FOR MISSING MODULE FILE
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -26,6 +26,7 @@
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
+! HELP-NEXT: -module-dirPut MODULE files in 'directory'
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
@@ -41,6 +42,7 @@
 ! HELP-FC1-NEXT: -E Only run the preprocessor
 ! HELP-FC1-NEXT: -help  Display available options
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
+! HELP-FC1-NEXT: -module-dirPut MODULE files in 'directory'
 ! HELP-FC1-NEXT: -o   Write output to 
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Flang-Driver/driver-help-hidden.f90

[PATCH] D95448: [flang][driver] Add support for `-J/-module-dir`

2021-01-29 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 320188.
arnamoy10 added a comment.

Added test for the driver-help, also contains all the changes that was done in 
the previous diff (Aliasing `-J` and `-module-dir`, changing data structures 
etc).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95448/new/

https://reviews.llvm.org/D95448

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/include-module.f90

Index: flang/test/Flang-Driver/include-module.f90
===
--- flang/test/Flang-Driver/include-module.f90
+++ flang/test/Flang-Driver/include-module.f90
@@ -8,12 +8,28 @@
 !--
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
 
 !-
 ! FRONTEND FLANG DRIVER (flang-new -fc1)
 !-
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
 
 !-
 ! EXPECTED OUTPUT FOR MISSING MODULE FILE
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -26,6 +26,7 @@
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
+! HELP-NEXT: -JPut MODULE files in 'directory'
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
@@ -41,6 +42,7 @@
 ! HELP-FC1-NEXT: -E Only run the preprocessor
 ! HELP-FC1-NEXT: -help  Display available options
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
+! HELP-FC1-NEXT: -JPut MODULE files in 'directory'
 ! HELP-FC1-NEXT: -o   Write output to 
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: 

[PATCH] D95448: [flang][driver] Add support for `-J/-module-dir`

2021-01-29 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 320184.
arnamoy10 added a comment.

Addressing reviewers' comments with the following changes:

1. Aliasing of -module-dir and -J to avoid code duplication
2. Moving the code to set the module and search directories from 
`FrontendActions.cpp` to `CompilerInvocation.cpp`
3. Data structures updated/ variables added to separate Preprocessor options 
from Compiler Options
4. Added more test cases.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95448/new/

https://reviews.llvm.org/D95448

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Flang-Driver/include-module.f90

Index: flang/test/Flang-Driver/include-module.f90
===
--- flang/test/Flang-Driver/include-module.f90
+++ flang/test/Flang-Driver/include-module.f90
@@ -8,12 +8,28 @@
 !--
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
 
 !-
 ! FRONTEND FLANG DRIVER (flang-new -fc1)
 !-
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
 
 !-
 ! EXPECTED OUTPUT FOR MISSING MODULE FILE
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -96,11 +96,9 @@
 
   auto {*ci.parsing().parseTree()};
 
-  // Prepare semantics
-  Fortran::semantics::SemanticsContext semanticsContext{
-  defaultKinds, features, ci.allCookedSources()};
+  // Prepare semantics 
   Fortran::semantics::Semantics semantics{
-  semanticsContext, parseTree, ci.parsing().cooked().AsCharBlock()};
+  ci.semaChecking(), parseTree, ci.parsing().cooked().AsCharBlock()};
 
   // Run semantic checks
   semantics.Perform();
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -183,6 +183,14 @@
 opts.searchDirectoriesFromDashI.emplace_back(currentArg->getValue());
 }
 
+/// Parses all semantic related arguments and populates the variables
+/// options accordingly.
+static void 

[PATCH] D95448: [flang][driver] Add support for `-J/-module-dir`

2021-01-26 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 created this revision.
arnamoy10 added reviewers: awarzynski, sscalpone, sameeranjoshi, SouraVX, 
tskeith, kiranktp, AMDChirag.
Herald added a subscriber: dang.
Herald added a reviewer: jansvoboda11.
arnamoy10 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add support for option -J/-module-dir in the new Flang driver.
This will allow for including module files in other directories, as the default 
search path is currently the working folder.  This also provides an option of 
storing the output module in the specified folder.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95448

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/include/flang/Parser/parsing.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/include-module.f90

Index: flang/test/Flang-Driver/include-module.f90
===
--- flang/test/Flang-Driver/include-module.f90
+++ flang/test/Flang-Driver/include-module.f90
@@ -1,4 +1,4 @@
-! Ensure argument -I works as expected with module files.
+! Ensure argument -I, -J and -module-dir works as expected with module files.
 ! The module files for this test are not real module files.
 
 ! REQUIRES: new-flang-driver
@@ -8,12 +8,20 @@
 !--
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
 
 !-
 ! FRONTEND FLANG DRIVER (flang-new -fc1)
 !-
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
 ! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
 
 !-
 ! EXPECTED OUTPUT FOR MISSING MODULE FILE
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -26,6 +26,7 @@
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
+! HELP-NEXT: -module-dir  Add to the list of directories to be searched by an USE statement
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
@@ -41,6 +42,7 @@
 ! HELP-FC1-NEXT: -E Only run the preprocessor
 ! HELP-FC1-NEXT: -help  Display available options
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
+! HELP-FC1-NEXT: -module-dir  Add to the list of directories to be searched by an USE statement
 ! HELP-FC1-NEXT: -o   Write output to 
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -26,6 +26,7 @@
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! CHECK-NEXT: -help Display available options
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
+! CHECK-NEXT: -module-dir  Add to the list of directories to be