[PATCH] D47273: [bash-completion] Fix tab separation on macOS

2018-05-23 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi accepted this revision.
yamaguchi added a comment.

LGTM


https://reviews.llvm.org/D47273



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


[PATCH] D49852: [Modules] Do not emit relocation error when -fno-validate-pch is set

2018-07-26 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added reviewers: rsmith, dblaikie, v.g.vassilev.

Clang emits error when implicit modules was relocated from the
first build directory. However this was biting our usecase where we copy
the contents of build directory to another directory in order to
distribute.


https://reviews.llvm.org/D49852

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Modules/resolution-change.m


Index: clang/test/Modules/resolution-change.m
===
--- clang/test/Modules/resolution-change.m
+++ clang/test/Modules/resolution-change.m
@@ -21,6 +21,8 @@
 // RUN: not %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I 
%S/Inputs/modules-with-same-name/path2/A -include-pch %t-A.pch %s -fsyntax-only 
2>&1 | FileCheck -check-prefix=CHECK-WRONGA %s
 // CHECK-WRONGA: module 'A' was built in directory 
'{{.*Inputs.modules-with-same-name.path1.A}}' but now resides in directory 
'{{.*Inputs.modules-with-same-name.path2.A}}'
 
+// RUN: %clang_cc1 -fno-validate-pch -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I 
%S/Inputs/modules-with-same-name/path2/A -include-pch %t-A.pch %s -fsyntax-only
+
 #ifndef HEADER
 #define HEADER
 @import DependsOnA;
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2632,7 +2632,9 @@
   if (M && M->Directory) {
 // If we're implicitly loading a module, the base directory can't
 // change between the build and use.
-if (F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
+// Don't emit module relocation error if we have -fno-validate-pch
+if (!PP.getPreprocessorOpts().DisablePCHValidation &&
+F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
   const DirectoryEntry *BuildDir =
   PP.getFileManager().getDirectory(Blob);
   if (!BuildDir || BuildDir != M->Directory) {
@@ -3602,7 +3604,8 @@
 Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName);
 auto &Map = PP.getHeaderSearchInfo().getModuleMap();
 const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr;
-if (!ModMap) {
+// Don't emit module relocation error if we have -fno-validate-pch
+if (!PP.getPreprocessorOpts().DisablePCHValidation && !ModMap) {
   assert(ImportedBy && "top-level import should be verified");
   if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) {
 if (auto *ASTFE = M ? M->getASTFile() : nullptr) {
@@ -5039,7 +5042,9 @@
 
   if (!ParentModule) {
 if (const FileEntry *CurFile = CurrentModule->getASTFile()) {
-  if (CurFile != F.File) {
+  // Don't emit module relocation error if we have -fno-validate-pch
+  if (!PP.getPreprocessorOpts().DisablePCHValidation &&
+  CurFile != F.File) {
 if (!Diags.isDiagnosticInFlight()) {
   Diag(diag::err_module_file_conflict)
 << CurrentModule->getTopLevelModuleName()


Index: clang/test/Modules/resolution-change.m
===
--- clang/test/Modules/resolution-change.m
+++ clang/test/Modules/resolution-change.m
@@ -21,6 +21,8 @@
 // RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I %S/Inputs/modules-with-same-name/path2/A -include-pch %t-A.pch %s -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-WRONGA %s
 // CHECK-WRONGA: module 'A' was built in directory '{{.*Inputs.modules-with-same-name.path1.A}}' but now resides in directory '{{.*Inputs.modules-with-same-name.path2.A}}'
 
+// RUN: %clang_cc1 -fno-validate-pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I %S/Inputs/modules-with-same-name/path2/A -include-pch %t-A.pch %s -fsyntax-only
+
 #ifndef HEADER
 #define HEADER
 @import DependsOnA;
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2632,7 +2632,9 @@
   if (M && M->Directory) {
 // If we're implicitly loading a module, the base directory can't
 // change between the build and use.
-if (F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
+// Don't emit module relocation error if we have -fno-validate-pch
+if (!PP.getPreprocessorOpts().DisablePCHValidation &&
+F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
   const DirectoryEntry *BuildDir =
   PP.getFileManager().getDirectory(Blob);
   if (!BuildDir || BuildDir != M

[PATCH] D49852: [Modules] Do not emit relocation error when -fno-validate-pch is set

2018-08-01 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338503: [Modules] Do not emit relocation error when 
-fno-validate-pch is set (authored by yamaguchi, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D49852?vs=157479&id=158484#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49852

Files:
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/test/Modules/resolution-change.m


Index: cfe/trunk/test/Modules/resolution-change.m
===
--- cfe/trunk/test/Modules/resolution-change.m
+++ cfe/trunk/test/Modules/resolution-change.m
@@ -21,6 +21,8 @@
 // RUN: not %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I 
%S/Inputs/modules-with-same-name/path2/A -include-pch %t-A.pch %s -fsyntax-only 
2>&1 | FileCheck -check-prefix=CHECK-WRONGA %s
 // CHECK-WRONGA: module 'A' was built in directory 
'{{.*Inputs.modules-with-same-name.path1.A}}' but now resides in directory 
'{{.*Inputs.modules-with-same-name.path2.A}}'
 
+// RUN: %clang_cc1 -fno-validate-pch -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I 
%S/Inputs/modules-with-same-name/path2/A -include-pch %t-A.pch %s -fsyntax-only
+
 #ifndef HEADER
 #define HEADER
 @import DependsOnA;
Index: cfe/trunk/lib/Serialization/ASTReader.cpp
===
--- cfe/trunk/lib/Serialization/ASTReader.cpp
+++ cfe/trunk/lib/Serialization/ASTReader.cpp
@@ -2632,7 +2632,9 @@
   if (M && M->Directory) {
 // If we're implicitly loading a module, the base directory can't
 // change between the build and use.
-if (F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
+// Don't emit module relocation error if we have -fno-validate-pch
+if (!PP.getPreprocessorOpts().DisablePCHValidation &&
+F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
   const DirectoryEntry *BuildDir =
   PP.getFileManager().getDirectory(Blob);
   if (!BuildDir || BuildDir != M->Directory) {
@@ -3602,7 +3604,8 @@
 Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName);
 auto &Map = PP.getHeaderSearchInfo().getModuleMap();
 const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr;
-if (!ModMap) {
+// Don't emit module relocation error if we have -fno-validate-pch
+if (!PP.getPreprocessorOpts().DisablePCHValidation && !ModMap) {
   assert(ImportedBy && "top-level import should be verified");
   if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) {
 if (auto *ASTFE = M ? M->getASTFile() : nullptr) {
@@ -5039,7 +5042,9 @@
 
   if (!ParentModule) {
 if (const FileEntry *CurFile = CurrentModule->getASTFile()) {
-  if (CurFile != F.File) {
+  // Don't emit module relocation error if we have -fno-validate-pch
+  if (!PP.getPreprocessorOpts().DisablePCHValidation &&
+  CurFile != F.File) {
 if (!Diags.isDiagnosticInFlight()) {
   Diag(diag::err_module_file_conflict)
 << CurrentModule->getTopLevelModuleName()


Index: cfe/trunk/test/Modules/resolution-change.m
===
--- cfe/trunk/test/Modules/resolution-change.m
+++ cfe/trunk/test/Modules/resolution-change.m
@@ -21,6 +21,8 @@
 // RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I %S/Inputs/modules-with-same-name/path2/A -include-pch %t-A.pch %s -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-WRONGA %s
 // CHECK-WRONGA: module 'A' was built in directory '{{.*Inputs.modules-with-same-name.path1.A}}' but now resides in directory '{{.*Inputs.modules-with-same-name.path2.A}}'
 
+// RUN: %clang_cc1 -fno-validate-pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I %S/Inputs/modules-with-same-name/path2/A -include-pch %t-A.pch %s -fsyntax-only
+
 #ifndef HEADER
 #define HEADER
 @import DependsOnA;
Index: cfe/trunk/lib/Serialization/ASTReader.cpp
===
--- cfe/trunk/lib/Serialization/ASTReader.cpp
+++ cfe/trunk/lib/Serialization/ASTReader.cpp
@@ -2632,7 +2632,9 @@
   if (M && M->Directory) {
 // If we're implicitly loading a module, the base directory can't
 // change between the build and use.
-if (F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
+// Don't emit module relocation error if we have -fno-validate-pch
+if (!PP.getPreprocessorOpts().DisablePCHValidation &&
+F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
   const DirectoryEntry 

[PATCH] D34055: Be more strict when checking the -flto option value

2017-06-09 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 102051.
yamaguchi added a comment.

I think we don't need additional testcase, because this is non-functional 
change. Driver.cpp will emit error if value was not "thin" nor "full". This 
testcase is at clang/test/CodeGen/thinlto-backend-option.ll.


https://reviews.llvm.org/D34055

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -649,8 +649,9 @@
   Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
 
   Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ);
-  const Arg *A = Args.getLastArg(OPT_flto, OPT_flto_EQ);
-  Opts.EmitSummaryIndex = A && A->containsValue("thin");
+  Opts.EmitSummaryIndex =
+  Args.hasArg(OPT_flto_EQ) &&
+  StringRef(Args.getLastArgValue(OPT_flto_EQ)) == "thin";
   Opts.LTOUnit = Args.hasFlag(OPT_flto_unit, OPT_fno_lto_unit, false);
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != InputKind::LLVM_IR)


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -649,8 +649,9 @@
   Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
 
   Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ);
-  const Arg *A = Args.getLastArg(OPT_flto, OPT_flto_EQ);
-  Opts.EmitSummaryIndex = A && A->containsValue("thin");
+  Opts.EmitSummaryIndex =
+  Args.hasArg(OPT_flto_EQ) &&
+  StringRef(Args.getLastArgValue(OPT_flto_EQ)) == "thin";
   Opts.LTOUnit = Args.hasFlag(OPT_flto_unit, OPT_fno_lto_unit, false);
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != InputKind::LLVM_IR)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34055: Be more strict when checking the -flto option value

2017-06-14 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 102551.
yamaguchi added a comment.
Herald added a subscriber: eraman.

Update patch. Add testcase and check if argument is valid or not.


https://reviews.llvm.org/D34055

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/thinlto-backend-option.ll


Index: clang/test/CodeGen/thinlto-backend-option.ll
===
--- clang/test/CodeGen/thinlto-backend-option.ll
+++ clang/test/CodeGen/thinlto-backend-option.ll
@@ -8,6 +8,8 @@
 
 ; RUN: %clang -flto=thin -c -o %t.o %s
 ; RUN: llvm-lto -thinlto -o %t %t.o
-; RUN: not %clang_cc1 -x ir %t.o -fthinlto-index=%t.thinlto.bc -backend-option 
-nonexistent -emit-obj -o /dev/null 2>&1 | FileCheck %s
+; RUN: not %clang_cc1 -x ir %t.o -fthinlto-index=%t.thinlto.bc -backend-option 
-nonexistent -emit-obj -o /dev/null 2>&1 | FileCheck %s -check-prefix=UNKNOWN
+; UNKNOWN: clang: Unknown command line argument '-nonexistent'
 
-; CHECK: clang: Unknown command line argument '-nonexistent'
+; RUN: not %clang_cc1 -flto=thinfoo 2>&1 | FileCheck %s -check-prefix=INVALID
+; INVALID: error: invalid value 'thinfoo' in '-flto=thinfoo' 
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -649,8 +649,14 @@
   Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
 
   Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ);
-  const Arg *A = Args.getLastArg(OPT_flto, OPT_flto_EQ);
-  Opts.EmitSummaryIndex = A && A->containsValue("thin");
+  Opts.EmitSummaryIndex = false;
+  if (Arg *A = Args.getLastArg(OPT_flto_EQ)) {
+StringRef S = A->getValue();
+if (S == "thin")
+  Opts.EmitSummaryIndex = true;
+else if (S != "full")
+  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << S;
+  }
   Opts.LTOUnit = Args.hasFlag(OPT_flto_unit, OPT_fno_lto_unit, false);
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != InputKind::LLVM_IR)


Index: clang/test/CodeGen/thinlto-backend-option.ll
===
--- clang/test/CodeGen/thinlto-backend-option.ll
+++ clang/test/CodeGen/thinlto-backend-option.ll
@@ -8,6 +8,8 @@
 
 ; RUN: %clang -flto=thin -c -o %t.o %s
 ; RUN: llvm-lto -thinlto -o %t %t.o
-; RUN: not %clang_cc1 -x ir %t.o -fthinlto-index=%t.thinlto.bc -backend-option -nonexistent -emit-obj -o /dev/null 2>&1 | FileCheck %s
+; RUN: not %clang_cc1 -x ir %t.o -fthinlto-index=%t.thinlto.bc -backend-option -nonexistent -emit-obj -o /dev/null 2>&1 | FileCheck %s -check-prefix=UNKNOWN
+; UNKNOWN: clang: Unknown command line argument '-nonexistent'
 
-; CHECK: clang: Unknown command line argument '-nonexistent'
+; RUN: not %clang_cc1 -flto=thinfoo 2>&1 | FileCheck %s -check-prefix=INVALID
+; INVALID: error: invalid value 'thinfoo' in '-flto=thinfoo' 
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -649,8 +649,14 @@
   Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
 
   Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ);
-  const Arg *A = Args.getLastArg(OPT_flto, OPT_flto_EQ);
-  Opts.EmitSummaryIndex = A && A->containsValue("thin");
+  Opts.EmitSummaryIndex = false;
+  if (Arg *A = Args.getLastArg(OPT_flto_EQ)) {
+StringRef S = A->getValue();
+if (S == "thin")
+  Opts.EmitSummaryIndex = true;
+else if (S != "full")
+  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << S;
+  }
   Opts.LTOUnit = Args.hasFlag(OPT_flto_unit, OPT_fno_lto_unit, false);
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != InputKind::LLVM_IR)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34055: Be more strict when checking the -flto option value

2017-06-14 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305392: Be more strict when checking the -flto option value 
(authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D34055?vs=102551&id=102555#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34055

Files:
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/thinlto-backend-option.ll


Index: cfe/trunk/test/CodeGen/thinlto-backend-option.ll
===
--- cfe/trunk/test/CodeGen/thinlto-backend-option.ll
+++ cfe/trunk/test/CodeGen/thinlto-backend-option.ll
@@ -8,6 +8,8 @@
 
 ; RUN: %clang -flto=thin -c -o %t.o %s
 ; RUN: llvm-lto -thinlto -o %t %t.o
-; RUN: not %clang_cc1 -x ir %t.o -fthinlto-index=%t.thinlto.bc -backend-option 
-nonexistent -emit-obj -o /dev/null 2>&1 | FileCheck %s
+; RUN: not %clang_cc1 -x ir %t.o -fthinlto-index=%t.thinlto.bc -backend-option 
-nonexistent -emit-obj -o /dev/null 2>&1 | FileCheck %s -check-prefix=UNKNOWN
+; UNKNOWN: clang: Unknown command line argument '-nonexistent'
 
-; CHECK: clang: Unknown command line argument '-nonexistent'
+; RUN: not %clang_cc1 -flto=thinfoo 2>&1 | FileCheck %s -check-prefix=INVALID
+; INVALID: error: invalid value 'thinfoo' in '-flto=thinfoo'
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -649,8 +649,14 @@
   Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
 
   Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ);
-  const Arg *A = Args.getLastArg(OPT_flto, OPT_flto_EQ);
-  Opts.EmitSummaryIndex = A && A->containsValue("thin");
+  Opts.EmitSummaryIndex = false;
+  if (Arg *A = Args.getLastArg(OPT_flto_EQ)) {
+StringRef S = A->getValue();
+if (S == "thin")
+  Opts.EmitSummaryIndex = true;
+else if (S != "full")
+  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << S;
+  }
   Opts.LTOUnit = Args.hasFlag(OPT_flto_unit, OPT_fno_lto_unit, false);
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != InputKind::LLVM_IR)


Index: cfe/trunk/test/CodeGen/thinlto-backend-option.ll
===
--- cfe/trunk/test/CodeGen/thinlto-backend-option.ll
+++ cfe/trunk/test/CodeGen/thinlto-backend-option.ll
@@ -8,6 +8,8 @@
 
 ; RUN: %clang -flto=thin -c -o %t.o %s
 ; RUN: llvm-lto -thinlto -o %t %t.o
-; RUN: not %clang_cc1 -x ir %t.o -fthinlto-index=%t.thinlto.bc -backend-option -nonexistent -emit-obj -o /dev/null 2>&1 | FileCheck %s
+; RUN: not %clang_cc1 -x ir %t.o -fthinlto-index=%t.thinlto.bc -backend-option -nonexistent -emit-obj -o /dev/null 2>&1 | FileCheck %s -check-prefix=UNKNOWN
+; UNKNOWN: clang: Unknown command line argument '-nonexistent'
 
-; CHECK: clang: Unknown command line argument '-nonexistent'
+; RUN: not %clang_cc1 -flto=thinfoo 2>&1 | FileCheck %s -check-prefix=INVALID
+; INVALID: error: invalid value 'thinfoo' in '-flto=thinfoo'
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -649,8 +649,14 @@
   Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
 
   Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ);
-  const Arg *A = Args.getLastArg(OPT_flto, OPT_flto_EQ);
-  Opts.EmitSummaryIndex = A && A->containsValue("thin");
+  Opts.EmitSummaryIndex = false;
+  if (Arg *A = Args.getLastArg(OPT_flto_EQ)) {
+StringRef S = A->getValue();
+if (S == "thin")
+  Opts.EmitSummaryIndex = true;
+else if (S != "full")
+  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << S;
+  }
   Opts.LTOUnit = Args.hasFlag(OPT_flto_unit, OPT_fno_lto_unit, false);
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != InputKind::LLVM_IR)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32341: Fix a bug that warnings generated with -M or -MM flags

2017-06-16 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi closed this revision.
yamaguchi added a comment.

Landed in r305561.


https://reviews.llvm.org/D32341



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


[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 102944.
yamaguchi marked 3 inline comments as done.
yamaguchi added a comment.
Herald added a subscriber: hiraditya.

Update patch and add support for `clang -stdlib=[tab]` case.
In this case we expect to see all possible values.
(Eg. `libc++ libstdc++ platform` for `clang -stdlib=[tab]`).


https://reviews.llvm.org/D33383

Files:
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  lld/COFF/Driver.h
  lld/COFF/DriverUtils.cpp
  lld/ELF/Driver.h
  lld/ELF/DriverUtils.cpp
  lld/lib/Driver/DarwinLdDriver.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/Option/OptTable.cpp
  llvm/lib/Option/Option.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/unittests/Option/OptionParsingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -196,6 +196,9 @@
   OS << ", nullptr";
 
 // The option meta-variable name (unused).
+OS << ", nullptr";
+
+// The option Values (unused for groups).
 OS << ", nullptr)\n";
   }
   OS << "\n";
@@ -285,6 +288,13 @@
 else
   OS << "nullptr";
 
+// The option Values. Used for shell autocompletion.
+OS << ", ";
+if (!isa(R.getValueInit("ArgValues")))
+  write_cstring(OS, R.getValueAsString("ArgValues"));
+else
+  OS << "nullptr";
+
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -18,8 +18,9 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR) OPT_##ID,
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  OPT_##ID,
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -36,10 +37,10 @@
 };
 
 static const OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR)   \
-  { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \
-FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
+   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-cvtres/llvm-cvtres.cpp
===
--- llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -37,7 +37,7 @@
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   OPT_##ID,
 #include "Opts.inc"
 #undef OPTION
@@ -49,12 +49,12 @@
 
 static const opt::OptTable::Info InfoTable[] = {
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   {\
-  PREFIX,  NAME, HELPTEXT, \
-  METAVAR, OPT_##ID, opt::Option::KIND##Class, \
-  PARAM,   FLAGS,OPT_##GROUP,  \
-  OPT_##ALIAS, ALIASARGS},
+  PREFIX,  NAME,  HELPTEXT,\
+  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
+  PARAM,   FLAGS, OPT_##GROUP, \
+  OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -31,7 +31,7 @@
 
 enum {
   OPT_INVALID = 0,
-#define OPTION(_1, _

[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: clang/test/Driver/autocomplete.c:7
 // NONE: foo
+// RUN: %clang --autocomplete=l,=,-stdlib | FileCheck %s -check-prefix=STDLIB
+// STDLIB: libc++ libstdc++

ruiu wrote:
> Why do you want to pass the arguments in the reverse order?
In the reverse order, current flag is always exists at first, so I thought it 
is more simple. (Eg. `clang -fsyntax-only -o foo -std=c` will be passed as 
`c,=,-std,foo,-i,-fsyntax-only`)


https://reviews.llvm.org/D33383



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


[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi marked 2 inline comments as done.
yamaguchi added inline comments.



Comment at: llvm/lib/Option/OptTable.cpp:198
+  continue;
+std::string S = "-" + std::string(In.Name);
+std::string C = (Command[1] == "=") ? 

yamaguchi wrote:
> teemperor wrote:
> > Hmm, will this work with "--" flags? Also, same as above with naming `S` 
> > and `C`.
> @teemperor 
> Do you think we should add some sample value completions to flags start with 
> "--" (such as --target) and flags which don't contain "=" (such as -mllvm 
> ) ?
> This part of code is rather ad hoc right now for -stdlib.
I had add support for this in this update as well, thanks.


https://reviews.llvm.org/D33383



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


[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 102946.
yamaguchi marked 5 inline comments as done.
yamaguchi added a comment.

Update patch. Rui's comment about the bash part is very reasonable.


https://reviews.llvm.org/D33383

Files:
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  lld/COFF/Driver.h
  lld/COFF/DriverUtils.cpp
  lld/ELF/Driver.h
  lld/ELF/DriverUtils.cpp
  lld/lib/Driver/DarwinLdDriver.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/Option/OptTable.cpp
  llvm/lib/Option/Option.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/unittests/Option/OptionParsingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -196,6 +196,9 @@
   OS << ", nullptr";
 
 // The option meta-variable name (unused).
+OS << ", nullptr";
+
+// The option Values (unused for groups).
 OS << ", nullptr)\n";
   }
   OS << "\n";
@@ -285,6 +288,13 @@
 else
   OS << "nullptr";
 
+// The option Values. Used for shell autocompletion.
+OS << ", ";
+if (!isa(R.getValueInit("ArgValues")))
+  write_cstring(OS, R.getValueAsString("ArgValues"));
+else
+  OS << "nullptr";
+
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -18,8 +18,9 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR) OPT_##ID,
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  OPT_##ID,
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -36,10 +37,10 @@
 };
 
 static const OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR)   \
-  { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \
-FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
+   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-cvtres/llvm-cvtres.cpp
===
--- llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -37,7 +37,7 @@
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   OPT_##ID,
 #include "Opts.inc"
 #undef OPTION
@@ -49,12 +49,12 @@
 
 static const opt::OptTable::Info InfoTable[] = {
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   {\
-  PREFIX,  NAME, HELPTEXT, \
-  METAVAR, OPT_##ID, opt::Option::KIND##Class, \
-  PARAM,   FLAGS,OPT_##GROUP,  \
-  OPT_##ALIAS, ALIASARGS},
+  PREFIX,  NAME,  HELPTEXT,\
+  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
+  PARAM,   FLAGS, OPT_##GROUP, \
+  OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -31,7 +31,7 @@
 
 enum {
   OPT_INVALID = 0,
-#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
+#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
 #include "Opti

[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 102958.
yamaguchi marked 10 inline comments as done.
yamaguchi added a comment.

Cleaned suggestValueCompletions and bash-autocomplete.sh, and added tests.

We have passed flags and values from bash to clang like `clang 
--autocomplete=l,=,-stdlib`, but I've changed this to pass `clang 
--autocomplte=-stdlib=,l` instead. This is more simple.

Added support and test for -meabi flag.
This flag is corner case, because it doesn't take `=` suffix like `-stdlib=`.

When `clang -stdlib=[tab]` is pushed, we would give possible values 
(libstd++,..), and when `clang -stdlib= [tab]` is pushed, we just give files 
under current directory.
And when `clang -meabi [tab]` is pushed, we give possible values (gnu,..).


https://reviews.llvm.org/D33383

Files:
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  lld/COFF/Driver.h
  lld/COFF/DriverUtils.cpp
  lld/ELF/Driver.h
  lld/ELF/DriverUtils.cpp
  lld/lib/Driver/DarwinLdDriver.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/Option/OptTable.cpp
  llvm/lib/Option/Option.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/unittests/Option/OptionParsingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -196,6 +196,9 @@
   OS << ", nullptr";
 
 // The option meta-variable name (unused).
+OS << ", nullptr";
+
+// The option Values (unused for groups).
 OS << ", nullptr)\n";
   }
   OS << "\n";
@@ -285,6 +288,13 @@
 else
   OS << "nullptr";
 
+// The option Values. Used for shell autocompletion.
+OS << ", ";
+if (!isa(R.getValueInit("Values")))
+  write_cstring(OS, R.getValueAsString("Values"));
+else
+  OS << "nullptr";
+
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -18,8 +18,9 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR) OPT_##ID,
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  OPT_##ID,
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -36,10 +37,10 @@
 };
 
 static const OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR)   \
-  { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \
-FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
+   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-cvtres/llvm-cvtres.cpp
===
--- llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -37,7 +37,7 @@
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   OPT_##ID,
 #include "Opts.inc"
 #undef OPTION
@@ -49,12 +49,12 @@
 
 static const opt::OptTable::Info InfoTable[] = {
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   {\
-  PREFIX,  NAME, HELPTEXT, \
-  METAVAR, OPT_##ID, opt::Option::KIND##Class, \
-  PARAM,   FLAGS,OPT_##GROUP,  \
-  OPT_##ALIAS, ALIASARGS},
+  PREFIX,  NAME,  HELPTEXT,\
+  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
+  PARAM,   FLAGS, OPT

[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 102959.
yamaguchi marked an inline comment as done.
yamaguchi added a comment.

Made trivial change.


https://reviews.llvm.org/D33383

Files:
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  lld/COFF/Driver.h
  lld/COFF/DriverUtils.cpp
  lld/ELF/Driver.h
  lld/ELF/DriverUtils.cpp
  lld/lib/Driver/DarwinLdDriver.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/Option/OptTable.cpp
  llvm/lib/Option/Option.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/unittests/Option/OptionParsingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -196,6 +196,9 @@
   OS << ", nullptr";
 
 // The option meta-variable name (unused).
+OS << ", nullptr";
+
+// The option Values (unused for groups).
 OS << ", nullptr)\n";
   }
   OS << "\n";
@@ -285,6 +288,13 @@
 else
   OS << "nullptr";
 
+// The option Values. Used for shell autocompletion.
+OS << ", ";
+if (!isa(R.getValueInit("Values")))
+  write_cstring(OS, R.getValueAsString("Values"));
+else
+  OS << "nullptr";
+
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -18,8 +18,9 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR) OPT_##ID,
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  OPT_##ID,
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -36,10 +37,10 @@
 };
 
 static const OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR)   \
-  { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \
-FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
+   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-cvtres/llvm-cvtres.cpp
===
--- llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -37,7 +37,7 @@
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   OPT_##ID,
 #include "Opts.inc"
 #undef OPTION
@@ -49,12 +49,12 @@
 
 static const opt::OptTable::Info InfoTable[] = {
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   {\
-  PREFIX,  NAME, HELPTEXT, \
-  METAVAR, OPT_##ID, opt::Option::KIND##Class, \
-  PARAM,   FLAGS,OPT_##GROUP,  \
-  OPT_##ALIAS, ALIASARGS},
+  PREFIX,  NAME,  HELPTEXT,\
+  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
+  PARAM,   FLAGS, OPT_##GROUP, \
+  OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -31,7 +31,7 @@
 
 enum {
   OPT_INVALID = 0,
-#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
+#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
 #include "Options.inc"
 #undef OPTION
 };
@@ -41,11 +41,9 @@
 #unde

[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 102960.
yamaguchi added a comment.

Made trivial bug fix.


https://reviews.llvm.org/D33383

Files:
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  lld/COFF/Driver.h
  lld/COFF/DriverUtils.cpp
  lld/ELF/Driver.h
  lld/ELF/DriverUtils.cpp
  lld/lib/Driver/DarwinLdDriver.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/Option/OptTable.cpp
  llvm/lib/Option/Option.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/unittests/Option/OptionParsingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -196,6 +196,9 @@
   OS << ", nullptr";
 
 // The option meta-variable name (unused).
+OS << ", nullptr";
+
+// The option Values (unused for groups).
 OS << ", nullptr)\n";
   }
   OS << "\n";
@@ -285,6 +288,13 @@
 else
   OS << "nullptr";
 
+// The option Values. Used for shell autocompletion.
+OS << ", ";
+if (!isa(R.getValueInit("Values")))
+  write_cstring(OS, R.getValueAsString("Values"));
+else
+  OS << "nullptr";
+
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -18,8 +18,9 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR) OPT_##ID,
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  OPT_##ID,
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -36,10 +37,10 @@
 };
 
 static const OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR)   \
-  { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \
-FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
+   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-cvtres/llvm-cvtres.cpp
===
--- llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -37,7 +37,7 @@
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   OPT_##ID,
 #include "Opts.inc"
 #undef OPTION
@@ -49,12 +49,12 @@
 
 static const opt::OptTable::Info InfoTable[] = {
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   {\
-  PREFIX,  NAME, HELPTEXT, \
-  METAVAR, OPT_##ID, opt::Option::KIND##Class, \
-  PARAM,   FLAGS,OPT_##GROUP,  \
-  OPT_##ALIAS, ALIASARGS},
+  PREFIX,  NAME,  HELPTEXT,\
+  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
+  PARAM,   FLAGS, OPT_##GROUP, \
+  OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -31,7 +31,7 @@
 
 enum {
   OPT_INVALID = 0,
-#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
+#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
 #include "Options.inc"
 #undef OPTION
 };
@@ -41,11 +41,9 @@
 #undef PREFIX
 
 static const llvm::opt::OptTabl

[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 102961.
yamaguchi added a comment.

Made trivial change.


https://reviews.llvm.org/D33383

Files:
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  lld/COFF/Driver.h
  lld/COFF/DriverUtils.cpp
  lld/ELF/Driver.h
  lld/ELF/DriverUtils.cpp
  lld/lib/Driver/DarwinLdDriver.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/Option/OptTable.cpp
  llvm/lib/Option/Option.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/unittests/Option/OptionParsingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -196,6 +196,9 @@
   OS << ", nullptr";
 
 // The option meta-variable name (unused).
+OS << ", nullptr";
+
+// The option Values (unused for groups).
 OS << ", nullptr)\n";
   }
   OS << "\n";
@@ -285,6 +288,13 @@
 else
   OS << "nullptr";
 
+// The option Values. Used for shell autocompletion.
+OS << ", ";
+if (!isa(R.getValueInit("Values")))
+  write_cstring(OS, R.getValueAsString("Values"));
+else
+  OS << "nullptr";
+
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -18,8 +18,9 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR) OPT_##ID,
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  OPT_##ID,
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -36,10 +37,10 @@
 };
 
 static const OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR)   \
-  { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \
-FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
+   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-cvtres/llvm-cvtres.cpp
===
--- llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -37,7 +37,7 @@
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   OPT_##ID,
 #include "Opts.inc"
 #undef OPTION
@@ -49,12 +49,12 @@
 
 static const opt::OptTable::Info InfoTable[] = {
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   {\
-  PREFIX,  NAME, HELPTEXT, \
-  METAVAR, OPT_##ID, opt::Option::KIND##Class, \
-  PARAM,   FLAGS,OPT_##GROUP,  \
-  OPT_##ALIAS, ALIASARGS},
+  PREFIX,  NAME,  HELPTEXT,\
+  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
+  PARAM,   FLAGS, OPT_##GROUP, \
+  OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -31,7 +31,7 @@
 
 enum {
   OPT_INVALID = 0,
-#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
+#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
 #include "Options.inc"
 #undef OPTION
 };
@@ -41,11 +41,9 @@
 #undef PREFIX
 
 static const llvm::opt::OptTable

[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-18 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 102964.
yamaguchi added a comment.

Made a trivial change in optionMatches.


https://reviews.llvm.org/D33383

Files:
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  lld/COFF/Driver.h
  lld/COFF/DriverUtils.cpp
  lld/ELF/Driver.h
  lld/ELF/DriverUtils.cpp
  lld/lib/Driver/DarwinLdDriver.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/Option/OptTable.cpp
  llvm/lib/Option/Option.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/unittests/Option/OptionParsingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -196,6 +196,9 @@
   OS << ", nullptr";
 
 // The option meta-variable name (unused).
+OS << ", nullptr";
+
+// The option Values (unused for groups).
 OS << ", nullptr)\n";
   }
   OS << "\n";
@@ -285,6 +288,13 @@
 else
   OS << "nullptr";
 
+// The option Values. Used for shell autocompletion.
+OS << ", ";
+if (!isa(R.getValueInit("Values")))
+  write_cstring(OS, R.getValueAsString("Values"));
+else
+  OS << "nullptr";
+
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -18,8 +18,9 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR) OPT_##ID,
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  OPT_##ID,
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -36,10 +37,10 @@
 };
 
 static const OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR)   \
-  { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \
-FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, ARGVALUE)\
+  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
+   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-cvtres/llvm-cvtres.cpp
===
--- llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -37,7 +37,7 @@
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   OPT_##ID,
 #include "Opts.inc"
 #undef OPTION
@@ -49,12 +49,12 @@
 
 static const opt::OptTable::Info InfoTable[] = {
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, ARGVALUE)\
   {\
-  PREFIX,  NAME, HELPTEXT, \
-  METAVAR, OPT_##ID, opt::Option::KIND##Class, \
-  PARAM,   FLAGS,OPT_##GROUP,  \
-  OPT_##ALIAS, ALIASARGS},
+  PREFIX,  NAME,  HELPTEXT,\
+  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
+  PARAM,   FLAGS, OPT_##GROUP, \
+  OPT_##ALIAS, ALIASARGS, ARGVALUE},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -31,7 +31,7 @@
 
 enum {
   OPT_INVALID = 0,
-#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
+#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
 #include "Options.inc"
 #undef OPTION
 };
@@ -41,11 +41,9 @@
 #undef PREFIX
 
 static const 

[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-18 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 102981.
yamaguchi marked 6 inline comments as done.
yamaguchi added a comment.

Update code comment according to Rui's comment.


https://reviews.llvm.org/D33383

Files:
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  lld/COFF/Driver.h
  lld/COFF/DriverUtils.cpp
  lld/ELF/Driver.h
  lld/ELF/DriverUtils.cpp
  lld/lib/Driver/DarwinLdDriver.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/Option/OptTable.cpp
  llvm/lib/Option/Option.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/unittests/Option/OptionParsingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -196,6 +196,9 @@
   OS << ", nullptr";
 
 // The option meta-variable name (unused).
+OS << ", nullptr";
+
+// The option Values (unused for groups).
 OS << ", nullptr)\n";
   }
   OS << "\n";
@@ -285,6 +288,13 @@
 else
   OS << "nullptr";
 
+// The option Values. Used for shell autocompletion.
+OS << ", ";
+if (!isa(R.getValueInit("Values")))
+  write_cstring(OS, R.getValueAsString("Values"));
+else
+  OS << "nullptr";
+
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -18,8 +18,9 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR) OPT_##ID,
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, VALUES)  \
+  OPT_##ID,
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -36,10 +37,10 @@
 };
 
 static const OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR)   \
-  { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \
-FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, VALUES)  \
+  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
+   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, VALUES},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-cvtres/llvm-cvtres.cpp
===
--- llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -37,7 +37,7 @@
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, VALUES)  \
   OPT_##ID,
 #include "Opts.inc"
 #undef OPTION
@@ -49,12 +49,12 @@
 
 static const opt::OptTable::Info InfoTable[] = {
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, VALUES)  \
   {\
-  PREFIX,  NAME, HELPTEXT, \
-  METAVAR, OPT_##ID, opt::Option::KIND##Class, \
-  PARAM,   FLAGS,OPT_##GROUP,  \
-  OPT_##ALIAS, ALIASARGS},
+  PREFIX,  NAME,  HELPTEXT,\
+  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
+  PARAM,   FLAGS, OPT_##GROUP, \
+  OPT_##ALIAS, ALIASARGS, VALUES},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -31,7 +31,7 @@
 
 enum {
   OPT_INVALID = 0,
-#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
+#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
 #include "Options.inc"
 #undef OPTION
 };
@@

[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-18 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 102982.
yamaguchi added a comment.

Add support and test for 
-cl-std=,-fno-sanitize-coverage=,-ffp-contract=,-flto=,-fveclib=,-fshow-overloads=,-fvisibility=,-mfloat-abi=,-mthread-model.


https://reviews.llvm.org/D33383

Files:
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  lld/COFF/Driver.h
  lld/COFF/DriverUtils.cpp
  lld/ELF/Driver.h
  lld/ELF/DriverUtils.cpp
  lld/lib/Driver/DarwinLdDriver.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/Option/OptTable.cpp
  llvm/lib/Option/Option.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-cvtres/llvm-cvtres.cpp
  llvm/unittests/Option/OptionParsingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -196,6 +196,9 @@
   OS << ", nullptr";
 
 // The option meta-variable name (unused).
+OS << ", nullptr";
+
+// The option Values (unused for groups).
 OS << ", nullptr)\n";
   }
   OS << "\n";
@@ -285,6 +288,13 @@
 else
   OS << "nullptr";
 
+// The option Values. Used for shell autocompletion.
+OS << ", ";
+if (!isa(R.getValueInit("Values")))
+  write_cstring(OS, R.getValueAsString("Values"));
+else
+  OS << "nullptr";
+
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
Index: llvm/unittests/Option/OptionParsingTest.cpp
===
--- llvm/unittests/Option/OptionParsingTest.cpp
+++ llvm/unittests/Option/OptionParsingTest.cpp
@@ -18,8 +18,9 @@
 
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR) OPT_##ID,
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, VALUES)  \
+  OPT_##ID,
 #include "Opts.inc"
   LastOption
 #undef OPTION
@@ -36,10 +37,10 @@
 };
 
 static const OptTable::Info InfoTable[] = {
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR)   \
-  { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \
-FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, VALUES)  \
+  {PREFIX, NAME,  HELPTEXT,METAVAR, OPT_##ID,  Option::KIND##Class,\
+   PARAM,  FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, VALUES},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/tools/llvm-cvtres/llvm-cvtres.cpp
===
--- llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -37,7 +37,7 @@
 enum ID {
   OPT_INVALID = 0, // This is not an option ID.
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, VALUES)  \
   OPT_##ID,
 #include "Opts.inc"
 #undef OPTION
@@ -49,12 +49,12 @@
 
 static const opt::OptTable::Info InfoTable[] = {
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
-   HELPTEXT, METAVAR)  \
+   HELPTEXT, METAVAR, VALUES)  \
   {\
-  PREFIX,  NAME, HELPTEXT, \
-  METAVAR, OPT_##ID, opt::Option::KIND##Class, \
-  PARAM,   FLAGS,OPT_##GROUP,  \
-  OPT_##ALIAS, ALIASARGS},
+  PREFIX,  NAME,  HELPTEXT,\
+  METAVAR, OPT_##ID,  opt::Option::KIND##Class,\
+  PARAM,   FLAGS, OPT_##GROUP, \
+  OPT_##ALIAS, ALIASARGS, VALUES},
 #include "Opts.inc"
 #undef OPTION
 };
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -31,7 +31,7 @@
 
 enum {
   OPT_INVALID = 0,
-#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
+#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, 

[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-20 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi closed this revision.
yamaguchi added a comment.

Landed in https://reviews.llvm.org/rL305805.


https://reviews.llvm.org/D33383



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


[PATCH] D34557: Sort the autocomplete candidates before printing them out.

2017-06-23 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi accepted this revision.
yamaguchi added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks for the patch.


https://reviews.llvm.org/D34557



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


[PATCH] D34607: [Bash-autocompletion] Check clang version in Bash

2017-06-25 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

Add check if user's clang version supports --autocomplete or not.
If not, we just autocomplete files.


https://reviews.llvm.org/D34607

Files:
  clang/utils/bash-autocomplete.sh


Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -1,7 +1,7 @@
 # Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use 
this.
 _clang()
 {
-  local cur prev words cword arg
+  local cur prev words cword arg flags
   _init_completion -n : || return
 
   # bash always separates '=' as a token even if there's no space before/after 
'='.
@@ -24,7 +24,12 @@
 arg="$w2=,$cur"
   fi
 
-  local flags=$( clang --autocomplete="$arg" )
+  flags=$( clang --autocomplete="$arg" 2>/dev/null )
+  # Check if --autocomplete is supported in user's clang version.
+  if [[ "$?" != 0 ]]; then
+_filedir
+return 0
+  fi
   if [[ "$cur" == '=' ]]; then
 COMPREPLY=( $( compgen -W "$flags" -- "") )
   elif [[ "$flags" == "" || "$arg" == "" ]]; then


Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -1,7 +1,7 @@
 # Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use this.
 _clang()
 {
-  local cur prev words cword arg
+  local cur prev words cword arg flags
   _init_completion -n : || return
 
   # bash always separates '=' as a token even if there's no space before/after '='.
@@ -24,7 +24,12 @@
 arg="$w2=,$cur"
   fi
 
-  local flags=$( clang --autocomplete="$arg" )
+  flags=$( clang --autocomplete="$arg" 2>/dev/null )
+  # Check if --autocomplete is supported in user's clang version.
+  if [[ "$?" != 0 ]]; then
+_filedir
+return 0
+  fi
   if [[ "$cur" == '=' ]]; then
 COMPREPLY=( $( compgen -W "$flags" -- "") )
   elif [[ "$flags" == "" || "$arg" == "" ]]; then
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34607: [Bash-autocompletion] Check clang version in Bash

2017-06-25 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 103884.
yamaguchi added a comment.

Update patch.


https://reviews.llvm.org/D34607

Files:
  clang/utils/bash-autocomplete.sh


Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -1,7 +1,7 @@
 # Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use 
this.
 _clang()
 {
-  local cur prev words cword arg
+  local cur prev words cword arg flags
   _init_completion -n : || return
 
   # bash always separates '=' as a token even if there's no space before/after 
'='.
@@ -24,7 +24,14 @@
 arg="$w2=,$cur"
   fi
 
-  local flags=$( clang --autocomplete="$arg" )
+  flags=$( clang --autocomplete="$arg" 2>/dev/null )
+  # If clang is old that it does not support --autocomplete,
+  # fall back to the filename completion.
+  if [[ "$?" != 0 ]]; then
+_filedir
+return
+  fi
+
   if [[ "$cur" == '=' ]]; then
 COMPREPLY=( $( compgen -W "$flags" -- "") )
   elif [[ "$flags" == "" || "$arg" == "" ]]; then


Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -1,7 +1,7 @@
 # Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use this.
 _clang()
 {
-  local cur prev words cword arg
+  local cur prev words cword arg flags
   _init_completion -n : || return
 
   # bash always separates '=' as a token even if there's no space before/after '='.
@@ -24,7 +24,14 @@
 arg="$w2=,$cur"
   fi
 
-  local flags=$( clang --autocomplete="$arg" )
+  flags=$( clang --autocomplete="$arg" 2>/dev/null )
+  # If clang is old that it does not support --autocomplete,
+  # fall back to the filename completion.
+  if [[ "$?" != 0 ]]; then
+_filedir
+return
+  fi
+
   if [[ "$cur" == '=' ]]; then
 COMPREPLY=( $( compgen -W "$flags" -- "") )
   elif [[ "$flags" == "" || "$arg" == "" ]]; then
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39342: [Bash-autocompletion] Pass all flags in shell command-line to Clang

2018-03-05 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326684: [Bash-autocompletion] Pass all flags in shell 
command-line to Clang (authored by yamaguchi, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D39342?vs=121449&id=136955#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39342

Files:
  cfe/trunk/include/clang/Driver/Driver.h
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/test/Driver/autocomplete.c
  cfe/trunk/utils/bash-autocomplete.sh
  llvm/trunk/lib/Option/OptTable.cpp

Index: llvm/trunk/lib/Option/OptTable.cpp
===
--- llvm/trunk/lib/Option/OptTable.cpp
+++ llvm/trunk/lib/Option/OptTable.cpp
@@ -219,7 +219,7 @@
 
 std::vector Result;
 for (StringRef Val : Candidates)
-  if (Val.startswith(Arg))
+  if (Val.startswith(Arg) && Arg.compare(Val))
 Result.push_back(Val);
 return Result;
   }
@@ -240,7 +240,7 @@
   std::string S = std::string(In.Prefixes[I]) + std::string(In.Name) + "\t";
   if (In.HelpText)
 S += In.HelpText;
-  if (StringRef(S).startswith(Cur))
+  if (StringRef(S).startswith(Cur) && S.compare(std::string(Cur) + "\t"))
 Ret.push_back(S);
 }
   }
Index: cfe/trunk/include/clang/Driver/Driver.h
===
--- cfe/trunk/include/clang/Driver/Driver.h
+++ cfe/trunk/include/clang/Driver/Driver.h
@@ -442,9 +442,9 @@
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
-  /// handleAutocompletions - Handle --autocomplete by searching and printing
+  /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
-  void handleAutocompletions(StringRef PassedFlags) const;
+  void HandleAutocompletions(StringRef PassedFlags) const;
 
   /// HandleImmediateArgs - Handle any arguments which should be
   /// treated before building actions or binding tools.
Index: cfe/trunk/test/Driver/autocomplete.c
===
--- cfe/trunk/test/Driver/autocomplete.c
+++ cfe/trunk/test/Driver/autocomplete.c
@@ -3,41 +3,36 @@
 // add/modify flags, change HelpTexts or the values of some flags.
 
 // Some corner cases.
-// RUN: %clang --autocomplete= | FileCheck %s -check-prefix=ALL_FLAGS
-// RUN: %clang --autocomplete=# | FileCheck %s -check-prefix=ALL_FLAGS
-// Let's pick some example flags that are hopefully unlikely to change.
-// ALL_FLAGS: -fast
-// ALL_FLAGS: -fastcp
-// ALL_FLAGS: -fastf
 // Just test that this doesn't crash:
+// RUN: %clang --autocomplete=
 // RUN: %clang --autocomplete=,
 // RUN: %clang --autocomplete==
 // RUN: %clang --autocomplete=,,
 // RUN: %clang --autocomplete=-
 
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
-// RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD
+// RUN: %clang --autocomplete=-std | FileCheck %s -check-prefix=STD
 // STD: -std= Language standard to compile for
 // RUN: %clang --autocomplete=foo | FileCheck %s -check-prefix=FOO
 // FOO-NOT: foo
 // RUN: %clang --autocomplete=-stdlib=,l | FileCheck %s -check-prefix=STDLIB
 // STDLIB: libc++
 // STDLIB-NEXT: libstdc++
-// RUN: %clang --autocomplete=-stdlib=, | FileCheck %s -check-prefix=STDLIBALL
+// RUN: %clang --autocomplete=-stdlib= | FileCheck %s -check-prefix=STDLIBALL
 // STDLIBALL: libc++
 // STDLIBALL-NEXT: libstdc++
 // STDLIBALL-NEXT: platform
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
-// RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
+// RUN: %clang --autocomplete=-meabi | FileCheck %s -check-prefix=MEABIALL
 // MEABIALL: 4
 // MEABIALL-NEXT: 5
 // MEABIALL-NEXT: default
 // MEABIALL-NEXT: gnu
 // RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD
 // CLSTD: CL2.0
-// RUN: %clang --autocomplete=-cl-std=, | FileCheck %s -check-prefix=CLSTDALL
+// RUN: %clang --autocomplete=-cl-std= | FileCheck %s -check-prefix=CLSTDALL
 // CLSTDALL: cl
 // CLSTDALL-NEXT: CL
 // CLSTDALL-NEXT: cl1.1
@@ -48,7 +43,7 @@
 // CLSTDALL-NEXT: CL2.0
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=,f | FileCheck %s -check-prefix=FNOSANICOVER
 // FNOSANICOVER: func
-// RUN: %clang --autocomplete=-fno-sanitize-coverage=, | FileCheck %s -check-prefix=FNOSANICOVERALL
+// RUN: %clang --autocomplete=-fno-sanitize-coverage= | FileCheck %s -check-prefix=FNOSANICOVERALL
 // FNOSANICOVERALL: 8bit-counters
 // FNOSANICOVERALL-NEXT: bb
 // FNOSANICOVERALL-NEXT: edge
@@ -62,41 +57,37 @@
 // FNOSANICOVERALL-NEXT: trace-gep
 // FNOSANICOVERALL-NEXT: trace-pc
 // FNOSANICOVERALL-NEXT: trace-pc-guard
-// RUN: %clang --autocomplete=-ffp-contract=, | FileCheck %s -check-prefix=FFPALL
+// RUN: %clang --autocom

[PATCH] D44191: Add Clang ReleaseNotes that --autocomplete breaks backward compatibily

2018-03-07 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added reviewers: teemperor, v.g.vassilev.

--autocomplete flag now handles all the flags passed to shell, and this
implementation breaks backward compatibily before Clang 6.0.


https://reviews.llvm.org/D44191

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -71,6 +71,16 @@
 
 - ...
 
+Modified Compiler Flags
+---
+
+- Before Clang 6.0, we passed "#" to --autocomplete flag to indicate to enable 
cc1
+  flags. For example, when -cc1 or -Xclang was passed to shell, shell executed 
clang
+  --autocomplete=#-. Clang 7.0 now passes all 
flags that
+  shell has, so that Clang can handle them internally which breaks backward 
compatibility
+  before Clang 6.0.
+
+
 New Pragmas in Clang
 ---
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -71,6 +71,16 @@
 
 - ...
 
+Modified Compiler Flags
+---
+
+- Before Clang 6.0, we passed "#" to --autocomplete flag to indicate to enable cc1
+  flags. For example, when -cc1 or -Xclang was passed to shell, shell executed clang
+  --autocomplete=#-. Clang 7.0 now passes all flags that
+  shell has, so that Clang can handle them internally which breaks backward compatibility
+  before Clang 6.0.
+
+
 New Pragmas in Clang
 ---
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44191: Add Clang ReleaseNotes that --autocomplete breaks backward compatibily

2018-03-07 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 137352.
yamaguchi added a comment.

Fixed typos


https://reviews.llvm.org/D44191

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -71,6 +71,15 @@
 
 - ...
 
+Modified Compiler Flags
+---
+
+- Before Clang 7.0, we prepended the "#" character to the --autocomplete 
argument to
+enable cc1 flags. For example, when the -cc1 or -Xclang flag is in the clang 
invocation,
+the shell executed clang --autocomplete=#-. Clang 7.0 now
+requires the whole invocation including all flags to be passed to the 
--autocomplete
+like this: clang --autocomplete=-cc1,-xc++,-fsyn.
+
 New Pragmas in Clang
 ---
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -71,6 +71,15 @@
 
 - ...
 
+Modified Compiler Flags
+---
+
+- Before Clang 7.0, we prepended the "#" character to the --autocomplete argument to
+enable cc1 flags. For example, when the -cc1 or -Xclang flag is in the clang invocation,
+the shell executed clang --autocomplete=#-. Clang 7.0 now
+requires the whole invocation including all flags to be passed to the --autocomplete
+like this: clang --autocomplete=-cc1,-xc++,-fsyn.
+
 New Pragmas in Clang
 ---
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44191: Add Clang ReleaseNotes that --autocomplete breaks backward compatibily

2018-03-07 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326889: Add Clang ReleaseNotes that --autocomplete breaks 
backward compatibily (authored by yamaguchi, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44191?vs=137352&id=137356#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44191

Files:
  cfe/trunk/docs/ReleaseNotes.rst


Index: cfe/trunk/docs/ReleaseNotes.rst
===
--- cfe/trunk/docs/ReleaseNotes.rst
+++ cfe/trunk/docs/ReleaseNotes.rst
@@ -71,6 +71,15 @@
 
 - ...
 
+Modified Compiler Flags
+---
+
+- Before Clang 7.0, we prepended the "#" character to the --autocomplete 
argument to
+enable cc1 flags. For example, when the -cc1 or -Xclang flag is in the clang 
invocation,
+the shell executed clang --autocomplete=#-. Clang 7.0 now
+requires the whole invocation including all flags to be passed to the 
--autocomplete
+like this: clang --autocomplete=-cc1,-xc++,-fsyn.
+
 New Pragmas in Clang
 ---
 


Index: cfe/trunk/docs/ReleaseNotes.rst
===
--- cfe/trunk/docs/ReleaseNotes.rst
+++ cfe/trunk/docs/ReleaseNotes.rst
@@ -71,6 +71,15 @@
 
 - ...
 
+Modified Compiler Flags
+---
+
+- Before Clang 7.0, we prepended the "#" character to the --autocomplete argument to
+enable cc1 flags. For example, when the -cc1 or -Xclang flag is in the clang invocation,
+the shell executed clang --autocomplete=#-. Clang 7.0 now
+requires the whole invocation including all flags to be passed to the --autocomplete
+like this: clang --autocomplete=-cc1,-xc++,-fsyn.
+
 New Pragmas in Clang
 ---
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44508: Remove unnecessary include from Driver.cpp

2018-03-15 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added a reviewer: dlj.
Herald added a subscriber: llvm-commits.

Clang compiles and test passes without these includes.


Repository:
  rL LLVM

https://reviews.llvm.org/D44508

Files:
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -73,8 +73,6 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/StringSaver.h"
 #include 
-#include 
-#include 
 #if LLVM_ON_UNIX
 #include  // getpid
 #endif


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -73,8 +73,6 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/StringSaver.h"
 #include 
-#include 
-#include 
 #if LLVM_ON_UNIX
 #include  // getpid
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44508: Remove unnecessary include from Driver.cpp

2018-03-16 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 138671.
yamaguchi added a comment.

@marsupial Thanks for the commment, found a bug in my script and fixed. Now 
this patch removes only includes which are not used in each TU.


Repository:
  rL LLVM

https://reviews.llvm.org/D44508

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/DriverOptions.cpp
  clang/lib/Driver/Multilib.cpp
  clang/lib/Driver/Phases.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/Types.cpp


Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include 
-#include 
 
 using namespace clang::driver;
 using namespace clang::driver::types;
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -18,7 +18,6 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SpecialCaseList.h"
-#include 
 
 using namespace clang;
 using namespace clang::SanitizerKind;
Index: clang/lib/Driver/Phases.cpp
===
--- clang/lib/Driver/Phases.cpp
+++ clang/lib/Driver/Phases.cpp
@@ -9,7 +9,6 @@
 
 #include "clang/Driver/Phases.h"
 #include "llvm/Support/ErrorHandling.h"
-#include 
 
 using namespace clang::driver;
 
Index: clang/lib/Driver/Multilib.cpp
===
--- clang/lib/Driver/Multilib.cpp
+++ clang/lib/Driver/Multilib.cpp
@@ -22,7 +22,6 @@
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
-#include 
 
 using namespace clang::driver;
 using namespace clang;
Index: clang/lib/Driver/DriverOptions.cpp
===
--- clang/lib/Driver/DriverOptions.cpp
+++ clang/lib/Driver/DriverOptions.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
-#include 
 
 using namespace clang::driver;
 using namespace clang::driver::options;
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -72,7 +72,6 @@
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/StringSaver.h"
-#include 
 #include 
 #include 
 #if LLVM_ON_UNIX


Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include 
-#include 
 
 using namespace clang::driver;
 using namespace clang::driver::types;
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -18,7 +18,6 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SpecialCaseList.h"
-#include 
 
 using namespace clang;
 using namespace clang::SanitizerKind;
Index: clang/lib/Driver/Phases.cpp
===
--- clang/lib/Driver/Phases.cpp
+++ clang/lib/Driver/Phases.cpp
@@ -9,7 +9,6 @@
 
 #include "clang/Driver/Phases.h"
 #include "llvm/Support/ErrorHandling.h"
-#include 
 
 using namespace clang::driver;
 
Index: clang/lib/Driver/Multilib.cpp
===
--- clang/lib/Driver/Multilib.cpp
+++ clang/lib/Driver/Multilib.cpp
@@ -22,7 +22,6 @@
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
-#include 
 
 using namespace clang::driver;
 using namespace clang;
Index: clang/lib/Driver/DriverOptions.cpp
===
--- clang/lib/Driver/DriverOptions.cpp
+++ clang/lib/Driver/DriverOptions.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
-#include 
 
 using namespace clang::driver;
 using namespace clang::driver::options;
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -72,7 +72,6 @@
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/StringSaver.h"
-#include 
 #include 
 #include 
 #if LLVM_ON_UNIX
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48367: [modules] Fix 37878; Autoload subdirectory modulemaps with specific LangOpts

2018-06-20 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added reviewers: rsmith, aprantl, bruno.

Reproducer and errors:
https://bugs.llvm.org/show_bug.cgi?id=37878

lookupModule was falling back to loadSubdirectoryModuleMaps when it couldn't
find ModuleName in (proper) search paths. This was causing iteration over all
files in the search path subdirectories for example "/usr/include/foobar" in
bugzilla case.

Users don't expect Clang to load modulemaps in subdirectories implicitly, and
also the disk access is not cheap.

if (ModMap.getLangOpts().ObjC1) is because I heard that this
subdirectory autoloading was supposed to happen only with ObjC.


https://reviews.llvm.org/D48367

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -282,7 +282,8 @@
 
 // Load all module maps in the immediate subdirectories of this search
 // directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+if (ModMap.getLangOpts().ObjC1)
+  loadSubdirectoryModuleMaps(SearchDirs[Idx]);
 
 // Look again for the module.
 Module = ModMap.findModule(ModuleName);
Index: clang/include/clang/Lex/ModuleMap.h
===
--- clang/include/clang/Lex/ModuleMap.h
+++ clang/include/clang/Lex/ModuleMap.h
@@ -110,6 +110,10 @@
   llvm::StringMap> PendingLinkAsModule;
 
 public:
+  const LangOptions getLangOpts() {
+return LangOpts;
+  }
+
   /// Use PendingLinkAsModule information to mark top level link names that
   /// are going to be replaced by export_as aliases.
   void resolveLinkAsDependencies(Module *Mod);


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -282,7 +282,8 @@
 
 // Load all module maps in the immediate subdirectories of this search
 // directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+if (ModMap.getLangOpts().ObjC1)
+  loadSubdirectoryModuleMaps(SearchDirs[Idx]);
 
 // Look again for the module.
 Module = ModMap.findModule(ModuleName);
Index: clang/include/clang/Lex/ModuleMap.h
===
--- clang/include/clang/Lex/ModuleMap.h
+++ clang/include/clang/Lex/ModuleMap.h
@@ -110,6 +110,10 @@
   llvm::StringMap> PendingLinkAsModule;
 
 public:
+  const LangOptions getLangOpts() {
+return LangOpts;
+  }
+
   /// Use PendingLinkAsModule information to mark top level link names that
   /// are going to be replaced by export_as aliases.
   void resolveLinkAsDependencies(Module *Mod);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48367: [modules] Fix 37878; Autoload subdirectory modulemaps with specific LangOpts

2018-06-20 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 152086.
yamaguchi added a comment.

Update commmit message and comment, add ObjC2


https://reviews.llvm.org/D48367

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -282,7 +282,8 @@
 
 // Load all module maps in the immediate subdirectories of this search
 // directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+if (ModMap.getLangOpts().ObjC1 || ModMap.getLangOpts().ObjC2)
+  loadSubdirectoryModuleMaps(SearchDirs[Idx]);
 
 // Look again for the module.
 Module = ModMap.findModule(ModuleName);
Index: clang/include/clang/Lex/ModuleMap.h
===
--- clang/include/clang/Lex/ModuleMap.h
+++ clang/include/clang/Lex/ModuleMap.h
@@ -110,6 +110,11 @@
   llvm::StringMap> PendingLinkAsModule;
 
 public:
+  /// Get LangOpts of ModuleMap
+  const LangOptions& getLangOpts() {
+return LangOpts;
+  }
+
   /// Use PendingLinkAsModule information to mark top level link names that
   /// are going to be replaced by export_as aliases.
   void resolveLinkAsDependencies(Module *Mod);


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -282,7 +282,8 @@
 
 // Load all module maps in the immediate subdirectories of this search
 // directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+if (ModMap.getLangOpts().ObjC1 || ModMap.getLangOpts().ObjC2)
+  loadSubdirectoryModuleMaps(SearchDirs[Idx]);
 
 // Look again for the module.
 Module = ModMap.findModule(ModuleName);
Index: clang/include/clang/Lex/ModuleMap.h
===
--- clang/include/clang/Lex/ModuleMap.h
+++ clang/include/clang/Lex/ModuleMap.h
@@ -110,6 +110,11 @@
   llvm::StringMap> PendingLinkAsModule;
 
 public:
+  /// Get LangOpts of ModuleMap
+  const LangOptions& getLangOpts() {
+return LangOpts;
+  }
+
   /// Use PendingLinkAsModule information to mark top level link names that
   /// are going to be replaced by export_as aliases.
   void resolveLinkAsDependencies(Module *Mod);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48367: [modules] Fix 37878; Autoload subdirectory modulemaps with specific LangOpts

2018-06-21 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 152240.
yamaguchi added a comment.

Add a test case


https://reviews.llvm.org/D48367

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/Modules/Inputs/autoload-subdirectory/a.h
  clang/test/Modules/Inputs/autoload-subdirectory/b.h
  clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
  clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
  clang/test/Modules/autoload-subdirectory.cpp


Index: clang/test/Modules/autoload-subdirectory.cpp
===
--- /dev/null
+++ clang/test/Modules/autoload-subdirectory.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang -fmodules -fmodule-name=Foo -I %S/Inputs/autoload-subdirectory/ 
%s
+
+#include "a.h"
+
+int main() {
+  foo neko;
+  return 0;
+}
Index: clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
@@ -0,0 +1,2 @@
+module a { header "a.h" }
+module b { header "b.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
@@ -0,0 +1,2 @@
+module a { header "a.h" }
+module b { header "b.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/b.h
@@ -0,0 +1 @@
+class bar {};
Index: clang/test/Modules/Inputs/autoload-subdirectory/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/a.h
@@ -0,0 +1,8 @@
+#include "b.h"
+
+class foo {
+  int x,y;
+  public:
+foo() {};
+~foo() {};
+};
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -282,7 +282,8 @@
 
 // Load all module maps in the immediate subdirectories of this search
 // directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+if (ModMap.getLangOpts().ObjC1 || ModMap.getLangOpts().ObjC2)
+  loadSubdirectoryModuleMaps(SearchDirs[Idx]);
 
 // Look again for the module.
 Module = ModMap.findModule(ModuleName);
Index: clang/include/clang/Lex/ModuleMap.h
===
--- clang/include/clang/Lex/ModuleMap.h
+++ clang/include/clang/Lex/ModuleMap.h
@@ -110,6 +110,11 @@
   llvm::StringMap> PendingLinkAsModule;
 
 public:
+  /// Get LangOpts of ModuleMap
+  const LangOptions& getLangOpts() {
+return LangOpts;
+  }
+
   /// Use PendingLinkAsModule information to mark top level link names that
   /// are going to be replaced by export_as aliases.
   void resolveLinkAsDependencies(Module *Mod);


Index: clang/test/Modules/autoload-subdirectory.cpp
===
--- /dev/null
+++ clang/test/Modules/autoload-subdirectory.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang -fmodules -fmodule-name=Foo -I %S/Inputs/autoload-subdirectory/ %s
+
+#include "a.h"
+
+int main() {
+  foo neko;
+  return 0;
+}
Index: clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
@@ -0,0 +1,2 @@
+module a { header "a.h" }
+module b { header "b.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
@@ -0,0 +1,2 @@
+module a { header "a.h" }
+module b { header "b.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/b.h
@@ -0,0 +1 @@
+class bar {};
Index: clang/test/Modules/Inputs/autoload-subdirectory/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/a.h
@@ -0,0 +1,8 @@
+#include "b.h"
+
+class foo {
+  int x,y;
+  public:
+foo() {};
+~foo() {};
+};
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -282,7 +282,8 @@
 
 // Load all module maps in the immediate subdirectories of this search
 // directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+if (ModMap.getLangOpts().ObjC1 || ModMap.getLangOpts().ObjC2)
+  loadSubdirectoryModuleMaps(SearchDirs[

[PATCH] D48367: [modules] Fix 37878; Autoload subdirectory modulemaps with specific LangOpts

2018-06-21 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: clang/lib/Lex/HeaderSearch.cpp:285
 // directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+if (ModMap.getLangOpts().ObjC1 || ModMap.getLangOpts().ObjC2)
+  loadSubdirectoryModuleMaps(SearchDirs[Idx]);

bruno wrote:
> aprantl wrote:
> > Are these flags also enabled in Objective-C++ mode?
> Looks like all this logic was introduced in r177621 to allow the names of 
> modules to differ from the name of their subdirectory in the include path.
> 
> Instead of having this to be based on the language, it's probably better if 
> we have it based on @import name lookup, which is the scenario where we 
> actually currently look more aggressively, did you try that path?
> 
> This is also lacking a testcase, can you create one?
> Are these flags also enabled in Objective-C++ mode?
I think so from FrontendOptions.h:190
`bool isObjectiveC() const { return Lang == ObjC || Lang == ObjCXX; }`

> it's probably better if we have it based on @import name lookup
I don't think I understood what you're saying, could you explain a bit more?

> This is also lacking a testcase, can you create one?
Sure!


https://reviews.llvm.org/D48367



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


[PATCH] D53589: [bash-autocompletion] Fix bug when a flag ends with '='

2018-10-23 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added reviewers: teemperor, ruiu.

There was a bug that when a flag ends with '=' and no value was suggested,
clang autocompletes the flag itself.
For example, in bash, it looked like this:

  $ clang -fmodule-file=[tab]
  -> $clang -fmodule-file=-fmodule-file

This is not what we expect. We expect a file autocompletion when no value
was found. With this patch, pressing tab suggests files in the current
directory.


https://reviews.llvm.org/D53589

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/autocomplete.c


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -115,3 +115,9 @@
 // Check if they can autocomplete values with coron
 // RUN: %clang --autocomplete=foo,bar,,,-fno-sanitize-coverage=,f | FileCheck 
%s -check-prefix=FNOSANICOVER-CORON
 // FNOSANICOVER-CORON: func
+
+// Clang should return empty string when no value completion was found, which 
will fall back to file autocompletion
+// RUN: %clang --autocomplete=-fmodule-file= | FileCheck %s 
-check-prefix=MODULE_FILE_EQUAL
+// MODULE_FILE_EQUAL-NOT: -fmodule-file=
+// RUN: %clang --autocomplete=-fmodule-file | FileCheck %s 
-check-prefix=MODULE_FILE
+// MODULE_FILE: -fmodule-file=
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1534,7 +1534,9 @@
   if (SuggestedCompletions.empty())
 SuggestedCompletions = Opts->suggestValueCompletions(Cur, "");
 
-  if (SuggestedCompletions.empty()) {
+  // When flag ends with '=' and there was no value completion, return empty
+  // string and fall back to the file autocompletion.
+  if (SuggestedCompletions.empty() && !Cur.endswith("=")) {
 // If the flag is in the form of "--autocomplete=-foo",
 // we were requested to print out all option names that start with "-foo".
 // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -115,3 +115,9 @@
 // Check if they can autocomplete values with coron
 // RUN: %clang --autocomplete=foo,bar,,,-fno-sanitize-coverage=,f | FileCheck %s -check-prefix=FNOSANICOVER-CORON
 // FNOSANICOVER-CORON: func
+
+// Clang should return empty string when no value completion was found, which will fall back to file autocompletion
+// RUN: %clang --autocomplete=-fmodule-file= | FileCheck %s -check-prefix=MODULE_FILE_EQUAL
+// MODULE_FILE_EQUAL-NOT: -fmodule-file=
+// RUN: %clang --autocomplete=-fmodule-file | FileCheck %s -check-prefix=MODULE_FILE
+// MODULE_FILE: -fmodule-file=
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1534,7 +1534,9 @@
   if (SuggestedCompletions.empty())
 SuggestedCompletions = Opts->suggestValueCompletions(Cur, "");
 
-  if (SuggestedCompletions.empty()) {
+  // When flag ends with '=' and there was no value completion, return empty
+  // string and fall back to the file autocompletion.
+  if (SuggestedCompletions.empty() && !Cur.endswith("=")) {
 // If the flag is in the form of "--autocomplete=-foo",
 // we were requested to print out all option names that start with "-foo".
 // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53639: [autocompletion] Handle the space before pressing tab

2018-10-24 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added reviewers: teemperor, ruiu.

Distinguish "--autocomplete=-someflag" and "--autocomplete=-someflag,"
because the latter indicates that the user put space before pushing tab
which should end up in a file completion.


https://reviews.llvm.org/D53639

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/autocomplete.c


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -121,3 +121,8 @@
 // MODULE_FILE_EQUAL-NOT: -fmodule-file=
 // RUN: %clang --autocomplete=-fmodule-file | FileCheck %s 
-check-prefix=MODULE_FILE
 // MODULE_FILE: -fmodule-file=
+
+// RUN: %clang --autocomplete=-Qunused-arguments, | FileCheck %s 
-check-prefix=QUNUSED_COMMA
+// QUNUSED_COMMA-NOT: -Qunused-arguments
+// RUN: %clang --autocomplete=-Qunused-arguments | FileCheck %s 
-check-prefix=QUNUSED
+// QUNUSED: -Qunused-arguments
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1508,6 +1508,13 @@
   unsigned short DisableFlags =
   options::NoDriverOption | options::Unsupported | options::Ignored;
 
+  // Distinguish "--autocomplete=-someflag" and "--autocomplete=-someflag,"
+  // because the latter indicates that the user put space before pushing tab
+  // which should end up in a file completion.
+  bool HasSpace = false;
+  if (PassedFlags.endswith(","))
+HasSpace = true;
+
   // Parse PassedFlags by "," as all the command-line flags are passed to this
   // function separated by ","
   StringRef TargetFlags = PassedFlags;
@@ -1525,6 +1532,14 @@
 
   StringRef Cur;
   Cur = Flags.at(Flags.size() - 1);
+
+  // If Flags were empty, it means the user typed `clang [tab]` where we should
+  // list all possible flags.
+  if (HasSpace && !Flags.empty()) {
+llvm::outs() << '\n';
+return;
+  }
+
   StringRef Prev;
   if (Flags.size() >= 2) {
 Prev = Flags.at(Flags.size() - 2);


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -121,3 +121,8 @@
 // MODULE_FILE_EQUAL-NOT: -fmodule-file=
 // RUN: %clang --autocomplete=-fmodule-file | FileCheck %s -check-prefix=MODULE_FILE
 // MODULE_FILE: -fmodule-file=
+
+// RUN: %clang --autocomplete=-Qunused-arguments, | FileCheck %s -check-prefix=QUNUSED_COMMA
+// QUNUSED_COMMA-NOT: -Qunused-arguments
+// RUN: %clang --autocomplete=-Qunused-arguments | FileCheck %s -check-prefix=QUNUSED
+// QUNUSED: -Qunused-arguments
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1508,6 +1508,13 @@
   unsigned short DisableFlags =
   options::NoDriverOption | options::Unsupported | options::Ignored;
 
+  // Distinguish "--autocomplete=-someflag" and "--autocomplete=-someflag,"
+  // because the latter indicates that the user put space before pushing tab
+  // which should end up in a file completion.
+  bool HasSpace = false;
+  if (PassedFlags.endswith(","))
+HasSpace = true;
+
   // Parse PassedFlags by "," as all the command-line flags are passed to this
   // function separated by ","
   StringRef TargetFlags = PassedFlags;
@@ -1525,6 +1532,14 @@
 
   StringRef Cur;
   Cur = Flags.at(Flags.size() - 1);
+
+  // If Flags were empty, it means the user typed `clang [tab]` where we should
+  // list all possible flags.
+  if (HasSpace && !Flags.empty()) {
+llvm::outs() << '\n';
+return;
+  }
+
   StringRef Prev;
   if (Flags.size() >= 2) {
 Prev = Flags.at(Flags.size() - 2);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53639: [autocompletion] Handle the space before pressing tab

2018-10-24 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 170849.
yamaguchi added a comment.

Updated HasSpace, added comments, fixed typo in the commit message


https://reviews.llvm.org/D53639

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/autocomplete.c


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -25,6 +25,7 @@
 // STDLIBALL-NEXT: platform
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
+// RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
 // RUN: %clang --autocomplete=-meabi | FileCheck %s -check-prefix=MEABIALL
 // MEABIALL: 4
 // MEABIALL-NEXT: 5
@@ -121,3 +122,8 @@
 // MODULE_FILE_EQUAL-NOT: -fmodule-file=
 // RUN: %clang --autocomplete=-fmodule-file | FileCheck %s 
-check-prefix=MODULE_FILE
 // MODULE_FILE: -fmodule-file=
+
+// RUN: %clang --autocomplete=-Qunused-arguments, | FileCheck %s 
-check-prefix=QUNUSED_COMMA
+// QUNUSED_COMMA-NOT: -Qunused-arguments
+// RUN: %clang --autocomplete=-Qunused-arguments | FileCheck %s 
-check-prefix=QUNUSED
+// QUNUSED: -Qunused-arguments
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1508,6 +1508,11 @@
   unsigned short DisableFlags =
   options::NoDriverOption | options::Unsupported | options::Ignored;
 
+  // Distinguish "--autocomplete=-someflag" and "--autocomplete=-someflag,"
+  // because the latter indicates that the user put space before pushing tab
+  // which should end up in a file completion.
+  const bool HasSpace = PassedFlags.endswith(",");
+
   // Parse PassedFlags by "," as all the command-line flags are passed to this
   // function separated by ","
   StringRef TargetFlags = PassedFlags;
@@ -1534,6 +1539,16 @@
   if (SuggestedCompletions.empty())
 SuggestedCompletions = Opts->suggestValueCompletions(Cur, "");
 
+  // If Flags were empty, it means the user typed `clang [tab]` where we should
+  // list all possible flags. If there was no value completion and the user
+  // pressed tab after a space, we should fall back to a file completion.
+  // Printing a newline is to be consistent with what we print at the end of
+  // this function.
+  if (SuggestedCompletions.empty() && HasSpace && !Flags.empty()) {
+llvm::outs() << '\n';
+return;
+  }
+
   // When flag ends with '=' and there was no value completion, return empty
   // string and fall back to the file autocompletion.
   if (SuggestedCompletions.empty() && !Cur.endswith("=")) {


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -25,6 +25,7 @@
 // STDLIBALL-NEXT: platform
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
+// RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
 // RUN: %clang --autocomplete=-meabi | FileCheck %s -check-prefix=MEABIALL
 // MEABIALL: 4
 // MEABIALL-NEXT: 5
@@ -121,3 +122,8 @@
 // MODULE_FILE_EQUAL-NOT: -fmodule-file=
 // RUN: %clang --autocomplete=-fmodule-file | FileCheck %s -check-prefix=MODULE_FILE
 // MODULE_FILE: -fmodule-file=
+
+// RUN: %clang --autocomplete=-Qunused-arguments, | FileCheck %s -check-prefix=QUNUSED_COMMA
+// QUNUSED_COMMA-NOT: -Qunused-arguments
+// RUN: %clang --autocomplete=-Qunused-arguments | FileCheck %s -check-prefix=QUNUSED
+// QUNUSED: -Qunused-arguments
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1508,6 +1508,11 @@
   unsigned short DisableFlags =
   options::NoDriverOption | options::Unsupported | options::Ignored;
 
+  // Distinguish "--autocomplete=-someflag" and "--autocomplete=-someflag,"
+  // because the latter indicates that the user put space before pushing tab
+  // which should end up in a file completion.
+  const bool HasSpace = PassedFlags.endswith(",");
+
   // Parse PassedFlags by "," as all the command-line flags are passed to this
   // function separated by ","
   StringRef TargetFlags = PassedFlags;
@@ -1534,6 +1539,16 @@
   if (SuggestedCompletions.empty())
 SuggestedCompletions = Opts->suggestValueCompletions(Cur, "");
 
+  // If Flags were empty, it means the user typed `clang [tab]` where we should
+  // list all possible flags. If there was no value completion and the user
+  // pressed tab after a space, we should fall back to a file completion.
+  // Printing a newline is to be consistent with what we print at the end of
+  // this function.
+  if (SuggestedCompletions.empty() && HasSpace && !Flags.empty()) {
+llvm::outs() << '\n';
+return;
+  }
+
   // When flag ends with '=' and there was no value completion, return empt

[PATCH] D53639: [autocompletion] Handle the space before pressing tab

2018-10-24 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL345133: [autocompletion] Handle the space before pressing 
tab (authored by yamaguchi, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D53639?vs=170849&id=170857#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53639

Files:
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/test/Driver/autocomplete.c


Index: cfe/trunk/test/Driver/autocomplete.c
===
--- cfe/trunk/test/Driver/autocomplete.c
+++ cfe/trunk/test/Driver/autocomplete.c
@@ -25,6 +25,7 @@
 // STDLIBALL-NEXT: platform
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
+// RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
 // RUN: %clang --autocomplete=-meabi | FileCheck %s -check-prefix=MEABIALL
 // MEABIALL: 4
 // MEABIALL-NEXT: 5
@@ -121,3 +122,8 @@
 // MODULE_FILE_EQUAL-NOT: -fmodule-file=
 // RUN: %clang --autocomplete=-fmodule-file | FileCheck %s 
-check-prefix=MODULE_FILE
 // MODULE_FILE: -fmodule-file=
+
+// RUN: %clang --autocomplete=-Qunused-arguments, | FileCheck %s 
-check-prefix=QUNUSED_COMMA
+// QUNUSED_COMMA-NOT: -Qunused-arguments
+// RUN: %clang --autocomplete=-Qunused-arguments | FileCheck %s 
-check-prefix=QUNUSED
+// QUNUSED: -Qunused-arguments
Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -1508,6 +1508,11 @@
   unsigned short DisableFlags =
   options::NoDriverOption | options::Unsupported | options::Ignored;
 
+  // Distinguish "--autocomplete=-someflag" and "--autocomplete=-someflag,"
+  // because the latter indicates that the user put space before pushing tab
+  // which should end up in a file completion.
+  const bool HasSpace = PassedFlags.endswith(",");
+
   // Parse PassedFlags by "," as all the command-line flags are passed to this
   // function separated by ","
   StringRef TargetFlags = PassedFlags;
@@ -1534,6 +1539,16 @@
   if (SuggestedCompletions.empty())
 SuggestedCompletions = Opts->suggestValueCompletions(Cur, "");
 
+  // If Flags were empty, it means the user typed `clang [tab]` where we should
+  // list all possible flags. If there was no value completion and the user
+  // pressed tab after a space, we should fall back to a file completion.
+  // We're printing a newline to be consistent with what we print at the end of
+  // this function.
+  if (SuggestedCompletions.empty() && HasSpace && !Flags.empty()) {
+llvm::outs() << '\n';
+return;
+  }
+
   // When flag ends with '=' and there was no value completion, return empty
   // string and fall back to the file autocompletion.
   if (SuggestedCompletions.empty() && !Cur.endswith("=")) {


Index: cfe/trunk/test/Driver/autocomplete.c
===
--- cfe/trunk/test/Driver/autocomplete.c
+++ cfe/trunk/test/Driver/autocomplete.c
@@ -25,6 +25,7 @@
 // STDLIBALL-NEXT: platform
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
+// RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
 // RUN: %clang --autocomplete=-meabi | FileCheck %s -check-prefix=MEABIALL
 // MEABIALL: 4
 // MEABIALL-NEXT: 5
@@ -121,3 +122,8 @@
 // MODULE_FILE_EQUAL-NOT: -fmodule-file=
 // RUN: %clang --autocomplete=-fmodule-file | FileCheck %s -check-prefix=MODULE_FILE
 // MODULE_FILE: -fmodule-file=
+
+// RUN: %clang --autocomplete=-Qunused-arguments, | FileCheck %s -check-prefix=QUNUSED_COMMA
+// QUNUSED_COMMA-NOT: -Qunused-arguments
+// RUN: %clang --autocomplete=-Qunused-arguments | FileCheck %s -check-prefix=QUNUSED
+// QUNUSED: -Qunused-arguments
Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -1508,6 +1508,11 @@
   unsigned short DisableFlags =
   options::NoDriverOption | options::Unsupported | options::Ignored;
 
+  // Distinguish "--autocomplete=-someflag" and "--autocomplete=-someflag,"
+  // because the latter indicates that the user put space before pushing tab
+  // which should end up in a file completion.
+  const bool HasSpace = PassedFlags.endswith(",");
+
   // Parse PassedFlags by "," as all the command-line flags are passed to this
   // function separated by ","
   StringRef TargetFlags = PassedFlags;
@@ -1534,6 +1539,16 @@
   if (SuggestedCompletions.empty())
 SuggestedCompletions = Opts->suggestValueCompletions(Cur, "");
 
+  // If Flags were empty, it means the user typed `clang [tab]` where we should
+  // list all possible flags. If there was no value completion and the user
+  // pressed tab after a space, we should fall back to a file completion.
+  // We're printing a newline t

[PATCH] D53639: [autocompletion] Handle the space before pressing tab

2018-10-24 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC345133: [autocompletion] Handle the space before pressing 
tab (authored by yamaguchi, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53639?vs=170849&id=170856#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53639

Files:
  lib/Driver/Driver.cpp
  test/Driver/autocomplete.c


Index: test/Driver/autocomplete.c
===
--- test/Driver/autocomplete.c
+++ test/Driver/autocomplete.c
@@ -25,6 +25,7 @@
 // STDLIBALL-NEXT: platform
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
+// RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
 // RUN: %clang --autocomplete=-meabi | FileCheck %s -check-prefix=MEABIALL
 // MEABIALL: 4
 // MEABIALL-NEXT: 5
@@ -121,3 +122,8 @@
 // MODULE_FILE_EQUAL-NOT: -fmodule-file=
 // RUN: %clang --autocomplete=-fmodule-file | FileCheck %s 
-check-prefix=MODULE_FILE
 // MODULE_FILE: -fmodule-file=
+
+// RUN: %clang --autocomplete=-Qunused-arguments, | FileCheck %s 
-check-prefix=QUNUSED_COMMA
+// QUNUSED_COMMA-NOT: -Qunused-arguments
+// RUN: %clang --autocomplete=-Qunused-arguments | FileCheck %s 
-check-prefix=QUNUSED
+// QUNUSED: -Qunused-arguments
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -1508,6 +1508,11 @@
   unsigned short DisableFlags =
   options::NoDriverOption | options::Unsupported | options::Ignored;
 
+  // Distinguish "--autocomplete=-someflag" and "--autocomplete=-someflag,"
+  // because the latter indicates that the user put space before pushing tab
+  // which should end up in a file completion.
+  const bool HasSpace = PassedFlags.endswith(",");
+
   // Parse PassedFlags by "," as all the command-line flags are passed to this
   // function separated by ","
   StringRef TargetFlags = PassedFlags;
@@ -1534,6 +1539,16 @@
   if (SuggestedCompletions.empty())
 SuggestedCompletions = Opts->suggestValueCompletions(Cur, "");
 
+  // If Flags were empty, it means the user typed `clang [tab]` where we should
+  // list all possible flags. If there was no value completion and the user
+  // pressed tab after a space, we should fall back to a file completion.
+  // We're printing a newline to be consistent with what we print at the end of
+  // this function.
+  if (SuggestedCompletions.empty() && HasSpace && !Flags.empty()) {
+llvm::outs() << '\n';
+return;
+  }
+
   // When flag ends with '=' and there was no value completion, return empty
   // string and fall back to the file autocompletion.
   if (SuggestedCompletions.empty() && !Cur.endswith("=")) {


Index: test/Driver/autocomplete.c
===
--- test/Driver/autocomplete.c
+++ test/Driver/autocomplete.c
@@ -25,6 +25,7 @@
 // STDLIBALL-NEXT: platform
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
+// RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
 // RUN: %clang --autocomplete=-meabi | FileCheck %s -check-prefix=MEABIALL
 // MEABIALL: 4
 // MEABIALL-NEXT: 5
@@ -121,3 +122,8 @@
 // MODULE_FILE_EQUAL-NOT: -fmodule-file=
 // RUN: %clang --autocomplete=-fmodule-file | FileCheck %s -check-prefix=MODULE_FILE
 // MODULE_FILE: -fmodule-file=
+
+// RUN: %clang --autocomplete=-Qunused-arguments, | FileCheck %s -check-prefix=QUNUSED_COMMA
+// QUNUSED_COMMA-NOT: -Qunused-arguments
+// RUN: %clang --autocomplete=-Qunused-arguments | FileCheck %s -check-prefix=QUNUSED
+// QUNUSED: -Qunused-arguments
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -1508,6 +1508,11 @@
   unsigned short DisableFlags =
   options::NoDriverOption | options::Unsupported | options::Ignored;
 
+  // Distinguish "--autocomplete=-someflag" and "--autocomplete=-someflag,"
+  // because the latter indicates that the user put space before pushing tab
+  // which should end up in a file completion.
+  const bool HasSpace = PassedFlags.endswith(",");
+
   // Parse PassedFlags by "," as all the command-line flags are passed to this
   // function separated by ","
   StringRef TargetFlags = PassedFlags;
@@ -1534,6 +1539,16 @@
   if (SuggestedCompletions.empty())
 SuggestedCompletions = Opts->suggestValueCompletions(Cur, "");
 
+  // If Flags were empty, it means the user typed `clang [tab]` where we should
+  // list all possible flags. If there was no value completion and the user
+  // pressed tab after a space, we should fall back to a file completion.
+  // We're printing a newline to be consistent with what we print at the end of
+  // this function.
+  if (SuggestedCompletions.empty() && HasSpace && !Flags.empty()) {
+llvm::outs() << '\n';
+return;
+ 

[PATCH] D53589: [bash-autocompletion] Fix bug when a flag ends with '='

2018-10-24 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi closed this revision.
yamaguchi added a comment.

Landed in https://reviews.llvm.org/rL345121


https://reviews.llvm.org/D53589



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


[PATCH] D54097: Save memory in ASTReader by using DenseMap instead of vector

2018-11-05 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added a reviewer: rsmith.

ReadASTBlock was allocating extra memory by resizing vector for all
record decls, and half of them stayed nullptr without being loaded. For
us this part was crucial and this patch had large amount of memory
improvement.

About clang performance regression, I run whole clang test 5 times
with and without this patch and took average:
Without patch: 239.434003
With patch : 238.862
So I think this doesn't cause cpu time regression.


https://reviews.llvm.org/D54097

Files:
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp

Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -2748,8 +2748,9 @@
 /// so that future GetDecl calls will return this declaration rather
 /// than trying to load a new declaration.
 inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
-  assert(!DeclsLoaded[Index] && "Decl loaded twice?");
-  DeclsLoaded[Index] = D;
+  assert((DeclsLoaded.find(Index) == DeclsLoaded.end()) &&
+ "Decl loaded twice?");
+  DeclsLoaded.insert({Index, D});
 }
 
 /// Determine whether the consumer will be interested in seeing
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2834,7 +2834,7 @@
   std::make_pair(LocalBaseTypeIndex,
  F.BaseTypeIndex - LocalBaseTypeIndex));
 
-TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes);
+NumTypes += F.LocalNumTypes;
   }
   break;
 }
@@ -2864,7 +2864,7 @@
 // module.
 F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID;
 
-DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls);
+NumDecls += F.LocalNumDecls;
   }
   break;
 }
@@ -3425,7 +3425,7 @@
   std::make_pair(LocalBaseMacroID,
  F.BaseMacroID - LocalBaseMacroID));
 
-MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros);
+NumMacros += F.LocalNumMacros;
   }
   break;
 }
@@ -7000,19 +7000,19 @@
   }
 
   Index -= NUM_PREDEF_TYPE_IDS;
-  assert(Index < TypesLoaded.size() && "Type index out-of-range");
-  if (TypesLoaded[Index].isNull()) {
-TypesLoaded[Index] = readTypeRecord(Index);
-if (TypesLoaded[Index].isNull())
+  assert(Index < NumTypes && "Type index out-of-range");
+  if (TypesLoaded.find(Index) == TypesLoaded.end()) {
+QualType QualTy = readTypeRecord(Index);
+TypesLoaded.insert({Index, QualTy});
+if (TypesLoaded.find(Index) == TypesLoaded.end())
   return QualType();
 
-TypesLoaded[Index]->setFromAST();
+QualTy->setFromAST();
 if (DeserializationListener)
-  DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID),
-TypesLoaded[Index]);
+  DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), QualTy);
   }
 
-  return TypesLoaded[Index].withFastQualifiers(FastQuals);
+  return TypesLoaded.find(Index)->second.withFastQualifiers(FastQuals);
 }
 
 QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) {
@@ -7241,13 +7241,14 @@
 
   unsigned Index = ID - NUM_PREDEF_DECL_IDS;
 
-  if (Index > DeclsLoaded.size()) {
+  if (Index > NumDecls) {
 Error("declaration ID out-of-range for AST file");
 return SourceLocation();
   }
 
-  if (Decl *D = DeclsLoaded[Index])
-return D->getLocation();
+  auto FindRes = DeclsLoaded.find(Index);
+  if (FindRes != DeclsLoaded.end())
+return FindRes->second->getLocation();
 
   SourceLocation Loc;
   DeclCursorForID(ID, Loc);
@@ -7326,34 +7327,38 @@
 
   unsigned Index = ID - NUM_PREDEF_DECL_IDS;
 
-  if (Index >= DeclsLoaded.size()) {
+  if (Index >= NumDecls) {
 assert(0 && "declaration ID out-of-range for AST file");
 Error("declaration ID out-of-range for AST file");
 return nullptr;
   }
 
-  return DeclsLoaded[Index];
+  auto FindRes = DeclsLoaded.find(Index);
+  if (FindRes == DeclsLoaded.end())
+return nullptr;
+
+  return FindRes->second;
 }
 
 Decl *ASTReader::GetDecl(DeclID ID) {
   if (ID < NUM_PREDEF_DECL_IDS)
 return GetExistingDecl(ID);
 
   unsigned Index = ID - NUM_PREDEF_DECL_IDS;
 
-  if (Index >= DeclsLoaded.size()) {
+  if (Index >= NumDecls) {
 assert(0 && "declaration ID out-of-range for AST file");
 Error("declaration ID out-of-range for AST file");
 return nullptr;
   }
 
-  if (!DeclsLoaded[Index]) {
+  if (DeclsLoaded.find(Index) == DeclsLoaded.end()) {
 ReadDeclRecord(ID);
 if (DeserializationListener)
-  DeserializationListener->DeclRead(ID, DeclsLoaded[Index]);
+  DeserializationListener->DeclRead(ID, DeclsLoaded.find(Index)->second);
   }
 
-  ret

[PATCH] D54097: Save memory in ASTReader by using DenseMap instead of vector

2018-11-05 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added a comment.

FYI, raw benchmarking data:
https://gist.github.com/yamaguchi1024/4f28406f51b413129cc762365fdd76c8
https://gist.github.com/yamaguchi1024/318b30db03adb10b7b230b706012a14c


https://reviews.llvm.org/D54097



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


[PATCH] D52513: [Modules] Do not emit file modification error when -fno-validate-pch is set

2018-09-25 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added reviewers: rsmith, v.g.vassilev.

This is a follow-up patch of
https://reviews.llvm.org/rL338503: [Modules] Do not emit relocation error when 
-fno-validate-pch is set

File modification with modules is also fine for our usecase as we
want to reuse pcms. This enables us to use the same build directory
again without deleting pcm directory.


https://reviews.llvm.org/D52513

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Modules/module-file-novalidate.c


Index: clang/test/Modules/module-file-novalidate.c
===
--- /dev/null
+++ clang/test/Modules/module-file-novalidate.c
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo 'int foo = 0;' > %t/a.h
+// RUN: echo 'module A { header "a.h" }' > %t/m.modulemap
+// RUN: %clang_cc1 -fmodules -emit-module -fmodule-name=A -x c %t/m.modulemap 
-o %t/m.pcm
+// RUN: echo 'int bar;' > %t/a.h
+// RUN: not %clang_cc1 -fmodules -fmodule-file=%t/m.pcm 
-fmodule-map-file=%t/m.modulemap -fno-validate-pch -x c %s -I%t -fsyntax-only 
2>&1 | FileCheck %s
+#include "a.h"
+int foo = 0; // redefinition of 'foo'
+// CHECK-NOT: fatal error: file {{.*}} has been modified since the module file 
{{.*}} was built
+// REQUIRES: shell
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2175,7 +2175,8 @@
   bool IsOutOfDate = false;
 
   // For an overridden file, there is nothing to validate.
-  if (!Overridden && //
+  // Don't emit file modification error if we have -fno-validate-pch
+  if (!Overridden && !PP.getPreprocessorOpts().DisablePCHValidation &&
   (StoredSize != File->getSize() ||
(StoredTime && StoredTime != File->getModificationTime() &&
 !DisableValidation)


Index: clang/test/Modules/module-file-novalidate.c
===
--- /dev/null
+++ clang/test/Modules/module-file-novalidate.c
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo 'int foo = 0;' > %t/a.h
+// RUN: echo 'module A { header "a.h" }' > %t/m.modulemap
+// RUN: %clang_cc1 -fmodules -emit-module -fmodule-name=A -x c %t/m.modulemap -o %t/m.pcm
+// RUN: echo 'int bar;' > %t/a.h
+// RUN: not %clang_cc1 -fmodules -fmodule-file=%t/m.pcm -fmodule-map-file=%t/m.modulemap -fno-validate-pch -x c %s -I%t -fsyntax-only 2>&1 | FileCheck %s
+#include "a.h"
+int foo = 0; // redefinition of 'foo'
+// CHECK-NOT: fatal error: file {{.*}} has been modified since the module file {{.*}} was built
+// REQUIRES: shell
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2175,7 +2175,8 @@
   bool IsOutOfDate = false;
 
   // For an overridden file, there is nothing to validate.
-  if (!Overridden && //
+  // Don't emit file modification error if we have -fno-validate-pch
+  if (!Overridden && !PP.getPreprocessorOpts().DisablePCHValidation &&
   (StoredSize != File->getSize() ||
(StoredTime && StoredTime != File->getModificationTime() &&
 !DisableValidation)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37203: [Bash-autocompletion] Follow up patch for D36782

2017-08-28 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

https://reviews.llvm.org/D36782 broke lld buildbots, because I've changed 
OptionInfo's type
from ArrayRef to std::vector, so it became a copy, not a reference.
In this patch, I changed Table to static, so that it won't be freed
after the return. However, I'm not sure if this is Ok for lld, because
it requires this function to be called atomic.


https://reviews.llvm.org/D37203

Files:
  lld/COFF/DriverUtils.cpp


Index: lld/COFF/DriverUtils.cpp
===
--- lld/COFF/DriverUtils.cpp
+++ lld/COFF/DriverUtils.cpp
@@ -727,7 +727,7 @@
   std::vector Argv = replaceResponseFiles(ArgsArr);
 
   // Make InputArgList from string vectors.
-  COFFOptTable Table;
+  static COFFOptTable Table;
   unsigned MissingIndex;
   unsigned MissingCount;
   opt::InputArgList Args = Table.ParseArgs(Argv, MissingIndex, MissingCount);


Index: lld/COFF/DriverUtils.cpp
===
--- lld/COFF/DriverUtils.cpp
+++ lld/COFF/DriverUtils.cpp
@@ -727,7 +727,7 @@
   std::vector Argv = replaceResponseFiles(ArgsArr);
 
   // Make InputArgList from string vectors.
-  COFFOptTable Table;
+  static COFFOptTable Table;
   unsigned MissingIndex;
   unsigned MissingCount;
   opt::InputArgList Args = Table.ParseArgs(Argv, MissingIndex, MissingCount);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36820: [Bash-autocompletion] Add support for -std=

2017-08-28 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL311971: [Bash-autocompletion] Add support for -std= 
(authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D36820?vs=111804&id=113009#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36820

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/test/Driver/autocomplete.c
  llvm/trunk/utils/TableGen/OptParserEmitter.cpp


Index: llvm/trunk/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/trunk/utils/TableGen/OptParserEmitter.cpp
+++ llvm/trunk/utils/TableGen/OptParserEmitter.cpp
@@ -308,11 +308,11 @@
 if (isa(R.getValueInit("ValuesCode")))
   continue;
 OS << "{\n";
+OS << "bool ValuesWereAdded;\n";
 OS << R.getValueAsString("ValuesCode");
 OS << "\n";
 for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
-  OS << "bool ValuesWereAdded = ";
-  OS << "Opt.addValues(";
+  OS << "ValuesWereAdded = Opt.addValues(";
   std::string S = (Pref + R.getValueAsString("Name")).str();
   write_cstring(OS, S);
   OS << ", Values);\n";
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -2270,7 +2270,14 @@
 def static : Flag<["-", "--"], "static">, Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
-  Group, HelpText<"Language standard to compile for">;
+  Group, HelpText<"Language standard to compile for">,
+  ValuesCode<[{
+const char *Values =
+#define LANGSTANDARD(id, name, lang, desc, features) name ","
+#define LANGSTANDARD_ALIAS(id, alias) alias ","
+#include "clang/Frontend/LangStandards.def"
+;
+  }]>;
 def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>,
   HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">;
 def sub__library : JoinedOrSeparate<["-"], "sub_library">;
Index: cfe/trunk/test/Driver/autocomplete.c
===
--- cfe/trunk/test/Driver/autocomplete.c
+++ cfe/trunk/test/Driver/autocomplete.c
@@ -95,3 +95,5 @@
 // NOWARNING: -Wno-invalid-pp-token
 // RUN: %clang --autocomplete=-analyzer-checker, | FileCheck %s 
-check-prefix=ANALYZER
 // ANALYZER: unix.Malloc
+// RUN: %clang --autocomplete=-std=, | FileCheck %s -check-prefix=STDVAL
+// STDVAL: c99


Index: llvm/trunk/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/trunk/utils/TableGen/OptParserEmitter.cpp
+++ llvm/trunk/utils/TableGen/OptParserEmitter.cpp
@@ -308,11 +308,11 @@
 if (isa(R.getValueInit("ValuesCode")))
   continue;
 OS << "{\n";
+OS << "bool ValuesWereAdded;\n";
 OS << R.getValueAsString("ValuesCode");
 OS << "\n";
 for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
-  OS << "bool ValuesWereAdded = ";
-  OS << "Opt.addValues(";
+  OS << "ValuesWereAdded = Opt.addValues(";
   std::string S = (Pref + R.getValueAsString("Name")).str();
   write_cstring(OS, S);
   OS << ", Values);\n";
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -2270,7 +2270,14 @@
 def static : Flag<["-", "--"], "static">, Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
-  Group, HelpText<"Language standard to compile for">;
+  Group, HelpText<"Language standard to compile for">,
+  ValuesCode<[{
+const char *Values =
+#define LANGSTANDARD(id, name, lang, desc, features) name ","
+#define LANGSTANDARD_ALIAS(id, alias) alias ","
+#include "clang/Frontend/LangStandards.def"
+;
+  }]>;
 def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>,
   HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">;
 def sub__library : JoinedOrSeparate<["-"], "sub_library">;
Index: cfe/trunk/test/Driver/autocomplete.c
===
--- cfe/trunk/test/Driver/autocomplete.c
+++ cfe/trunk/test/Driver/autocomplete.c
@@ -95,3 +95,5 @@
 // NOWARNING: -Wno-invalid-pp-token
 // RUN: %clang --autocomplete=-analyzer-checker, | FileCheck %s -check-prefix=ANALYZER
 // ANALYZER: unix.Malloc
+// RUN: %clang --autocomplete=-std=, | FileCheck %s -check-prefix=STDVAL
+// STDVAL: c99
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37203: [Bash-autocompletion] Follow up patch for D36782

2017-08-28 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi abandoned this revision.
yamaguchi added a comment.

https://reviews.llvm.org/D37217 has already landed, so we don't need this 
anymore.


https://reviews.llvm.org/D37203



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


[PATCH] D37249: [Bash-autocomplete] Refactor autocomplete code into own function

2017-08-28 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

We wrote many codes in HandleImediateArgs, so I've refactored it into
handleAutocompletions.


https://reviews.llvm.org/D37249

Files:
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp

Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1157,6 +1157,57 @@
 OS << i << ',' << DiagnosticIDs::getCategoryNameFromID(i) << '\n';
 }
 
+void Driver::handleAutocompletions(const llvm::opt::Arg *A) const {
+  // Print out all options that start with a given argument. This is used for
+  // shell autocompletion.
+  StringRef PassedFlags = A->getValue();
+  std::vector SuggestedCompletions;
+
+  unsigned short DisableFlags =
+  options::NoDriverOption | options::Unsupported | options::Ignored;
+  // We want to show cc1-only options only when clang is invoked as "clang
+  // -cc1".
+  // When clang is invoked as "clang -cc1", we add "#" to the beginning of an
+  // --autocomplete
+  // option so that the clang driver can distinguish whether it is requested to
+  // show cc1-only options or not.
+  if (PassedFlags[0] == '#') {
+DisableFlags &= ~options::NoDriverOption;
+PassedFlags = PassedFlags.substr(1);
+  }
+
+  if (PassedFlags.find(',') == StringRef::npos) {
+// If the flag is in the form of "--autocomplete=-foo",
+// we were requested to print out all option names that start with "-foo".
+// For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
+SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
+
+// We have to query the -W flags manually as they're not in the OptTable.
+// TODO: Find a good way to add them to OptTable instead and them remove
+// this code.
+for (StringRef S : DiagnosticIDs::getDiagnosticFlags())
+  if (S.startswith(PassedFlags))
+SuggestedCompletions.push_back(S);
+  } else {
+// If the flag is in the form of "--autocomplete=foo,bar", we were
+// requested to print out all option values for "-foo" that start with
+// "bar". For example,
+// "--autocomplete=-stdlib=,l" is expanded to "libc++" and "libstdc++".
+StringRef Option, Arg;
+std::tie(Option, Arg) = PassedFlags.split(',');
+SuggestedCompletions = Opts->suggestValueCompletions(Option, Arg);
+  }
+
+  // Sort the autocomplete candidates so that shells print them out in a
+  // deterministic order. We could sort in any way, but we chose
+  // case-insensitive sorting for consistency with the -help option
+  // which prints out options in the case-insensitive alphabetical order.
+  std::sort(SuggestedCompletions.begin(), SuggestedCompletions.end(),
+[](StringRef A, StringRef B) { return A.compare_lower(B) < 0; });
+
+  llvm::outs() << llvm::join(SuggestedCompletions, "\n") << '\n';
+}
+
 bool Driver::HandleImmediateArgs(const Compilation &C) {
   // The order these options are handled in gcc is all over the place, but we
   // don't expect inconsistencies w.r.t. that to matter in practice.
@@ -1250,50 +1301,7 @@
   }
 
   if (Arg *A = C.getArgs().getLastArg(options::OPT_autocomplete)) {
-// Print out all options that start with a given argument. This is used for
-// shell autocompletion.
-StringRef PassedFlags = A->getValue();
-std::vector SuggestedCompletions;
-
-unsigned short DisableFlags = options::NoDriverOption | options::Unsupported | options::Ignored;
-// We want to show cc1-only options only when clang is invoked as "clang -cc1".
-// When clang is invoked as "clang -cc1", we add "#" to the beginning of an --autocomplete
-// option so that the clang driver can distinguish whether it is requested to show cc1-only options or not.
-if (PassedFlags[0] == '#') {
-  DisableFlags &= ~options::NoDriverOption;
-  PassedFlags = PassedFlags.substr(1);
-}
-
-if (PassedFlags.find(',') == StringRef::npos) {
-  // If the flag is in the form of "--autocomplete=-foo",
-  // we were requested to print out all option names that start with "-foo".
-  // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
-  SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
-
-  // We have to query the -W flags manually as they're not in the OptTable.
-  // TODO: Find a good way to add them to OptTable instead and them remove
-  // this code.
-  for (StringRef S : DiagnosticIDs::getDiagnosticFlags())
-if (S.startswith(PassedFlags))
-  SuggestedCompletions.push_back(S);
-} else {
-  // If the flag is in the form of "--autocomplete=foo,bar", we were
-  // requested to print out all option values for "-foo" that start with
-  // "bar". For example,
-  // "--autocomplete=-stdlib=,l" is expanded to "libc++" and "libstdc++".
-  StringRef Option, Arg;
-  std::tie(Option, Arg) = PassedFlags.split(',');
-  SuggestedCom

[PATCH] D37249: [Bash-autocomplete] Refactor autocomplete code into own function

2017-08-28 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 113027.
yamaguchi marked an inline comment as done.
yamaguchi added a comment.

Update diff. I agree that this is more generic.


https://reviews.llvm.org/D37249

Files:
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp

Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1157,6 +1157,56 @@
 OS << i << ',' << DiagnosticIDs::getCategoryNameFromID(i) << '\n';
 }
 
+void Driver::handleAutocompletions(StringRef PassedFlags) const {
+  // Print out all options that start with a given argument. This is used for
+  // shell autocompletion.
+  std::vector SuggestedCompletions;
+
+  unsigned short DisableFlags =
+  options::NoDriverOption | options::Unsupported | options::Ignored;
+  // We want to show cc1-only options only when clang is invoked as "clang
+  // -cc1".
+  // When clang is invoked as "clang -cc1", we add "#" to the beginning of an
+  // --autocomplete
+  // option so that the clang driver can distinguish whether it is requested to
+  // show cc1-only options or not.
+  if (PassedFlags[0] == '#') {
+DisableFlags &= ~options::NoDriverOption;
+PassedFlags = PassedFlags.substr(1);
+  }
+
+  if (PassedFlags.find(',') == StringRef::npos) {
+// If the flag is in the form of "--autocomplete=-foo",
+// we were requested to print out all option names that start with "-foo".
+// For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
+SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
+
+// We have to query the -W flags manually as they're not in the OptTable.
+// TODO: Find a good way to add them to OptTable instead and them remove
+// this code.
+for (StringRef S : DiagnosticIDs::getDiagnosticFlags())
+  if (S.startswith(PassedFlags))
+SuggestedCompletions.push_back(S);
+  } else {
+// If the flag is in the form of "--autocomplete=foo,bar", we were
+// requested to print out all option values for "-foo" that start with
+// "bar". For example,
+// "--autocomplete=-stdlib=,l" is expanded to "libc++" and "libstdc++".
+StringRef Option, Arg;
+std::tie(Option, Arg) = PassedFlags.split(',');
+SuggestedCompletions = Opts->suggestValueCompletions(Option, Arg);
+  }
+
+  // Sort the autocomplete candidates so that shells print them out in a
+  // deterministic order. We could sort in any way, but we chose
+  // case-insensitive sorting for consistency with the -help option
+  // which prints out options in the case-insensitive alphabetical order.
+  std::sort(SuggestedCompletions.begin(), SuggestedCompletions.end(),
+[](StringRef A, StringRef B) { return A.compare_lower(B) < 0; });
+
+  llvm::outs() << llvm::join(SuggestedCompletions, "\n") << '\n';
+}
+
 bool Driver::HandleImmediateArgs(const Compilation &C) {
   // The order these options are handled in gcc is all over the place, but we
   // don't expect inconsistencies w.r.t. that to matter in practice.
@@ -1250,50 +1300,8 @@
   }
 
   if (Arg *A = C.getArgs().getLastArg(options::OPT_autocomplete)) {
-// Print out all options that start with a given argument. This is used for
-// shell autocompletion.
 StringRef PassedFlags = A->getValue();
-std::vector SuggestedCompletions;
-
-unsigned short DisableFlags = options::NoDriverOption | options::Unsupported | options::Ignored;
-// We want to show cc1-only options only when clang is invoked as "clang -cc1".
-// When clang is invoked as "clang -cc1", we add "#" to the beginning of an --autocomplete
-// option so that the clang driver can distinguish whether it is requested to show cc1-only options or not.
-if (PassedFlags[0] == '#') {
-  DisableFlags &= ~options::NoDriverOption;
-  PassedFlags = PassedFlags.substr(1);
-}
-
-if (PassedFlags.find(',') == StringRef::npos) {
-  // If the flag is in the form of "--autocomplete=-foo",
-  // we were requested to print out all option names that start with "-foo".
-  // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
-  SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
-
-  // We have to query the -W flags manually as they're not in the OptTable.
-  // TODO: Find a good way to add them to OptTable instead and them remove
-  // this code.
-  for (StringRef S : DiagnosticIDs::getDiagnosticFlags())
-if (S.startswith(PassedFlags))
-  SuggestedCompletions.push_back(S);
-} else {
-  // If the flag is in the form of "--autocomplete=foo,bar", we were
-  // requested to print out all option values for "-foo" that start with
-  // "bar". For example,
-  // "--autocomplete=-stdlib=,l" is expanded to "libc++" and "libstdc++".
-  StringRef Option, Arg;
-  std::tie(Option, Arg) = PassedFlags.split(',');
-  SuggestedComple

[PATCH] D37249: [Bash-autocomplete] Refactor autocomplete code into own function

2017-08-29 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312018: [Bash-autocomplete] Refactor autocomplete code into 
own function (authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D37249?vs=113027&id=113118#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37249

Files:
  cfe/trunk/include/clang/Driver/Driver.h
  cfe/trunk/lib/Driver/Driver.cpp

Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -1156,6 +1156,56 @@
 OS << i << ',' << DiagnosticIDs::getCategoryNameFromID(i) << '\n';
 }
 
+void Driver::handleAutocompletions(StringRef PassedFlags) const {
+  // Print out all options that start with a given argument. This is used for
+  // shell autocompletion.
+  std::vector SuggestedCompletions;
+
+  unsigned short DisableFlags =
+  options::NoDriverOption | options::Unsupported | options::Ignored;
+  // We want to show cc1-only options only when clang is invoked as "clang
+  // -cc1".
+  // When clang is invoked as "clang -cc1", we add "#" to the beginning of an
+  // --autocomplete
+  // option so that the clang driver can distinguish whether it is requested to
+  // show cc1-only options or not.
+  if (PassedFlags[0] == '#') {
+DisableFlags &= ~options::NoDriverOption;
+PassedFlags = PassedFlags.substr(1);
+  }
+
+  if (PassedFlags.find(',') == StringRef::npos) {
+// If the flag is in the form of "--autocomplete=-foo",
+// we were requested to print out all option names that start with "-foo".
+// For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
+SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
+
+// We have to query the -W flags manually as they're not in the OptTable.
+// TODO: Find a good way to add them to OptTable instead and them remove
+// this code.
+for (StringRef S : DiagnosticIDs::getDiagnosticFlags())
+  if (S.startswith(PassedFlags))
+SuggestedCompletions.push_back(S);
+  } else {
+// If the flag is in the form of "--autocomplete=foo,bar", we were
+// requested to print out all option values for "-foo" that start with
+// "bar". For example,
+// "--autocomplete=-stdlib=,l" is expanded to "libc++" and "libstdc++".
+StringRef Option, Arg;
+std::tie(Option, Arg) = PassedFlags.split(',');
+SuggestedCompletions = Opts->suggestValueCompletions(Option, Arg);
+  }
+
+  // Sort the autocomplete candidates so that shells print them out in a
+  // deterministic order. We could sort in any way, but we chose
+  // case-insensitive sorting for consistency with the -help option
+  // which prints out options in the case-insensitive alphabetical order.
+  std::sort(SuggestedCompletions.begin(), SuggestedCompletions.end(),
+[](StringRef A, StringRef B) { return A.compare_lower(B) < 0; });
+
+  llvm::outs() << llvm::join(SuggestedCompletions, "\n") << '\n';
+}
+
 bool Driver::HandleImmediateArgs(const Compilation &C) {
   // The order these options are handled in gcc is all over the place, but we
   // don't expect inconsistencies w.r.t. that to matter in practice.
@@ -1249,50 +1299,8 @@
   }
 
   if (Arg *A = C.getArgs().getLastArg(options::OPT_autocomplete)) {
-// Print out all options that start with a given argument. This is used for
-// shell autocompletion.
 StringRef PassedFlags = A->getValue();
-std::vector SuggestedCompletions;
-
-unsigned short DisableFlags = options::NoDriverOption | options::Unsupported | options::Ignored;
-// We want to show cc1-only options only when clang is invoked as "clang -cc1".
-// When clang is invoked as "clang -cc1", we add "#" to the beginning of an --autocomplete
-// option so that the clang driver can distinguish whether it is requested to show cc1-only options or not.
-if (PassedFlags[0] == '#') {
-  DisableFlags &= ~options::NoDriverOption;
-  PassedFlags = PassedFlags.substr(1);
-}
-
-if (PassedFlags.find(',') == StringRef::npos) {
-  // If the flag is in the form of "--autocomplete=-foo",
-  // we were requested to print out all option names that start with "-foo".
-  // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
-  SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
-
-  // We have to query the -W flags manually as they're not in the OptTable.
-  // TODO: Find a good way to add them to OptTable instead and them remove
-  // this code.
-  for (StringRef S : DiagnosticIDs::getDiagnosticFlags())
-if (S.startswith(PassedFlags))
-  SuggestedCompletions.push_back(S);
-} else {
-  // If the flag is in the form of "--autocomplete=foo,bar", we were
-  // requested to print out all option values for "-foo" that start with
-  // "bar". For example,
-  // "--autocomplete=-stdlib=,l

[PATCH] D37465: [Bash-autocomplete] Fix crash when invoking --autocomplete without value.

2017-09-05 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi accepted this revision.
yamaguchi added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks for the fix!


Repository:
  rL LLVM

https://reviews.llvm.org/D37465



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


[PATCH] D56390: Generate Checkers.inc under clang/Driver and use from CC1Options.td

2019-01-07 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added a reviewer: thakis.
Herald added a subscriber: mgorny.

Generate Checkers.inc also under include/clang/Driver so that we can
include this file from Driver/CC1Options.td without making Driver's
tablegen output depending on StaticAnalyzer/Checker's tablegen output.


https://reviews.llvm.org/D56390

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/CMakeLists.txt


Index: clang/include/clang/Driver/CMakeLists.txt
===
--- clang/include/clang/Driver/CMakeLists.txt
+++ clang/include/clang/Driver/CMakeLists.txt
@@ -1,3 +1,7 @@
 set(LLVM_TARGET_DEFINITIONS Options.td)
 tablegen(LLVM Options.inc -gen-opt-parser-defs)
+clang_tablegen(Checkers.inc -gen-clang-sa-checkers
+   -I ${CMAKE_CURRENT_SOURCE_DIR}/../StaticAnalyzer/Checkers
+   SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../StaticAnalyzer/Checkers/Checkers.td
+   TARGET SACheckerForClangDriver)
 add_public_tablegen_target(ClangDriverOptions)
Index: clang/include/clang/Driver/CC1Options.td
===
--- clang/include/clang/Driver/CC1Options.td
+++ clang/include/clang/Driver/CC1Options.td
@@ -109,11 +109,11 @@
 const char *Values =
 #define GET_CHECKERS
 #define CHECKER(FULLNAME, CLASS, HT, DOC_URI)  FULLNAME ","
-#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
+#include "clang/Driver/Checkers.inc"
 #undef GET_CHECKERS
 #define GET_PACKAGES
 #define PACKAGE(FULLNAME)  FULLNAME ","
-#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
+#include "clang/Driver/Checkers.inc"
 #undef GET_PACKAGES
 ;
   }]>;


Index: clang/include/clang/Driver/CMakeLists.txt
===
--- clang/include/clang/Driver/CMakeLists.txt
+++ clang/include/clang/Driver/CMakeLists.txt
@@ -1,3 +1,7 @@
 set(LLVM_TARGET_DEFINITIONS Options.td)
 tablegen(LLVM Options.inc -gen-opt-parser-defs)
+clang_tablegen(Checkers.inc -gen-clang-sa-checkers
+   -I ${CMAKE_CURRENT_SOURCE_DIR}/../StaticAnalyzer/Checkers
+   SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../StaticAnalyzer/Checkers/Checkers.td
+   TARGET SACheckerForClangDriver)
 add_public_tablegen_target(ClangDriverOptions)
Index: clang/include/clang/Driver/CC1Options.td
===
--- clang/include/clang/Driver/CC1Options.td
+++ clang/include/clang/Driver/CC1Options.td
@@ -109,11 +109,11 @@
 const char *Values =
 #define GET_CHECKERS
 #define CHECKER(FULLNAME, CLASS, HT, DOC_URI)  FULLNAME ","
-#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
+#include "clang/Driver/Checkers.inc"
 #undef GET_CHECKERS
 #define GET_PACKAGES
 #define PACKAGE(FULLNAME)  FULLNAME ","
-#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
+#include "clang/Driver/Checkers.inc"
 #undef GET_PACKAGES
 ;
   }]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56438: [Modules] Allow modulemap path change for implicitly built modules

2019-01-08 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added reviewers: rsmith, dblaikie.

Previous code was comparing the location of "modulemap which
is currently loaded and gives a definition of current module"
and "the location of the modulemap where the current implicit module was built".

This check was problematic for the usecase when installing modulemaps and 
prebuilt pcms
to other (e.g install) directories.


https://reviews.llvm.org/D56438

Files:
  clang/lib/Serialization/ASTReader.cpp


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3632,7 +3632,8 @@
 
 // Check the primary module map file.
 const FileEntry *StoredModMap = FileMgr.getFile(F.ModuleMapPath);
-if (StoredModMap == nullptr || StoredModMap != ModMap) {
+if (!PP.getPreprocessorOpts().DisablePCHValidation &&
+(StoredModMap == nullptr || StoredModMap != ModMap)) {
   assert(ModMap && "found module is missing module map file");
   assert(ImportedBy && "top-level import should be verified");
   if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3632,7 +3632,8 @@
 
 // Check the primary module map file.
 const FileEntry *StoredModMap = FileMgr.getFile(F.ModuleMapPath);
-if (StoredModMap == nullptr || StoredModMap != ModMap) {
+if (!PP.getPreprocessorOpts().DisablePCHValidation &&
+(StoredModMap == nullptr || StoredModMap != ModMap)) {
   assert(ModMap && "found module is missing module map file");
   assert(ImportedBy && "top-level import should be verified");
   if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56438: [Modules] Allow modulemap path change for implicitly built modules

2019-01-08 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added a comment.

We have both explicitly and implicitly prebuilt modules, but this patch only 
relates to implicit ones. I agree that our usecase is a bit unique where we're 
installing and distributing implicitly built pcm, but I also imagine there 
might be a usecase where you built implicit pcms in some directory and want to 
reuse them somehow from other locations. If it doesn't make sense to be 
upstream, this can stay in our fork.


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

https://reviews.llvm.org/D56438



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


[PATCH] D45921: Add getDeserializationListener to ASTReader

2018-04-21 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added reviewers: v.g.vassilev, rsmith, dblaikie, thakis.

We need to know if ASTReader already has a DeserializationListner or
not, and this also helps to create a multiplexing deserialization
listener if there is one already attached.


https://reviews.llvm.org/D45921

Files:
  clang/include/clang/Serialization/ASTReader.h


Index: clang/include/clang/Serialization/ASTReader.h
===
--- clang/include/clang/Serialization/ASTReader.h
+++ clang/include/clang/Serialization/ASTReader.h
@@ -1599,6 +1599,11 @@
   void setDeserializationListener(ASTDeserializationListener *Listener,
   bool TakeOwnership = false);
 
+  /// \brief Get the AST deserialization listener.
+  ASTDeserializationListener *getDeserializationListener() {
+return DeserializationListener;
+  }
+
   /// \brief Determine whether this AST reader has a global index.
   bool hasGlobalIndex() const { return (bool)GlobalIndex; }
 


Index: clang/include/clang/Serialization/ASTReader.h
===
--- clang/include/clang/Serialization/ASTReader.h
+++ clang/include/clang/Serialization/ASTReader.h
@@ -1599,6 +1599,11 @@
   void setDeserializationListener(ASTDeserializationListener *Listener,
   bool TakeOwnership = false);
 
+  /// \brief Get the AST deserialization listener.
+  ASTDeserializationListener *getDeserializationListener() {
+return DeserializationListener;
+  }
+
   /// \brief Determine whether this AST reader has a global index.
   bool hasGlobalIndex() const { return (bool)GlobalIndex; }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45921: Add getDeserializationListener to ASTReader

2018-04-25 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added a comment.

Do you mean something like `addDeserializationListener` which create a 
multiplex listener with an existing listener? I think that'll be good as well!


https://reviews.llvm.org/D45921



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


[PATCH] D45921: Add getDeserializationListener to ASTReader

2018-04-26 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL330946: Add getDeserializationListener to ASTReader 
(authored by yamaguchi, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45921?vs=143441&id=144124#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45921

Files:
  cfe/trunk/include/clang/Serialization/ASTReader.h


Index: cfe/trunk/include/clang/Serialization/ASTReader.h
===
--- cfe/trunk/include/clang/Serialization/ASTReader.h
+++ cfe/trunk/include/clang/Serialization/ASTReader.h
@@ -1599,6 +1599,11 @@
   void setDeserializationListener(ASTDeserializationListener *Listener,
   bool TakeOwnership = false);
 
+  /// \brief Get the AST deserialization listener.
+  ASTDeserializationListener *getDeserializationListener() {
+return DeserializationListener;
+  }
+
   /// \brief Determine whether this AST reader has a global index.
   bool hasGlobalIndex() const { return (bool)GlobalIndex; }
 


Index: cfe/trunk/include/clang/Serialization/ASTReader.h
===
--- cfe/trunk/include/clang/Serialization/ASTReader.h
+++ cfe/trunk/include/clang/Serialization/ASTReader.h
@@ -1599,6 +1599,11 @@
   void setDeserializationListener(ASTDeserializationListener *Listener,
   bool TakeOwnership = false);
 
+  /// \brief Get the AST deserialization listener.
+  ASTDeserializationListener *getDeserializationListener() {
+return DeserializationListener;
+  }
+
   /// \brief Determine whether this AST reader has a global index.
   bool hasGlobalIndex() const { return (bool)GlobalIndex; }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48367: [modules] Fix 37878; Autoload subdirectory modulemaps with specific LangOpts

2018-06-25 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: clang/lib/Lex/HeaderSearch.cpp:285
 // directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+if (ModMap.getLangOpts().ObjC1 || ModMap.getLangOpts().ObjC2)
+  loadSubdirectoryModuleMaps(SearchDirs[Idx]);

bruno wrote:
> yamaguchi wrote:
> > bruno wrote:
> > > aprantl wrote:
> > > > Are these flags also enabled in Objective-C++ mode?
> > > Looks like all this logic was introduced in r177621 to allow the names of 
> > > modules to differ from the name of their subdirectory in the include path.
> > > 
> > > Instead of having this to be based on the language, it's probably better 
> > > if we have it based on @import name lookup, which is the scenario where 
> > > we actually currently look more aggressively, did you try that path?
> > > 
> > > This is also lacking a testcase, can you create one?
> > > Are these flags also enabled in Objective-C++ mode?
> > I think so from FrontendOptions.h:190
> > `bool isObjectiveC() const { return Lang == ObjC || Lang == ObjCXX; }`
> > 
> > > it's probably better if we have it based on @import name lookup
> > I don't think I understood what you're saying, could you explain a bit more?
> > 
> > > This is also lacking a testcase, can you create one?
> > Sure!
> > I don't think I understood what you're saying, could you explain a bit more?
> 
> This extra call to `loadSubdirectoryModuleMaps` was introduced in r177621 to 
> allow `@import SomeName` to work even if `SomeName` doesn't match a 
> subdirectory name. See the original commit for more details.
> 
> This means that it was never supposed to be called when the module is built 
> via `#include` or `#import`, which is what you are getting. That said, I 
> believe it's better if the condition for calling `loadSubdirectoryModuleMaps` 
> checks somehow if the lookup is coming from of an `@import` instead of 
> checking the language (we too don't want it to be called for ObjC when 
> `#include` or `#import` are used).
> we too don't want it to be called for ObjC when #include or #import are used
https://gist.github.com/yamaguchi1024/27caba1897eb813b297a8c4785adc11d
This is one thing I could think of, it excludes `#include` but `#import` and 
`@import` are still treated in the same way. Do you have any idea how to do 
this? Is Clang differenciating the module behavior based on `#import` or 
`@import` in ObjC?



Comment at: clang/test/Modules/autoload-subdirectory.cpp:1
+// RUN: %clang -fmodules -fmodule-name=Foo -I %S/Inputs/autoload-subdirectory/ 
%s
+

bruno wrote:
> Instead of `%clang`, please use `%clang_cc1` and `-verify` here.
Sure


https://reviews.llvm.org/D48367



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


[PATCH] D48367: [modules] Fix 37878; Autoload subdirectory modulemaps with specific LangOpts

2018-06-25 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 152664.
yamaguchi added a comment.

use %clang_cc1 instead of %clang


https://reviews.llvm.org/D48367

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/Modules/Inputs/autoload-subdirectory/a.h
  clang/test/Modules/Inputs/autoload-subdirectory/b.h
  clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
  clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
  clang/test/Modules/autoload-subdirectory.cpp


Index: clang/test/Modules/autoload-subdirectory.cpp
===
--- /dev/null
+++ clang/test/Modules/autoload-subdirectory.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fmodules -fmodule-name=Foo -I 
%S/Inputs/autoload-subdirectory/ %s -verify
+// expected-no-diagnostics
+
+#include "a.h"
+
+int main() {
+  foo neko;
+  return 0;
+}
Index: clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
@@ -0,0 +1,2 @@
+module a { header "a.h" }
+module b { header "b.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
@@ -0,0 +1,2 @@
+module a { header "a.h" }
+module b { header "b.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/b.h
@@ -0,0 +1 @@
+class bar {};
Index: clang/test/Modules/Inputs/autoload-subdirectory/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/a.h
@@ -0,0 +1,8 @@
+#include "b.h"
+
+class foo {
+  int x,y;
+  public:
+foo() {};
+~foo() {};
+};
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -282,7 +282,8 @@
 
 // Load all module maps in the immediate subdirectories of this search
 // directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+if (ModMap.getLangOpts().ObjC1 || ModMap.getLangOpts().ObjC2)
+  loadSubdirectoryModuleMaps(SearchDirs[Idx]);
 
 // Look again for the module.
 Module = ModMap.findModule(ModuleName);
Index: clang/include/clang/Lex/ModuleMap.h
===
--- clang/include/clang/Lex/ModuleMap.h
+++ clang/include/clang/Lex/ModuleMap.h
@@ -110,6 +110,11 @@
   llvm::StringMap> PendingLinkAsModule;
 
 public:
+  /// Get LangOpts of ModuleMap
+  const LangOptions& getLangOpts() {
+return LangOpts;
+  }
+
   /// Use PendingLinkAsModule information to mark top level link names that
   /// are going to be replaced by export_as aliases.
   void resolveLinkAsDependencies(Module *Mod);


Index: clang/test/Modules/autoload-subdirectory.cpp
===
--- /dev/null
+++ clang/test/Modules/autoload-subdirectory.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fmodules -fmodule-name=Foo -I %S/Inputs/autoload-subdirectory/ %s -verify
+// expected-no-diagnostics
+
+#include "a.h"
+
+int main() {
+  foo neko;
+  return 0;
+}
Index: clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
@@ -0,0 +1,2 @@
+module a { header "a.h" }
+module b { header "b.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
@@ -0,0 +1,2 @@
+module a { header "a.h" }
+module b { header "b.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/b.h
@@ -0,0 +1 @@
+class bar {};
Index: clang/test/Modules/Inputs/autoload-subdirectory/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/a.h
@@ -0,0 +1,8 @@
+#include "b.h"
+
+class foo {
+  int x,y;
+  public:
+foo() {};
+~foo() {};
+};
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -282,7 +282,8 @@
 
 // Load all module maps in the immediate subdirectories of this search
 // directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+if (ModMap

[PATCH] D48367: [modules] Fix 37878; Autoload subdirectory modulemaps with specific LangOpts

2018-06-26 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 152875.
yamaguchi added a comment.

Add #import test and add branch AllowExtraModuleMapSearch when ModuleName was 
from @import


https://reviews.llvm.org/D48367

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Modules/Inputs/autoload-subdirectory/a.h
  clang/test/Modules/Inputs/autoload-subdirectory/b.h
  clang/test/Modules/Inputs/autoload-subdirectory/c.h
  clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
  clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
  clang/test/Modules/a.out
  clang/test/Modules/autoload-subdirectory.cpp

Index: clang/test/Modules/autoload-subdirectory.cpp
===
--- /dev/null
+++ clang/test/Modules/autoload-subdirectory.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fmodules -fmodule-name=Foo -I %S/Inputs/autoload-subdirectory/ %s -verify
+// expected-no-diagnostics
+
+#include "a.h"
+#import "c.h"
+
+int main() {
+  foo neko;
+  return 0;
+}
Index: clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
@@ -0,0 +1,3 @@
+module a { header "a.h" }
+module b { header "b.h" }
+module c { header "c.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
@@ -0,0 +1,3 @@
+module a { header "a.h" }
+module b { header "b.h" }
+module c { header "c.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/c.h
@@ -0,0 +1,7 @@
+class nyan {
+  bool x, y;
+
+public:
+  nyan(){};
+  ~nyan(){};
+};
Index: clang/test/Modules/Inputs/autoload-subdirectory/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/b.h
@@ -0,0 +1 @@
+class bar {};
Index: clang/test/Modules/Inputs/autoload-subdirectory/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/a.h
@@ -0,0 +1,9 @@
+#include "b.h"
+
+class foo {
+  int x, y;
+
+public:
+  foo(){};
+  ~foo(){};
+};
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2613,7 +2613,9 @@
  "MODULE_DIRECTORY found before MODULE_NAME");
   // If we've already loaded a module map file covering this module, we may
   // have a better path for it (relative to the current build).
-  Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName);
+  Module *M = PP.getHeaderSearchInfo().lookupModule(
+  F.ModuleName, /*AllowSearch*/ true,
+  /*AllowExtraModuleMapSearch*/ true);
   if (M && M->Directory) {
 // If we're implicitly loading a module, the base directory can't
 // change between the build and use.
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -198,14 +198,15 @@
   return Result.str().str();
 }
 
-Module *HeaderSearch::lookupModule(StringRef ModuleName, bool AllowSearch) {
+Module *HeaderSearch::lookupModule(StringRef ModuleName, bool AllowSearch,
+   bool AllowExtraModuleMapSearch) {
   // Look in the module map to determine if there is a module by this name.
   Module *Module = ModMap.findModule(ModuleName);
   if (Module || !AllowSearch || !HSOpts->ImplicitModuleMaps)
 return Module;
 
   StringRef SearchName = ModuleName;
-  Module = lookupModule(ModuleName, SearchName);
+  Module = lookupModule(ModuleName, SearchName, AllowExtraModuleMapSearch);
 
   // The facility for "private modules" -- adjacent, optional module maps named
   // module.private.modulemap that are supposed to define private submodules --
@@ -216,13 +217,14 @@
   // could force building unwanted dependencies into the parent module and cause
   // dependency cycles.
   if (!Module && SearchName.consume_back("_Private"))
-Module = lookupModule(ModuleName, SearchName);
+Module = lookupModule(ModuleName, SearchName, AllowExtraModuleMapSearch);
   if (!Module && SearchName.consume_back("Private"))
-Module = lookupModule(ModuleName, SearchName);
+Module = lookupModule(ModuleName, SearchName, AllowExtraModuleMapSearch);
   return Module;
 }
 
-Module *HeaderSearch::lookupModule(StringRef ModuleName, Strin

[PATCH] D48367: [modules] Fix 37878; Autoload subdirectory modulemaps with specific LangOpts

2018-06-26 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: clang/lib/Lex/HeaderSearch.cpp:285
 // directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+if (ModMap.getLangOpts().ObjC1 || ModMap.getLangOpts().ObjC2)
+  loadSubdirectoryModuleMaps(SearchDirs[Idx]);

bruno wrote:
> yamaguchi wrote:
> > bruno wrote:
> > > yamaguchi wrote:
> > > > bruno wrote:
> > > > > aprantl wrote:
> > > > > > Are these flags also enabled in Objective-C++ mode?
> > > > > Looks like all this logic was introduced in r177621 to allow the 
> > > > > names of modules to differ from the name of their subdirectory in the 
> > > > > include path.
> > > > > 
> > > > > Instead of having this to be based on the language, it's probably 
> > > > > better if we have it based on @import name lookup, which is the 
> > > > > scenario where we actually currently look more aggressively, did you 
> > > > > try that path?
> > > > > 
> > > > > This is also lacking a testcase, can you create one?
> > > > > Are these flags also enabled in Objective-C++ mode?
> > > > I think so from FrontendOptions.h:190
> > > > `bool isObjectiveC() const { return Lang == ObjC || Lang == ObjCXX; }`
> > > > 
> > > > > it's probably better if we have it based on @import name lookup
> > > > I don't think I understood what you're saying, could you explain a bit 
> > > > more?
> > > > 
> > > > > This is also lacking a testcase, can you create one?
> > > > Sure!
> > > > I don't think I understood what you're saying, could you explain a bit 
> > > > more?
> > > 
> > > This extra call to `loadSubdirectoryModuleMaps` was introduced in r177621 
> > > to allow `@import SomeName` to work even if `SomeName` doesn't match a 
> > > subdirectory name. See the original commit for more details.
> > > 
> > > This means that it was never supposed to be called when the module is 
> > > built via `#include` or `#import`, which is what you are getting. That 
> > > said, I believe it's better if the condition for calling 
> > > `loadSubdirectoryModuleMaps` checks somehow if the lookup is coming from 
> > > of an `@import` instead of checking the language (we too don't want it to 
> > > be called for ObjC when `#include` or `#import` are used).
> > > we too don't want it to be called for ObjC when #include or #import are 
> > > used
> > https://gist.github.com/yamaguchi1024/27caba1897eb813b297a8c4785adc11d
> > This is one thing I could think of, it excludes `#include` but `#import` 
> > and `@import` are still treated in the same way. Do you have any idea how 
> > to do this? Is Clang differenciating the module behavior based on `#import` 
> > or `@import` in ObjC?
> > https://gist.github.com/yamaguchi1024/27caba1897eb813b297a8c4785adc11d
> 
> Something along these lines seems fine. I'd reverse the condition of 
> `IsInclusionDirective` to be true by default (which is the most common case), 
> and you pass false when coming from `@import`s. Maybe also rename it to 
> something more meaningful for the change in question, around the lines of 
> `AllowExtraModuleMapSearch`.
> 
> > This is one thing I could think of, it excludes #include but #import and 
> > @import are still treated in the same way.
> 
> `#import` and `#include` should be treated the same way (extra searches 
> shouldn't happen for both), `@import` is the only one different. 
> 
> > Do you have any idea how to do this? Is Clang differenciating the module 
> > behavior based on #import or @import in ObjC?
> 
> `#import` works very much like `#include`, the difference is that `#import`'s 
> have implicit `#pragma once` like behavior. 
> #import and #include should be treated the same way
I'll add a test for #import as well.


https://reviews.llvm.org/D48367



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


[PATCH] D48367: [modules] Fix 37878; Autoload subdirectory modulemaps with specific LangOpts

2018-06-26 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 152876.
yamaguchi added a comment.

Delete a.out)


https://reviews.llvm.org/D48367

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Modules/Inputs/autoload-subdirectory/a.h
  clang/test/Modules/Inputs/autoload-subdirectory/b.h
  clang/test/Modules/Inputs/autoload-subdirectory/c.h
  clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
  clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
  clang/test/Modules/autoload-subdirectory.cpp

Index: clang/test/Modules/autoload-subdirectory.cpp
===
--- /dev/null
+++ clang/test/Modules/autoload-subdirectory.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fmodules -fmodule-name=Foo -I %S/Inputs/autoload-subdirectory/ %s -verify
+// expected-no-diagnostics
+
+#include "a.h"
+#import "c.h"
+
+int main() {
+  foo neko;
+  return 0;
+}
Index: clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/module.modulemap
@@ -0,0 +1,3 @@
+module a { header "a.h" }
+module b { header "b.h" }
+module c { header "c.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
@@ -0,0 +1,3 @@
+module a { header "a.h" }
+module b { header "b.h" }
+module c { header "c.h" }
Index: clang/test/Modules/Inputs/autoload-subdirectory/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/c.h
@@ -0,0 +1,7 @@
+class nyan {
+  bool x, y;
+
+public:
+  nyan(){};
+  ~nyan(){};
+};
Index: clang/test/Modules/Inputs/autoload-subdirectory/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/b.h
@@ -0,0 +1 @@
+class bar {};
Index: clang/test/Modules/Inputs/autoload-subdirectory/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/autoload-subdirectory/a.h
@@ -0,0 +1,9 @@
+#include "b.h"
+
+class foo {
+  int x, y;
+
+public:
+  foo(){};
+  ~foo(){};
+};
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2613,7 +2613,9 @@
  "MODULE_DIRECTORY found before MODULE_NAME");
   // If we've already loaded a module map file covering this module, we may
   // have a better path for it (relative to the current build).
-  Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName);
+  Module *M = PP.getHeaderSearchInfo().lookupModule(
+  F.ModuleName, /*AllowSearch*/ true,
+  /*AllowExtraModuleMapSearch*/ true);
   if (M && M->Directory) {
 // If we're implicitly loading a module, the base directory can't
 // change between the build and use.
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -198,14 +198,15 @@
   return Result.str().str();
 }
 
-Module *HeaderSearch::lookupModule(StringRef ModuleName, bool AllowSearch) {
+Module *HeaderSearch::lookupModule(StringRef ModuleName, bool AllowSearch,
+   bool AllowExtraModuleMapSearch) {
   // Look in the module map to determine if there is a module by this name.
   Module *Module = ModMap.findModule(ModuleName);
   if (Module || !AllowSearch || !HSOpts->ImplicitModuleMaps)
 return Module;
 
   StringRef SearchName = ModuleName;
-  Module = lookupModule(ModuleName, SearchName);
+  Module = lookupModule(ModuleName, SearchName, AllowExtraModuleMapSearch);
 
   // The facility for "private modules" -- adjacent, optional module maps named
   // module.private.modulemap that are supposed to define private submodules --
@@ -216,13 +217,14 @@
   // could force building unwanted dependencies into the parent module and cause
   // dependency cycles.
   if (!Module && SearchName.consume_back("_Private"))
-Module = lookupModule(ModuleName, SearchName);
+Module = lookupModule(ModuleName, SearchName, AllowExtraModuleMapSearch);
   if (!Module && SearchName.consume_back("Private"))
-Module = lookupModule(ModuleName, SearchName);
+Module = lookupModule(ModuleName, SearchName, AllowExtraModuleMapSearch);
   return Module;
 }
 
-Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName) {
+Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
+ 

[PATCH] D48367: [modules] Fix 37878; Autoload subdirectory modulemaps with specific LangOpts

2018-07-10 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL336660: [modules] Fix 37878; Autoload subdirectory 
modulemaps with specific LangOpts (authored by yamaguchi, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48367?vs=152876&id=154779#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48367

Files:
  cfe/trunk/include/clang/Lex/HeaderSearch.h
  cfe/trunk/lib/Frontend/CompilerInstance.cpp
  cfe/trunk/lib/Lex/HeaderSearch.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/test/Modules/Inputs/autoload-subdirectory/a.h
  cfe/trunk/test/Modules/Inputs/autoload-subdirectory/b.h
  cfe/trunk/test/Modules/Inputs/autoload-subdirectory/c.h
  cfe/trunk/test/Modules/Inputs/autoload-subdirectory/include/module.modulemap
  cfe/trunk/test/Modules/Inputs/autoload-subdirectory/module.modulemap
  cfe/trunk/test/Modules/autoload-subdirectory.cpp

Index: cfe/trunk/lib/Serialization/ASTReader.cpp
===
--- cfe/trunk/lib/Serialization/ASTReader.cpp
+++ cfe/trunk/lib/Serialization/ASTReader.cpp
@@ -2626,7 +2626,9 @@
  "MODULE_DIRECTORY found before MODULE_NAME");
   // If we've already loaded a module map file covering this module, we may
   // have a better path for it (relative to the current build).
-  Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName);
+  Module *M = PP.getHeaderSearchInfo().lookupModule(
+  F.ModuleName, /*AllowSearch*/ true,
+  /*AllowExtraModuleMapSearch*/ true);
   if (M && M->Directory) {
 // If we're implicitly loading a module, the base directory can't
 // change between the build and use.
Index: cfe/trunk/lib/Lex/HeaderSearch.cpp
===
--- cfe/trunk/lib/Lex/HeaderSearch.cpp
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp
@@ -198,14 +198,15 @@
   return Result.str().str();
 }
 
-Module *HeaderSearch::lookupModule(StringRef ModuleName, bool AllowSearch) {
+Module *HeaderSearch::lookupModule(StringRef ModuleName, bool AllowSearch,
+   bool AllowExtraModuleMapSearch) {
   // Look in the module map to determine if there is a module by this name.
   Module *Module = ModMap.findModule(ModuleName);
   if (Module || !AllowSearch || !HSOpts->ImplicitModuleMaps)
 return Module;
 
   StringRef SearchName = ModuleName;
-  Module = lookupModule(ModuleName, SearchName);
+  Module = lookupModule(ModuleName, SearchName, AllowExtraModuleMapSearch);
 
   // The facility for "private modules" -- adjacent, optional module maps named
   // module.private.modulemap that are supposed to define private submodules --
@@ -216,13 +217,14 @@
   // could force building unwanted dependencies into the parent module and cause
   // dependency cycles.
   if (!Module && SearchName.consume_back("_Private"))
-Module = lookupModule(ModuleName, SearchName);
+Module = lookupModule(ModuleName, SearchName, AllowExtraModuleMapSearch);
   if (!Module && SearchName.consume_back("Private"))
-Module = lookupModule(ModuleName, SearchName);
+Module = lookupModule(ModuleName, SearchName, AllowExtraModuleMapSearch);
   return Module;
 }
 
-Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName) {
+Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
+   bool AllowExtraModuleMapSearch) {
   Module *Module = nullptr;
 
   // Look through the various header search paths to load any available module
@@ -281,8 +283,9 @@
   continue;
 
 // Load all module maps in the immediate subdirectories of this search
-// directory.
-loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+// directory if ModuleName was from @import.
+if (AllowExtraModuleMapSearch)
+  loadSubdirectoryModuleMaps(SearchDirs[Idx]);
 
 // Look again for the module.
 Module = ModMap.findModule(ModuleName);
Index: cfe/trunk/lib/Frontend/CompilerInstance.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp
@@ -1653,8 +1653,10 @@
 // Retrieve the cached top-level module.
 Module = Known->second;
   } else if (ModuleName == getLangOpts().CurrentModule) {
-// This is the module we're building. 
-Module = PP->getHeaderSearchInfo().lookupModule(ModuleName);
+// This is the module we're building.
+Module = PP->getHeaderSearchInfo().lookupModule(
+ModuleName, /*AllowSearch*/ true,
+/*AllowExtraModuleMapSearch*/ !IsInclusionDirective);
 /// FIXME: perhaps we should (a) look for a module using the module name
 //  to file map (PrebuiltModuleFiles) and (b) diagnose if still not found?
 //if (Module == nullptr) {
@@ -1666,7 +1668,8 @@
 Known = KnownModules.insert(std::make_

[PATCH] D36209: [Bash-autocompletion] Add comment to test so that it is easier to fix

2017-08-01 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

clang/test/Driver/autocomplete.c is a test for --autocomplete, and this
test might break if people add/modify flags or HelpText. So I've add
comment for future developers so that they can fix this file according
to the change they had made.


https://reviews.llvm.org/D36209

Files:
  clang/test/Driver/autocomplete.c


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -1,3 +1,7 @@
+// Test for --autocompletion flag, which is a API used for shell 
autocompletion.
+// If this test had broke due to adding/modifying flags or changing HelpText,
+// please modify this file according to the change you have made on flags used 
in this file.
+
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
 // RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -1,3 +1,7 @@
+// Test for --autocompletion flag, which is a API used for shell autocompletion.
+// If this test had broke due to adding/modifying flags or changing HelpText,
+// please modify this file according to the change you have made on flags used in this file.
+
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
 // RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36209: [Bash-autocompletion] Add comment to test so that it is easier to fix

2017-08-01 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 109277.
yamaguchi added a comment.

Update diff.


https://reviews.llvm.org/D36209

Files:
  clang/test/Driver/autocomplete.c


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -1,3 +1,8 @@
+// Test for --autocompletion flag, which is a API used for shell 
autocompletion.
+// If this test had broke due to adding/modifying flags or changing HelpText,
+// please modify this file according to the change you have made on flags
+// used in this file.
+
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
 // RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -1,3 +1,8 @@
+// Test for --autocompletion flag, which is a API used for shell autocompletion.
+// If this test had broke due to adding/modifying flags or changing HelpText,
+// please modify this file according to the change you have made on flags
+// used in this file.
+
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
 // RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36209: [Bash-autocompletion] Add comment to test so that it is easier to fix

2017-08-01 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added a comment.

@ruiu 
This test will break for instance, when someone add new value to 
mrelocation-model because values has to be shown in row 78- 83 order, or when 
someone made a new flags which start with `-Wno-invalid-pp-` because in row 96 
only -Wno-invalid-pp-token is expected for this prefix.


https://reviews.llvm.org/D36209



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


[PATCH] D36209: [Bash-autocompletion] Add comment to test so that it is easier to fix

2017-08-01 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 109281.
yamaguchi added a comment.

Modified comment.


https://reviews.llvm.org/D36209

Files:
  clang/test/Driver/autocomplete.c


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -1,3 +1,7 @@
+// Test for the --autocompletion flag, which is an API used for shell
+// autocompletion. You may have to update tests in this file when you
+// add/modify adding/modifying flags or changing HelpText.
+
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
 // RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -1,3 +1,7 @@
+// Test for the --autocompletion flag, which is an API used for shell
+// autocompletion. You may have to update tests in this file when you
+// add/modify adding/modifying flags or changing HelpText.
+
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
 // RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36209: [Bash-autocompletion] Add comment to test so that it is easier to fix

2017-08-02 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 109283.
yamaguchi added a comment.

Fixed typo.


https://reviews.llvm.org/D36209

Files:
  clang/test/Driver/autocomplete.c


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -1,3 +1,7 @@
+// Test for the --autocompletion flag, which is an API used for shell
+// autocompletion. You may have to update tests in this file when you
+// add/modify flags, change HelpTexts or the values of some flags.
+
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
 // RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -1,3 +1,7 @@
+// Test for the --autocompletion flag, which is an API used for shell
+// autocompletion. You may have to update tests in this file when you
+// add/modify flags, change HelpTexts or the values of some flags.
+
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
 // RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36209: [Bash-autocompletion] Add comment to test so that it is easier to fix

2017-08-02 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309794: [Bash-autocompletion] Add comment to test so that it 
is easier to fix (authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D36209?vs=109283&id=109285#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36209

Files:
  cfe/trunk/test/Driver/autocomplete.c


Index: cfe/trunk/test/Driver/autocomplete.c
===
--- cfe/trunk/test/Driver/autocomplete.c
+++ cfe/trunk/test/Driver/autocomplete.c
@@ -1,3 +1,7 @@
+// Test for the --autocompletion flag, which is an API used for shell
+// autocompletion. You may have to update tests in this file when you
+// add/modify flags, change HelpTexts or the values of some flags.
+
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
 // RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD


Index: cfe/trunk/test/Driver/autocomplete.c
===
--- cfe/trunk/test/Driver/autocomplete.c
+++ cfe/trunk/test/Driver/autocomplete.c
@@ -1,3 +1,7 @@
+// Test for the --autocompletion flag, which is an API used for shell
+// autocompletion. You may have to update tests in this file when you
+// add/modify flags, change HelpTexts or the values of some flags.
+
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
 // RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36567: [Bash-autocompletion] Add --autocomplete flag to 5.0 release notes

2017-08-09 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

I thought we should add this information to release notes, because we
added a new flag to clang driver.


https://reviews.llvm.org/D36567

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -61,7 +61,7 @@
 New Compiler Flags
 --
 
-The option 
+- --autocomplete was implemented to obtain a list of flags and its arguments. 
This is used for shell autocompletion.
 
 Deprecated Compiler Flags
 -


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -61,7 +61,7 @@
 New Compiler Flags
 --
 
-The option 
+- --autocomplete was implemented to obtain a list of flags and its arguments. This is used for shell autocompletion.
 
 Deprecated Compiler Flags
 -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36567: [Bash-autocompletion] Add --autocomplete flag to 5.0 release notes

2017-08-11 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310700: [Bash-autocompletion] Add --autocomplete flag to 5.0 
release notes (authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D36567?vs=110518&id=110679#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36567

Files:
  cfe/trunk/docs/ReleaseNotes.rst


Index: cfe/trunk/docs/ReleaseNotes.rst
===
--- cfe/trunk/docs/ReleaseNotes.rst
+++ cfe/trunk/docs/ReleaseNotes.rst
@@ -75,7 +75,7 @@
 New Compiler Flags
 --
 
-The option 
+- --autocomplete was implemented to obtain a list of flags and its arguments. 
This is used for shell autocompletion.
 
 Deprecated Compiler Flags
 -


Index: cfe/trunk/docs/ReleaseNotes.rst
===
--- cfe/trunk/docs/ReleaseNotes.rst
+++ cfe/trunk/docs/ReleaseNotes.rst
@@ -75,7 +75,7 @@
 New Compiler Flags
 --
 
-The option 
+- --autocomplete was implemented to obtain a list of flags and its arguments. This is used for shell autocompletion.
 
 Deprecated Compiler Flags
 -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36782: [Bash-autocompletion] Add support for static analyzer flags

2017-08-15 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
Herald added a subscriber: hiraditya.

This is a patch for clang autocomplete feature.

It will collect values which -analyzer-checker takes, which is defined in
clang/StaticAnalyzer/Checkers/Checkers.inc, dynamically.
First, from ValuesCode class in Options.td, TableGen will generate C++
code in Options.inc. Options.inc will be included in DriverOptions.cpp, and
calls OptTable's addValues function. addValues function will add second
argument to Option's Values class. Values contains string like "foo,bar,.."
which is handed to Values class
in OptTable.


https://reviews.llvm.org/D36782

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/Option/OptTable.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -298,5 +298,25 @@
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
+
+  OS << "\n";
+  OS << "#ifdef OPTTABLE_ARG_INIT\n";
+  OS << "//\n";
+  OS << "// Option Values\n\n";
+  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
+const Record &R = *Opts[I];
+if (!isa(R.getValueInit("ValuesCode"))) {
+  OS << R.getValueAsString("ValuesCode");
+  OS << "\n";
+  for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
+OS << "Opt.addValues(";
+std::string S = (Pref + R.getValueAsString("Name")).str();
+write_cstring(OS, S);
+OS << ", Values);";
+  }
+}
+  }
+  OS << "\n";
+  OS << "#endif // OPTTABLE_ARG_INIT\n";
 }
 } // end namespace llvm
Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -196,7 +196,7 @@
 
 // Returns true if one of the Prefixes + In.Names matches Option
 static bool optionMatches(const OptTable::Info &In, StringRef Option) {
-  if (In.Values && In.Prefixes)
+  if (In.Prefixes)
 for (size_t I = 0; In.Prefixes[I]; I++)
   if (Option == std::string(In.Prefixes[I]) + In.Name)
 return true;
@@ -209,8 +209,9 @@
 std::vector
 OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const {
   // Search all options and return possible values.
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
-if (!optionMatches(In, Option))
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
+if (!In.Values || !optionMatches(In, Option))
   continue;
 
 SmallVector Candidates;
@@ -228,7 +229,8 @@
 std::vector
 OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
   std::vector Ret;
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
 if (!In.Prefixes || (!In.HelpText && !In.GroupID))
   continue;
 if (In.Flags & DisableFlags)
@@ -245,6 +247,14 @@
   return Ret;
 }
 
+void OptTable::addValues(const char *Option, const char *Values) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+Info &In = OptionInfos[I];
+if (optionMatches(In, Option))
+  In.Values = Values;
+  }
+}
+
 Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
unsigned FlagsToInclude,
unsigned FlagsToExclude) const {
@@ -256,8 +266,8 @@
   if (isInput(PrefixesUnion, Str))
 return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
 
-  const Info *Start = OptionInfos.begin() + FirstSearchableIndex;
-  const Info *End = OptionInfos.end();
+  const Info *Start = OptionInfos.data() + FirstSearchableIndex;
+  const Info *End = OptionInfos.data() + OptionInfos.size();
   StringRef Name = StringRef(Str).ltrim(PrefixChars);
 
   // Search for the first next option which could be a prefix.
Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -58,7 +58,7 @@
 
 private:
   /// \brief The static option information table.
-  ArrayRef OptionInfos;
+  std::vector OptionInfos;
   bool IgnoreCase;
 
   unsigned TheInputOptionID = 0;
@@ -143,6 +143,15 @@
   std::vector findByPrefix(StringRef Cur,
 unsigned short DisableFlags) const;
 
+  /// Add Values to Option's Values class
+  ///
+  /// \param [in] Option - Prefix + Name of the flag which Values will be
+  //  changed
+  /// \param [in] Values - String of Values seperated by ",", such as
+  //  "foo, bar..", where foo and bar is the ar

[PATCH] D36782: [Bash-autocompletion] Add support for static analyzer flags

2017-08-16 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 111318.
yamaguchi marked 7 inline comments as done.
yamaguchi added a comment.

Update diff according to Raphael's comments.


https://reviews.llvm.org/D36782

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/Option/OptTable.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -298,5 +298,29 @@
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
+
+  OS << "\n";
+  OS << "#ifdef OPTTABLE_ARG_INIT\n";
+  OS << "//\n";
+  OS << "// Option Values\n\n";
+  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
+const Record &R = *Opts[I];
+if (!isa(R.getValueInit("ValuesCode"))) {
+  OS << "{\n";
+  OS << R.getValueAsString("ValuesCode");
+  OS << "\n";
+  for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
+OS << "assert(";
+OS << "Opt.addValues(";
+std::string S = (Pref + R.getValueAsString("Name")).str();
+write_cstring(OS, S);
+OS << ", Values)";
+OS << ");\n";
+  }
+  OS << "}\n";
+}
+  }
+  OS << "\n";
+  OS << "#endif // OPTTABLE_ARG_INIT\n";
 }
 } // end namespace llvm
Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -196,7 +196,7 @@
 
 // Returns true if one of the Prefixes + In.Names matches Option
 static bool optionMatches(const OptTable::Info &In, StringRef Option) {
-  if (In.Values && In.Prefixes)
+  if (In.Prefixes)
 for (size_t I = 0; In.Prefixes[I]; I++)
   if (Option == std::string(In.Prefixes[I]) + In.Name)
 return true;
@@ -209,8 +209,9 @@
 std::vector
 OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const {
   // Search all options and return possible values.
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
-if (!optionMatches(In, Option))
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
+if (!In.Values || !optionMatches(In, Option))
   continue;
 
 SmallVector Candidates;
@@ -228,7 +229,8 @@
 std::vector
 OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
   std::vector Ret;
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
 if (!In.Prefixes || (!In.HelpText && !In.GroupID))
   continue;
 if (In.Flags & DisableFlags)
@@ -245,6 +247,17 @@
   return Ret;
 }
 
+bool OptTable::addValues(const char *Option, const char *Values) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+Info &In = OptionInfos[I];
+if (optionMatches(In, Option)) {
+  In.Values = Values;
+  return true;
+}
+  }
+  return false;
+}
+
 Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
unsigned FlagsToInclude,
unsigned FlagsToExclude) const {
@@ -256,8 +269,8 @@
   if (isInput(PrefixesUnion, Str))
 return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
 
-  const Info *Start = OptionInfos.begin() + FirstSearchableIndex;
-  const Info *End = OptionInfos.end();
+  const Info *Start = OptionInfos.data() + FirstSearchableIndex;
+  const Info *End = OptionInfos.data() + OptionInfos.size();
   StringRef Name = StringRef(Str).ltrim(PrefixChars);
 
   // Search for the first next option which could be a prefix.
Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -57,8 +57,8 @@
   };
 
 private:
-  /// \brief The static option information table.
-  ArrayRef OptionInfos;
+  /// \brief The non-static option information table.
+  std::vector OptionInfos;
   bool IgnoreCase;
 
   unsigned TheInputOptionID = 0;
@@ -143,6 +143,17 @@
   std::vector findByPrefix(StringRef Cur,
 unsigned short DisableFlags) const;
 
+  /// Add Values to Option's Values class
+  ///
+  /// \param [in] Option - Prefix + Name of the flag which Values will be
+  ///  changed. For example, "-analyzer-checker".
+  /// \param [in] Values - String of Values seperated by ",", such as
+  ///  "foo, bar..", where foo and bar is the argument which the Option flag
+  //  takes
+  ///
+  /// \return true in success, and false in fail.
+  bool addValues(const char *Option, const char *Values);
+
   /// \brief Parse a single argum

[PATCH] D36782: [Bash-autocompletion] Add support for static analyzer flags

2017-08-16 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 111457.
yamaguchi marked 2 inline comments as done.
yamaguchi added a comment.

Update diff.


https://reviews.llvm.org/D36782

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/Option/OptTable.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -298,5 +298,30 @@
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
+
+  OS << "\n";
+  OS << "#ifdef OPTTABLE_ARG_INIT\n";
+  OS << "//\n";
+  OS << "// Option Values\n\n";
+  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
+const Record &R = *Opts[I];
+if (!isa(R.getValueInit("ValuesCode"))) {
+  OS << "{\n";
+  OS << R.getValueAsString("ValuesCode");
+  OS << "\n";
+  for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
+OS << "bool ValuesWereAdded = ";
+OS << "Opt.addValues(";
+std::string S = (Pref + R.getValueAsString("Name")).str();
+write_cstring(OS, S);
+OS << ", Values);\n";
+OS << "(void)ValuesWereAdded;\nassert(ValuesWereAdded &&";
+OS << " \"Couldn't add values to OptTable!\");\n";
+  }
+  OS << "}\n";
+}
+  }
+  OS << "\n";
+  OS << "#endif // OPTTABLE_ARG_INIT\n";
 }
 } // end namespace llvm
Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -196,7 +196,7 @@
 
 // Returns true if one of the Prefixes + In.Names matches Option
 static bool optionMatches(const OptTable::Info &In, StringRef Option) {
-  if (In.Values && In.Prefixes)
+  if (In.Prefixes)
 for (size_t I = 0; In.Prefixes[I]; I++)
   if (Option == std::string(In.Prefixes[I]) + In.Name)
 return true;
@@ -209,8 +209,9 @@
 std::vector
 OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const {
   // Search all options and return possible values.
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
-if (!optionMatches(In, Option))
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
+if (!In.Values || !optionMatches(In, Option))
   continue;
 
 SmallVector Candidates;
@@ -228,7 +229,8 @@
 std::vector
 OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
   std::vector Ret;
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
 if (!In.Prefixes || (!In.HelpText && !In.GroupID))
   continue;
 if (In.Flags & DisableFlags)
@@ -245,6 +247,17 @@
   return Ret;
 }
 
+bool OptTable::addValues(const char *Option, const char *Values) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+Info &In = OptionInfos[I];
+if (optionMatches(In, Option)) {
+  In.Values = Values;
+  return true;
+}
+  }
+  return false;
+}
+
 Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
unsigned FlagsToInclude,
unsigned FlagsToExclude) const {
@@ -256,8 +269,8 @@
   if (isInput(PrefixesUnion, Str))
 return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
 
-  const Info *Start = OptionInfos.begin() + FirstSearchableIndex;
-  const Info *End = OptionInfos.end();
+  const Info *Start = OptionInfos.data() + FirstSearchableIndex;
+  const Info *End = OptionInfos.data() + OptionInfos.size();
   StringRef Name = StringRef(Str).ltrim(PrefixChars);
 
   // Search for the first next option which could be a prefix.
Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -57,8 +57,8 @@
   };
 
 private:
-  /// \brief The static option information table.
-  ArrayRef OptionInfos;
+  /// \brief The option information table.
+  std::vector OptionInfos;
   bool IgnoreCase;
 
   unsigned TheInputOptionID = 0;
@@ -143,6 +143,17 @@
   std::vector findByPrefix(StringRef Cur,
 unsigned short DisableFlags) const;
 
+  /// Add Values to Option's Values class
+  ///
+  /// \param [in] Option - Prefix + Name of the flag which Values will be
+  ///  changed. For example, "-analyzer-checker".
+  /// \param [in] Values - String of Values seperated by ",", such as
+  ///  "foo, bar..", where foo and bar is the argument which the Option flag
+  //  takes
+  ///
+  /// \return true in success, and false in fail.
+  bool addVal

[PATCH] D36782: [Bash-autocompletion] Add support for static analyzer flags

2017-08-16 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added a comment.

@ruiu 
I understand your concern. However by doing this (rather than building 
functions for each flag), we will be able to get all information in OptTable 
itself. It is true that this is quite fragile, but adding ValuesCode to new 
flag is not complicated, so I believe overall it's fine.


https://reviews.llvm.org/D36782



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


[PATCH] D36820: [Bash-autocompletion] Add support for -std=

2017-08-16 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

Add support for autocompleting values of -std= by including
LangStandards.def. This patch relies on https://reviews.llvm.org/D36782, and is 
using two-stage
code generation.


https://reviews.llvm.org/D36820

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/autocomplete.c
  llvm/utils/TableGen/OptParserEmitter.cpp


Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -303,14 +303,15 @@
   OS << "#ifdef OPTTABLE_ARG_INIT\n";
   OS << "//\n";
   OS << "// Option Values\n\n";
+  OS << "bool ValuesWereAdded;\n";
   for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
 const Record &R = *Opts[I];
 if (!isa(R.getValueInit("ValuesCode"))) {
   OS << "{\n";
   OS << R.getValueAsString("ValuesCode");
   OS << "\n";
   for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
-OS << "bool ValuesWereAdded = ";
+OS << "ValuesWereAdded = ";
 OS << "Opt.addValues(";
 std::string S = (Pref + R.getValueAsString("Name")).str();
 write_cstring(OS, S);
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -95,3 +95,5 @@
 // NOWARNING: -Wno-invalid-pp-token
 // RUN: %clang --autocomplete=-analyzer-checker, | FileCheck %s 
-check-prefix=ANALYZER
 // ANALYZER: unix.Malloc
+// RUN: %clang --autocomplete=-std=, | FileCheck %s -check-prefix=STDVAL
+// STDVAL: c99
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2249,7 +2249,14 @@
 def static : Flag<["-", "--"], "static">, Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
-  Group, HelpText<"Language standard to compile for">;
+  Group, HelpText<"Language standard to compile for">,
+  ValuesCode<[{
+const char* Values =
+#define LANGSTANDARD(id, name, lang, desc, features) name ","
+#define LANGSTANDARD_ALIAS(id, alias) alias ","
+#include "clang/Frontend/LangStandards.def"
+;
+  }]>;
 def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>,
   HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">;
 def sub__library : JoinedOrSeparate<["-"], "sub_library">;


Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -303,14 +303,15 @@
   OS << "#ifdef OPTTABLE_ARG_INIT\n";
   OS << "//\n";
   OS << "// Option Values\n\n";
+  OS << "bool ValuesWereAdded;\n";
   for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
 const Record &R = *Opts[I];
 if (!isa(R.getValueInit("ValuesCode"))) {
   OS << "{\n";
   OS << R.getValueAsString("ValuesCode");
   OS << "\n";
   for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
-OS << "bool ValuesWereAdded = ";
+OS << "ValuesWereAdded = ";
 OS << "Opt.addValues(";
 std::string S = (Pref + R.getValueAsString("Name")).str();
 write_cstring(OS, S);
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -95,3 +95,5 @@
 // NOWARNING: -Wno-invalid-pp-token
 // RUN: %clang --autocomplete=-analyzer-checker, | FileCheck %s -check-prefix=ANALYZER
 // ANALYZER: unix.Malloc
+// RUN: %clang --autocomplete=-std=, | FileCheck %s -check-prefix=STDVAL
+// STDVAL: c99
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2249,7 +2249,14 @@
 def static : Flag<["-", "--"], "static">, Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
-  Group, HelpText<"Language standard to compile for">;
+  Group, HelpText<"Language standard to compile for">,
+  ValuesCode<[{
+const char* Values =
+#define LANGSTANDARD(id, name, lang, desc, features) name ","
+#define LANGSTANDARD_ALIAS(id, alias) alias ","
+#include "clang/Frontend/LangStandards.def"
+;
+  }]>;
 def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>,
   HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">;
 def sub__library : JoinedOrSeparate<["-"], "sub_library">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bi

[PATCH] D36782: [Bash-autocompletion] Add support for static analyzer flags

2017-08-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 111547.
yamaguchi marked 2 inline comments as done.
yamaguchi added a comment.

Update diff.


https://reviews.llvm.org/D36782

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/Option/OptTable.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -298,5 +298,30 @@
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
+
+  OS << "\n";
+  OS << "#ifdef OPTTABLE_ARG_INIT\n";
+  OS << "//\n";
+  OS << "// Option Values\n\n";
+  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
+const Record &R = *Opts[I];
+if (!isa(R.getValueInit("ValuesCode"))) {
+  OS << "{\n";
+  OS << R.getValueAsString("ValuesCode");
+  OS << "\n";
+  for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
+OS << "bool ValuesWereAdded = ";
+OS << "Opt.addValues(";
+std::string S = (Pref + R.getValueAsString("Name")).str();
+write_cstring(OS, S);
+OS << ", Values);\n";
+OS << "(void)ValuesWereAdded;\nassert(ValuesWereAdded &&";
+OS << " \"Couldn't add values to OptTable!\");\n";
+  }
+  OS << "}\n";
+}
+  }
+  OS << "\n";
+  OS << "#endif // OPTTABLE_ARG_INIT\n";
 }
 } // end namespace llvm
Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -196,7 +196,7 @@
 
 // Returns true if one of the Prefixes + In.Names matches Option
 static bool optionMatches(const OptTable::Info &In, StringRef Option) {
-  if (In.Values && In.Prefixes)
+  if (In.Prefixes)
 for (size_t I = 0; In.Prefixes[I]; I++)
   if (Option == std::string(In.Prefixes[I]) + In.Name)
 return true;
@@ -209,8 +209,9 @@
 std::vector
 OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const {
   // Search all options and return possible values.
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
-if (!optionMatches(In, Option))
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
+if (!In.Values || !optionMatches(In, Option))
   continue;
 
 SmallVector Candidates;
@@ -228,7 +229,8 @@
 std::vector
 OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
   std::vector Ret;
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
 if (!In.Prefixes || (!In.HelpText && !In.GroupID))
   continue;
 if (In.Flags & DisableFlags)
@@ -245,6 +247,17 @@
   return Ret;
 }
 
+bool OptTable::addValues(const char *Option, const char *Values) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+Info &In = OptionInfos[I];
+if (optionMatches(In, Option)) {
+  In.Values = Values;
+  return true;
+}
+  }
+  return false;
+}
+
 Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
unsigned FlagsToInclude,
unsigned FlagsToExclude) const {
@@ -256,8 +269,8 @@
   if (isInput(PrefixesUnion, Str))
 return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
 
-  const Info *Start = OptionInfos.begin() + FirstSearchableIndex;
-  const Info *End = OptionInfos.end();
+  const Info *Start = OptionInfos.data() + FirstSearchableIndex;
+  const Info *End = OptionInfos.data() + OptionInfos.size();
   StringRef Name = StringRef(Str).ltrim(PrefixChars);
 
   // Search for the first next option which could be a prefix.
Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -57,8 +57,8 @@
   };
 
 private:
-  /// \brief The static option information table.
-  ArrayRef OptionInfos;
+  /// \brief The option information table.
+  std::vector OptionInfos;
   bool IgnoreCase;
 
   unsigned TheInputOptionID = 0;
@@ -143,6 +143,17 @@
   std::vector findByPrefix(StringRef Cur,
 unsigned short DisableFlags) const;
 
+  /// Add Values to Option's Values class
+  ///
+  /// \param [in] Option - Prefix + Name of the flag which Values will be
+  ///  changed. For example, "-analyzer-checker".
+  /// \param [in] Values - String of Values seperated by ",", such as
+  ///  "foo, bar..", where foo and bar is the argument which the Option flag
+  //  takes
+  ///
+  /// \return true in success, and false in fail.
+  bool addVal

[PATCH] D36782: [Bash-autocompletion] Add support for static analyzer flags

2017-08-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 111548.
yamaguchi added a comment.

const char* Values -> const char *Values


https://reviews.llvm.org/D36782

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/lib/Driver/DriverOptions.cpp
  clang/test/Driver/autocomplete.c
  llvm/include/llvm/Option/OptParser.td
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/Option/OptTable.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -298,5 +298,30 @@
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
+
+  OS << "\n";
+  OS << "#ifdef OPTTABLE_ARG_INIT\n";
+  OS << "//\n";
+  OS << "// Option Values\n\n";
+  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
+const Record &R = *Opts[I];
+if (!isa(R.getValueInit("ValuesCode"))) {
+  OS << "{\n";
+  OS << R.getValueAsString("ValuesCode");
+  OS << "\n";
+  for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
+OS << "bool ValuesWereAdded = ";
+OS << "Opt.addValues(";
+std::string S = (Pref + R.getValueAsString("Name")).str();
+write_cstring(OS, S);
+OS << ", Values);\n";
+OS << "(void)ValuesWereAdded;\nassert(ValuesWereAdded &&";
+OS << " \"Couldn't add values to OptTable!\");\n";
+  }
+  OS << "}\n";
+}
+  }
+  OS << "\n";
+  OS << "#endif // OPTTABLE_ARG_INIT\n";
 }
 } // end namespace llvm
Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -196,7 +196,7 @@
 
 // Returns true if one of the Prefixes + In.Names matches Option
 static bool optionMatches(const OptTable::Info &In, StringRef Option) {
-  if (In.Values && In.Prefixes)
+  if (In.Prefixes)
 for (size_t I = 0; In.Prefixes[I]; I++)
   if (Option == std::string(In.Prefixes[I]) + In.Name)
 return true;
@@ -209,8 +209,9 @@
 std::vector
 OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const {
   // Search all options and return possible values.
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
-if (!optionMatches(In, Option))
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
+if (!In.Values || !optionMatches(In, Option))
   continue;
 
 SmallVector Candidates;
@@ -228,7 +229,8 @@
 std::vector
 OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
   std::vector Ret;
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
 if (!In.Prefixes || (!In.HelpText && !In.GroupID))
   continue;
 if (In.Flags & DisableFlags)
@@ -245,6 +247,17 @@
   return Ret;
 }
 
+bool OptTable::addValues(const char *Option, const char *Values) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+Info &In = OptionInfos[I];
+if (optionMatches(In, Option)) {
+  In.Values = Values;
+  return true;
+}
+  }
+  return false;
+}
+
 Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
unsigned FlagsToInclude,
unsigned FlagsToExclude) const {
@@ -256,8 +269,8 @@
   if (isInput(PrefixesUnion, Str))
 return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
 
-  const Info *Start = OptionInfos.begin() + FirstSearchableIndex;
-  const Info *End = OptionInfos.end();
+  const Info *Start = OptionInfos.data() + FirstSearchableIndex;
+  const Info *End = OptionInfos.data() + OptionInfos.size();
   StringRef Name = StringRef(Str).ltrim(PrefixChars);
 
   // Search for the first next option which could be a prefix.
Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -57,8 +57,8 @@
   };
 
 private:
-  /// \brief The static option information table.
-  ArrayRef OptionInfos;
+  /// \brief The option information table.
+  std::vector OptionInfos;
   bool IgnoreCase;
 
   unsigned TheInputOptionID = 0;
@@ -143,6 +143,17 @@
   std::vector findByPrefix(StringRef Cur,
 unsigned short DisableFlags) const;
 
+  /// Add Values to Option's Values class
+  ///
+  /// \param [in] Option - Prefix + Name of the flag which Values will be
+  ///  changed. For example, "-analyzer-checker".
+  /// \param [in] Values - String of Values seperated by ",", such as
+  ///  "foo, bar..", where foo and bar is the argument which the Option flag
+  //  takes
+  ///
+  /// \return true in success, and false in fail.
+  bool addValues(const char *

[PATCH] D36820: [Bash-autocompletion] Add support for -std=

2017-08-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 111549.
yamaguchi marked 2 inline comments as done.
yamaguchi added a comment.

Update diff.


https://reviews.llvm.org/D36820

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/autocomplete.c
  llvm/utils/TableGen/OptParserEmitter.cpp


Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -303,14 +303,15 @@
   OS << "#ifdef OPTTABLE_ARG_INIT\n";
   OS << "//\n";
   OS << "// Option Values\n\n";
+  OS << "bool ValuesWereAdded;\n";
   for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
 const Record &R = *Opts[I];
 if (!isa(R.getValueInit("ValuesCode"))) {
   OS << "{\n";
   OS << R.getValueAsString("ValuesCode");
   OS << "\n";
   for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
-OS << "bool ValuesWereAdded = ";
+OS << "ValuesWereAdded = ";
 OS << "Opt.addValues(";
 std::string S = (Pref + R.getValueAsString("Name")).str();
 write_cstring(OS, S);
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -95,3 +95,5 @@
 // NOWARNING: -Wno-invalid-pp-token
 // RUN: %clang --autocomplete=-analyzer-checker, | FileCheck %s 
-check-prefix=ANALYZER
 // ANALYZER: unix.Malloc
+// RUN: %clang --autocomplete=-std=, | FileCheck %s -check-prefix=STDVAL
+// STDVAL: c99
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2249,7 +2249,14 @@
 def static : Flag<["-", "--"], "static">, Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
-  Group, HelpText<"Language standard to compile for">;
+  Group, HelpText<"Language standard to compile for">,
+  ValuesCode<[{
+const char *Values =
+#define LANGSTANDARD(id, name, lang, desc, features) name ","
+#define LANGSTANDARD_ALIAS(id, alias) alias ","
+#include "clang/Frontend/LangStandards.def"
+;
+  }]>;
 def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>,
   HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">;
 def sub__library : JoinedOrSeparate<["-"], "sub_library">;


Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -303,14 +303,15 @@
   OS << "#ifdef OPTTABLE_ARG_INIT\n";
   OS << "//\n";
   OS << "// Option Values\n\n";
+  OS << "bool ValuesWereAdded;\n";
   for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
 const Record &R = *Opts[I];
 if (!isa(R.getValueInit("ValuesCode"))) {
   OS << "{\n";
   OS << R.getValueAsString("ValuesCode");
   OS << "\n";
   for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
-OS << "bool ValuesWereAdded = ";
+OS << "ValuesWereAdded = ";
 OS << "Opt.addValues(";
 std::string S = (Pref + R.getValueAsString("Name")).str();
 write_cstring(OS, S);
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -95,3 +95,5 @@
 // NOWARNING: -Wno-invalid-pp-token
 // RUN: %clang --autocomplete=-analyzer-checker, | FileCheck %s -check-prefix=ANALYZER
 // ANALYZER: unix.Malloc
+// RUN: %clang --autocomplete=-std=, | FileCheck %s -check-prefix=STDVAL
+// STDVAL: c99
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2249,7 +2249,14 @@
 def static : Flag<["-", "--"], "static">, Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
-  Group, HelpText<"Language standard to compile for">;
+  Group, HelpText<"Language standard to compile for">,
+  ValuesCode<[{
+const char *Values =
+#define LANGSTANDARD(id, name, lang, desc, features) name ","
+#define LANGSTANDARD_ALIAS(id, alias) alias ","
+#include "clang/Frontend/LangStandards.def"
+;
+  }]>;
 def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>,
   HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">;
 def sub__library : JoinedOrSeparate<["-"], "sub_library">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36820: [Bash-autocompletion] Add support for -std=

2017-08-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: llvm/utils/TableGen/OptParserEmitter.cpp:314
   for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
-OS << "bool ValuesWereAdded = ";
+OS << "ValuesWereAdded = ";
 OS << "Opt.addValues(";

ruiu wrote:
> Why do you have to change this? The previous code looks nicer.
Because I got an error that ValuesWereAdded are defined several times.


https://reviews.llvm.org/D36820



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


[PATCH] D36820: [Bash-autocompletion] Add support for -std=

2017-08-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 111611.
yamaguchi marked 3 inline comments as done.
yamaguchi added a comment.

Update diff.


https://reviews.llvm.org/D36820

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/autocomplete.c
  llvm/utils/TableGen/OptParserEmitter.cpp


Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -307,10 +307,11 @@
 const Record &R = *Opts[I];
 if (!isa(R.getValueInit("ValuesCode"))) {
   OS << "{\n";
+  OS << "bool ValuesWereAdded;\n";
   OS << R.getValueAsString("ValuesCode");
   OS << "\n";
   for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
-OS << "bool ValuesWereAdded = ";
+OS << "ValuesWereAdded = ";
 OS << "Opt.addValues(";
 std::string S = (Pref + R.getValueAsString("Name")).str();
 write_cstring(OS, S);
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -95,3 +95,5 @@
 // NOWARNING: -Wno-invalid-pp-token
 // RUN: %clang --autocomplete=-analyzer-checker, | FileCheck %s 
-check-prefix=ANALYZER
 // ANALYZER: unix.Malloc
+// RUN: %clang --autocomplete=-std=, | FileCheck %s -check-prefix=STDVAL
+// STDVAL: c99
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2249,7 +2249,14 @@
 def static : Flag<["-", "--"], "static">, Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
-  Group, HelpText<"Language standard to compile for">;
+  Group, HelpText<"Language standard to compile for">,
+  ValuesCode<[{
+const char *Values =
+#define LANGSTANDARD(id, name, lang, desc, features) name ","
+#define LANGSTANDARD_ALIAS(id, alias) alias ","
+#include "clang/Frontend/LangStandards.def"
+;
+  }]>;
 def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>,
   HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">;
 def sub__library : JoinedOrSeparate<["-"], "sub_library">;


Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -307,10 +307,11 @@
 const Record &R = *Opts[I];
 if (!isa(R.getValueInit("ValuesCode"))) {
   OS << "{\n";
+  OS << "bool ValuesWereAdded;\n";
   OS << R.getValueAsString("ValuesCode");
   OS << "\n";
   for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
-OS << "bool ValuesWereAdded = ";
+OS << "ValuesWereAdded = ";
 OS << "Opt.addValues(";
 std::string S = (Pref + R.getValueAsString("Name")).str();
 write_cstring(OS, S);
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -95,3 +95,5 @@
 // NOWARNING: -Wno-invalid-pp-token
 // RUN: %clang --autocomplete=-analyzer-checker, | FileCheck %s -check-prefix=ANALYZER
 // ANALYZER: unix.Malloc
+// RUN: %clang --autocomplete=-std=, | FileCheck %s -check-prefix=STDVAL
+// STDVAL: c99
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2249,7 +2249,14 @@
 def static : Flag<["-", "--"], "static">, Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
-  Group, HelpText<"Language standard to compile for">;
+  Group, HelpText<"Language standard to compile for">,
+  ValuesCode<[{
+const char *Values =
+#define LANGSTANDARD(id, name, lang, desc, features) name ","
+#define LANGSTANDARD_ALIAS(id, alias) alias ","
+#include "clang/Frontend/LangStandards.def"
+;
+  }]>;
 def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>,
   HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">;
 def sub__library : JoinedOrSeparate<["-"], "sub_library">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36820: [Bash-autocompletion] Add support for -std=

2017-08-18 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: llvm/utils/TableGen/OptParserEmitter.cpp:319-320
 OS << ", Values);\n";
 OS << "(void)ValuesWereAdded;\nassert(ValuesWereAdded &&";
 OS << " \"Couldn't add values to OptTable!\");\n";
   }

ruiu wrote:
> Can you split the string after each "\n"? It seems the current way of 
> splitting is somewhat arbitrary.
Those code are on review in D36782 and I've fixed it, so I think it's fine now 
:)


https://reviews.llvm.org/D36820



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


[PATCH] D36820: [Bash-autocompletion] Add support for -std=

2017-08-18 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 111804.
yamaguchi added a comment.

Update diff. Thank you for your comments!


https://reviews.llvm.org/D36820

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/autocomplete.c
  llvm/utils/TableGen/OptParserEmitter.cpp


Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -305,21 +305,22 @@
   OS << "// Option Values\n\n";
   for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
 const Record &R = *Opts[I];
-if (!isa(R.getValueInit("ValuesCode"))) {
-  OS << "{\n";
-  OS << R.getValueAsString("ValuesCode");
-  OS << "\n";
-  for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
-OS << "bool ValuesWereAdded = ";
-OS << "Opt.addValues(";
-std::string S = (Pref + R.getValueAsString("Name")).str();
-write_cstring(OS, S);
-OS << ", Values);\n";
-OS << "(void)ValuesWereAdded;\nassert(ValuesWereAdded &&";
-OS << " \"Couldn't add values to OptTable!\");\n";
+if (isa(R.getValueInit("ValuesCode")))
+  continue;
+OS << "{\n";
+OS << "bool ValuesWereAdded;\n";
+OS << R.getValueAsString("ValuesCode");
+OS << "\n";
+for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
+  OS << "ValuesWereAdded = Opt.addValues(";
+  std::string S = (Pref + R.getValueAsString("Name")).str();
+  write_cstring(OS, S);
+  OS << ", Values);\n";
+  OS << "(void)ValuesWereAdded;\n";
+  OS << "assert(ValuesWereAdded && \"Couldn't add values to "
+"OptTable!\");\n";
   }
   OS << "}\n";
-}
   }
   OS << "\n";
   OS << "#endif // OPTTABLE_ARG_INIT\n";
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -95,3 +95,5 @@
 // NOWARNING: -Wno-invalid-pp-token
 // RUN: %clang --autocomplete=-analyzer-checker, | FileCheck %s 
-check-prefix=ANALYZER
 // ANALYZER: unix.Malloc
+// RUN: %clang --autocomplete=-std=, | FileCheck %s -check-prefix=STDVAL
+// STDVAL: c99
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2249,7 +2249,14 @@
 def static : Flag<["-", "--"], "static">, Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
-  Group, HelpText<"Language standard to compile for">;
+  Group, HelpText<"Language standard to compile for">,
+  ValuesCode<[{
+const char *Values =
+#define LANGSTANDARD(id, name, lang, desc, features) name ","
+#define LANGSTANDARD_ALIAS(id, alias) alias ","
+#include "clang/Frontend/LangStandards.def"
+;
+  }]>;
 def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>,
   HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">;
 def sub__library : JoinedOrSeparate<["-"], "sub_library">;


Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -305,21 +305,22 @@
   OS << "// Option Values\n\n";
   for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
 const Record &R = *Opts[I];
-if (!isa(R.getValueInit("ValuesCode"))) {
-  OS << "{\n";
-  OS << R.getValueAsString("ValuesCode");
-  OS << "\n";
-  for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
-OS << "bool ValuesWereAdded = ";
-OS << "Opt.addValues(";
-std::string S = (Pref + R.getValueAsString("Name")).str();
-write_cstring(OS, S);
-OS << ", Values);\n";
-OS << "(void)ValuesWereAdded;\nassert(ValuesWereAdded &&";
-OS << " \"Couldn't add values to OptTable!\");\n";
+if (isa(R.getValueInit("ValuesCode")))
+  continue;
+OS << "{\n";
+OS << "bool ValuesWereAdded;\n";
+OS << R.getValueAsString("ValuesCode");
+OS << "\n";
+for (const std::string &Pref : R.getValueAsListOfStrings("Prefixes")) {
+  OS << "ValuesWereAdded = Opt.addValues(";
+  std::string S = (Pref + R.getValueAsString("Name")).str();
+  write_cstring(OS, S);
+  OS << ", Values);\n";
+  OS << "(void)ValuesWereAdded;\n";
+  OS << "assert(ValuesWereAdded && \"Couldn't add values to "
+"OptTable!\");\n";
   }
   OS << "}\n";
-}
   }
   OS << "\n";
   OS << "#endif // OPTTABLE_ARG_INIT\n";
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -95,3 +95,5

[PATCH] D36782: [Bash-autocompletion] Add support for static analyzer flags

2017-08-18 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added a comment.

@ruiu 
I addressed your comments in https://reviews.llvm.org/D36820, so please take a 
look at it. Thank you!


https://reviews.llvm.org/D36782



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


[PATCH] D36782: [Bash-autocompletion] Add support for static analyzer flags

2017-08-23 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
yamaguchi marked an inline comment as done.
Closed by commit rL311552: [Bash-autocompletion] Add support for static 
analyzer flags (authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D36782?vs=111548&id=112353#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36782

Files:
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/lib/Driver/DriverOptions.cpp
  cfe/trunk/test/Driver/autocomplete.c
  llvm/trunk/include/llvm/Option/OptParser.td
  llvm/trunk/include/llvm/Option/OptTable.h
  llvm/trunk/lib/Option/OptTable.cpp
  llvm/trunk/utils/TableGen/OptParserEmitter.cpp

Index: llvm/trunk/include/llvm/Option/OptParser.td
===
--- llvm/trunk/include/llvm/Option/OptParser.td
+++ llvm/trunk/include/llvm/Option/OptParser.td
@@ -93,6 +93,7 @@
   string HelpText = ?;
   string MetaVarName = ?;
   string Values = ?;
+  code ValuesCode = ?;
   list Flags = [];
   OptionGroup Group = ?;
   Option Alias = ?;
@@ -128,6 +129,7 @@
 class HelpText { string HelpText = text; }
 class MetaVarName { string MetaVarName = name; }
 class Values { string Values = value; }
+class ValuesCode { code ValuesCode = valuecode; }
 
 // Predefined options.
 
Index: llvm/trunk/include/llvm/Option/OptTable.h
===
--- llvm/trunk/include/llvm/Option/OptTable.h
+++ llvm/trunk/include/llvm/Option/OptTable.h
@@ -57,8 +57,8 @@
   };
 
 private:
-  /// \brief The static option information table.
-  ArrayRef OptionInfos;
+  /// \brief The option information table.
+  std::vector OptionInfos;
   bool IgnoreCase;
 
   unsigned TheInputOptionID = 0;
@@ -143,6 +143,17 @@
   std::vector findByPrefix(StringRef Cur,
 unsigned short DisableFlags) const;
 
+  /// Add Values to Option's Values class
+  ///
+  /// \param [in] Option - Prefix + Name of the flag which Values will be
+  ///  changed. For example, "-analyzer-checker".
+  /// \param [in] Values - String of Values seperated by ",", such as
+  ///  "foo, bar..", where foo and bar is the argument which the Option flag
+  ///  takes
+  ///
+  /// \return true in success, and false in fail.
+  bool addValues(const char *Option, const char *Values);
+
   /// \brief Parse a single argument; returning the new argument and
   /// updating Index.
   ///
Index: llvm/trunk/lib/Option/OptTable.cpp
===
--- llvm/trunk/lib/Option/OptTable.cpp
+++ llvm/trunk/lib/Option/OptTable.cpp
@@ -196,7 +196,7 @@
 
 // Returns true if one of the Prefixes + In.Names matches Option
 static bool optionMatches(const OptTable::Info &In, StringRef Option) {
-  if (In.Values && In.Prefixes)
+  if (In.Prefixes)
 for (size_t I = 0; In.Prefixes[I]; I++)
   if (Option == std::string(In.Prefixes[I]) + In.Name)
 return true;
@@ -209,8 +209,9 @@
 std::vector
 OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const {
   // Search all options and return possible values.
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
-if (!optionMatches(In, Option))
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
+if (!In.Values || !optionMatches(In, Option))
   continue;
 
 SmallVector Candidates;
@@ -228,7 +229,8 @@
 std::vector
 OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
   std::vector Ret;
-  for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+const Info &In = OptionInfos[I];
 if (!In.Prefixes || (!In.HelpText && !In.GroupID))
   continue;
 if (In.Flags & DisableFlags)
@@ -245,6 +247,17 @@
   return Ret;
 }
 
+bool OptTable::addValues(const char *Option, const char *Values) {
+  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
+Info &In = OptionInfos[I];
+if (optionMatches(In, Option)) {
+  In.Values = Values;
+  return true;
+}
+  }
+  return false;
+}
+
 Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
unsigned FlagsToInclude,
unsigned FlagsToExclude) const {
@@ -256,8 +269,8 @@
   if (isInput(PrefixesUnion, Str))
 return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
 
-  const Info *Start = OptionInfos.begin() + FirstSearchableIndex;
-  const Info *End = OptionInfos.end();
+  const Info *Start = OptionInfos.data() + FirstSearchableIndex;
+  const Info *End = OptionInfos.data() + OptionInfos.size();
   StringRef Name = StringRef(Str).ltrim(PrefixChars);
 
   // Search for the first next option which could be a prefix.
Index: llvm/trunk/utils/TableGen/OptParserEmitter.cpp
==

[PATCH] D39342: [Bash-autocompletion] Pass all flags in shell command-line to Clang

2017-10-26 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

Previously, we passed "#" to --autocomplete to indicate to enable cc1
flags. For example, when -cc1 or -Xclang was passed to bash, bash
executed `clang --autocomplete=#-`.

However, this was not a good implementation because it depends -Xclang
and -cc1 parsing to shell. So I changed this to pass all flags shell
has, so that Clang can handle them internally.

I'll leave exsisting testcase as it is inorder to test backward
compatibility.


https://reviews.llvm.org/D39342

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh

Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -25,11 +25,11 @@
 w2="${COMP_WORDS[$cword - 2]}"
   fi
 
-  # Clang want to know if -cc1 or -Xclang option is specified or not, because we don't want to show
-  # cc1 options otherwise.
-  if [[ "${COMP_WORDS[1]}" == "-cc1" || "$w1" == "-Xclang" ]]; then
-arg="#"
-  fi
+  # Pass all the current command-line flags to clang, so that clang can handle
+  # these internally.
+  for i in `seq 1 $(($cword-1))`; do
+arg="$arg${COMP_WORDS[$i]}:"
+  done
 
   # bash always separates '=' as a token even if there's no space before/after '='.
   # On the other hand, '=' is just a regular character for clang options that
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -4,7 +4,6 @@
 
 // Some corner cases.
 // RUN: %clang --autocomplete= | FileCheck %s -check-prefix=ALL_FLAGS
-// RUN: %clang --autocomplete=# | FileCheck %s -check-prefix=ALL_FLAGS
 // Let's pick some example flags that are hopefully unlikely to change.
 // ALL_FLAGS: -fast
 // ALL_FLAGS: -fastcp
@@ -93,10 +92,6 @@
 // MRELOCMODELALL-NEXT: ropi-rwpi
 // MRELOCMODELALL-NEXT: rwpi
 // MRELOCMODELALL-NEXT: static
-// RUN: %clang --autocomplete=-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CLANG
-// MRELOCMODEL_CLANG-NOT: -mrelocation-model
-// RUN: %clang --autocomplete=#-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CC1
-// MRELOCMODEL_CC1: -mrelocation-model
 // RUN: %clang --autocomplete=-Wma | FileCheck %s -check-prefix=WARNING
 // WARNING: -Wmacro-redefined
 // WARNING-NEXT: -Wmain
@@ -110,3 +105,16 @@
 // ANALYZER: unix.Malloc
 // RUN: %clang --autocomplete=-std=, | FileCheck %s -check-prefix=STDVAL
 // STDVAL: c99
+//
+// Clang shouldn't autocomplete CC1 options unless -cc1 or -Xclang were provided
+// RUN: %clang --autocomplete=-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CLANG
+// MRELOCMODEL_CLANG-NOT: -mrelocation-model
+// RUN: %clang --autocomplete=-Xclang:-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CC1
+// RUN: %clang --autocomplete=-cc1:-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CC1
+// MRELOCMODEL_CC1: -mrelocation-model
+// Make sure it ignores passed flags unlesss they are -Xclang or -cc1
+// RUN: %clang --autocomplete=foo:bar::-fsyn | FileCheck %s -check-prefix=FSYN-CORON
+// FSYN-CORON: -fsyntax-only
+// Check if they can autocomplete values with coron
+// RUN: %clang --autocomplete=foo::bar-fno-sanitize-coverage=,f | FileCheck %s -check-prefix=FNOSANICOVER-CORON
+// FNOSANICOVER-CORON: func
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1164,34 +1164,38 @@
 
   unsigned short DisableFlags =
   options::NoDriverOption | options::Unsupported | options::Ignored;
-  // We want to show cc1-only options only when clang is invoked as "clang
-  // -cc1". When clang is invoked as "clang -cc1", we add "#" to the beginning
-  // of an --autocomplete  option so that the clang driver can distinguish
-  // whether it is requested to show cc1-only options or not.
-  if (PassedFlags.size() > 0 && PassedFlags[0] == '#') {
-DisableFlags &= ~options::NoDriverOption;
-PassedFlags = PassedFlags.substr(1);
+
+  // Parse PassedFlags by ":" as all the command-line flags are passed to this
+  // function separated by ":"
+  StringRef TargetFlag = PassedFlags;
+  for (; TargetFlag.find(':') != StringRef::npos;) {
+StringRef CurFlag;
+std::tie(CurFlag, TargetFlag) = TargetFlag.split(":");
+// We want to show cc1-only options only when clang is invoked with -cc1 or
+// -Xclang.
+if (CurFlag == "-Xclang" || CurFlag == "-cc1")
+  DisableFlags &= ~options::NoDriverOption;
   }
 
-  if (PassedFlags.find(',') == StringRef::npos) {
+  if (TargetFlag.find(',') == StringRef::npos) {
 // If the flag is in the form of "--autocomplete=-foo",
 // we were requested to print out all option names that start with "-foo".
 // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
-SuggestedCo

[PATCH] D39342: [Bash-autocompletion] Pass all flags in shell command-line to Clang

2017-10-27 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:1171
+  StringRef TargetFlag = PassedFlags;
+  for (; TargetFlag.find(':') != StringRef::npos;) {
+StringRef CurFlag;

v.g.vassilev wrote:
> Why not a `while` loop?
I didn't have special reason, I'll change it to while if it fits better.


https://reviews.llvm.org/D39342



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


[PATCH] D39342: [Bash-autocompletion] Pass all flags in shell command-line to Clang

2017-11-03 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 121444.
yamaguchi added a comment.
Herald added a subscriber: hiraditya.

Update diff. Pass all flags just with "," including values.


https://reviews.llvm.org/D39342

Files:
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  llvm/lib/Option/OptTable.cpp

Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -219,7 +219,7 @@
 
 std::vector Result;
 for (StringRef Val : Candidates)
-  if (Val.startswith(Arg))
+  if (Val.startswith(Arg) && Arg.compare(Val))
 Result.push_back(Val);
 return Result;
   }
@@ -240,7 +240,7 @@
   std::string S = std::string(In.Prefixes[I]) + std::string(In.Name) + "\t";
   if (In.HelpText)
 S += In.HelpText;
-  if (StringRef(S).startswith(Cur))
+  if (StringRef(S).startswith(Cur) && S.compare(std::string(Cur) + "\t"))
 Ret.push_back(S);
 }
   }
Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -25,35 +25,16 @@
 w2="${COMP_WORDS[$cword - 2]}"
   fi
 
-  # Clang want to know if -cc1 or -Xclang option is specified or not, because we don't want to show
-  # cc1 options otherwise.
-  if [[ "${COMP_WORDS[1]}" == "-cc1" || "$w1" == "-Xclang" ]]; then
-arg="#"
-  fi
-
-  # bash always separates '=' as a token even if there's no space before/after '='.
-  # On the other hand, '=' is just a regular character for clang options that
-  # contain '='. For example, "-stdlib=" is defined as is, instead of "-stdlib" and "=".
-  # So, we need to partially undo bash tokenization here for integrity.
-  if [[ "$cur" == -* ]]; then
-# -foo
-arg="$arg$cur"
-  elif [[ "$w1" == -*  && "$cur" == '=' ]]; then
-# -foo=
-arg="$arg$w1=,"
-  elif [[ "$cur" == -*= ]]; then
-# -foo=
-arg="$arg$cur,"
-  elif [[ "$w1" == -* ]]; then
-# -foo  or -foo bar
-arg="$arg$w1,$cur"
-  elif [[ "$w2" == -* && "$w1" == '=' ]]; then
-# -foo=bar
-arg="$arg$w2=,$cur"
-  elif [[ ${cur: -1} != '=' && ${cur/=} != $cur ]]; then
-# -foo=bar
-arg="$arg${cur%=*}=,${cur#*=}"
-  fi
+  # Pass all the current command-line flags to clang, so that clang can handle
+  # these internally.
+  # '=' is separated differently by bash, so we have to concat them without ','
+  for i in `seq 1 $cword`; do
+if [[ $i == $cword || "${COMP_WORDS[$(($i+1))]}" == '=' ]]; then
+  arg="$arg${COMP_WORDS[$i]}"
+else
+  arg="$arg${COMP_WORDS[$i]},"
+fi
+  done
 
   # expand ~ to $HOME
   eval local path=${COMP_WORDS[0]}
@@ -67,7 +48,7 @@
 
   # When clang does not emit any possible autocompletion, or user pushed tab after " ",
   # just autocomplete files.
-  if [[ "$flags" == "$(echo -e '\n')" || "$arg" == "" ]]; then
+  if [[ "$flags" == "$(echo -e '\n')" ]]; then
 # If -foo= and there was no possible values, autocomplete files.
 [[ "$cur" == '=' || "$cur" == -*= ]] && cur=""
 _clang_filedir
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -3,21 +3,16 @@
 // add/modify flags, change HelpTexts or the values of some flags.
 
 // Some corner cases.
-// RUN: %clang --autocomplete= | FileCheck %s -check-prefix=ALL_FLAGS
-// RUN: %clang --autocomplete=# | FileCheck %s -check-prefix=ALL_FLAGS
-// Let's pick some example flags that are hopefully unlikely to change.
-// ALL_FLAGS: -fast
-// ALL_FLAGS: -fastcp
-// ALL_FLAGS: -fastf
 // Just test that this doesn't crash:
+// RUN: %clang --autocomplete=
 // RUN: %clang --autocomplete=,
 // RUN: %clang --autocomplete==
 // RUN: %clang --autocomplete=,,
 // RUN: %clang --autocomplete=-
 
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
-// RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD
+// RUN: %clang --autocomplete=-std | FileCheck %s -check-prefix=STD
 // STD: -std= Language standard to compile for
 // RUN: %clang --autocomplete=foo | FileCheck %s -check-prefix=FOO
 // FOO-NOT: foo
@@ -30,14 +25,14 @@
 // STDLIBALL-NEXT: platform
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
-// RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
+// RUN: %clang --autocomplete=-meabi | FileCheck %s -check-prefix=MEABIALL
 // MEABIALL: 4
 // MEABIALL-NEXT: 5
 // MEABIALL-NEXT: default
 // MEABIALL-NEXT: gnu
 // RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD
 // CLSTD: CL2.0
-// RUN: %clang --autocomplete=-cl-std=, | FileCheck %s -check-prefix=CLSTDALL
+// RUN: %clang --autocomplete=-cl-std= | FileCheck %s -check-prefix=C

[PATCH] D39342: [Bash-autocompletion] Pass all flags in shell command-line to Clang

2017-11-03 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 121449.
yamaguchi added a comment.

Made a trivial fix in the testcase


https://reviews.llvm.org/D39342

Files:
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  llvm/lib/Option/OptTable.cpp

Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -219,7 +219,7 @@
 
 std::vector Result;
 for (StringRef Val : Candidates)
-  if (Val.startswith(Arg))
+  if (Val.startswith(Arg) && Arg.compare(Val))
 Result.push_back(Val);
 return Result;
   }
@@ -240,7 +240,7 @@
   std::string S = std::string(In.Prefixes[I]) + std::string(In.Name) + "\t";
   if (In.HelpText)
 S += In.HelpText;
-  if (StringRef(S).startswith(Cur))
+  if (StringRef(S).startswith(Cur) && S.compare(std::string(Cur) + "\t"))
 Ret.push_back(S);
 }
   }
Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -25,35 +25,16 @@
 w2="${COMP_WORDS[$cword - 2]}"
   fi
 
-  # Clang want to know if -cc1 or -Xclang option is specified or not, because we don't want to show
-  # cc1 options otherwise.
-  if [[ "${COMP_WORDS[1]}" == "-cc1" || "$w1" == "-Xclang" ]]; then
-arg="#"
-  fi
-
-  # bash always separates '=' as a token even if there's no space before/after '='.
-  # On the other hand, '=' is just a regular character for clang options that
-  # contain '='. For example, "-stdlib=" is defined as is, instead of "-stdlib" and "=".
-  # So, we need to partially undo bash tokenization here for integrity.
-  if [[ "$cur" == -* ]]; then
-# -foo
-arg="$arg$cur"
-  elif [[ "$w1" == -*  && "$cur" == '=' ]]; then
-# -foo=
-arg="$arg$w1=,"
-  elif [[ "$cur" == -*= ]]; then
-# -foo=
-arg="$arg$cur,"
-  elif [[ "$w1" == -* ]]; then
-# -foo  or -foo bar
-arg="$arg$w1,$cur"
-  elif [[ "$w2" == -* && "$w1" == '=' ]]; then
-# -foo=bar
-arg="$arg$w2=,$cur"
-  elif [[ ${cur: -1} != '=' && ${cur/=} != $cur ]]; then
-# -foo=bar
-arg="$arg${cur%=*}=,${cur#*=}"
-  fi
+  # Pass all the current command-line flags to clang, so that clang can handle
+  # these internally.
+  # '=' is separated differently by bash, so we have to concat them without ','
+  for i in `seq 1 $cword`; do
+if [[ $i == $cword || "${COMP_WORDS[$(($i+1))]}" == '=' ]]; then
+  arg="$arg${COMP_WORDS[$i]}"
+else
+  arg="$arg${COMP_WORDS[$i]},"
+fi
+  done
 
   # expand ~ to $HOME
   eval local path=${COMP_WORDS[0]}
@@ -67,7 +48,7 @@
 
   # When clang does not emit any possible autocompletion, or user pushed tab after " ",
   # just autocomplete files.
-  if [[ "$flags" == "$(echo -e '\n')" || "$arg" == "" ]]; then
+  if [[ "$flags" == "$(echo -e '\n')" ]]; then
 # If -foo= and there was no possible values, autocomplete files.
 [[ "$cur" == '=' || "$cur" == -*= ]] && cur=""
 _clang_filedir
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -3,41 +3,36 @@
 // add/modify flags, change HelpTexts or the values of some flags.
 
 // Some corner cases.
-// RUN: %clang --autocomplete= | FileCheck %s -check-prefix=ALL_FLAGS
-// RUN: %clang --autocomplete=# | FileCheck %s -check-prefix=ALL_FLAGS
-// Let's pick some example flags that are hopefully unlikely to change.
-// ALL_FLAGS: -fast
-// ALL_FLAGS: -fastcp
-// ALL_FLAGS: -fastf
 // Just test that this doesn't crash:
+// RUN: %clang --autocomplete=
 // RUN: %clang --autocomplete=,
 // RUN: %clang --autocomplete==
 // RUN: %clang --autocomplete=,,
 // RUN: %clang --autocomplete=-
 
 // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
 // FSYN: -fsyntax-only
-// RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD
+// RUN: %clang --autocomplete=-std | FileCheck %s -check-prefix=STD
 // STD: -std= Language standard to compile for
 // RUN: %clang --autocomplete=foo | FileCheck %s -check-prefix=FOO
 // FOO-NOT: foo
 // RUN: %clang --autocomplete=-stdlib=,l | FileCheck %s -check-prefix=STDLIB
 // STDLIB: libc++
 // STDLIB-NEXT: libstdc++
-// RUN: %clang --autocomplete=-stdlib=, | FileCheck %s -check-prefix=STDLIBALL
+// RUN: %clang --autocomplete=-stdlib= | FileCheck %s -check-prefix=STDLIBALL
 // STDLIBALL: libc++
 // STDLIBALL-NEXT: libstdc++
 // STDLIBALL-NEXT: platform
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
-// RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
+// RUN: %clang --autocomplete=-meabi | FileCheck %s -check-prefix=MEABIALL
 // MEABIALL: 4
 // MEABIALL-NEXT: 5
 // MEABIALL-NEXT: default
 // MEABIALL-NEX

[PATCH] D40234: [AutoComplete] Stable sort autocomplete candidates to remove non-deterministic ordering

2017-11-19 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi accepted this revision.
yamaguchi added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


https://reviews.llvm.org/D40234



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


[PATCH] D31591: Fix a bug which access nullptr and cause segmentation fault

2017-04-03 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 93860.
yamaguchi added a comment.

Moved comment inside if (ExistingInit).


https://reviews.llvm.org/D31591

Files:
  SemaInit.cpp


Index: SemaInit.cpp
===
--- SemaInit.cpp
+++ SemaInit.cpp
@@ -2260,15 +2260,17 @@
   assert(StructuredList->getNumInits() == 1
  && "A union should never have more than one initializer!");
 
-  // We're about to throw away an initializer, emit warning.
-  SemaRef.Diag(D->getFieldLoc(),
-   diag::warn_initializer_overrides)
-<< D->getSourceRange();
   Expr *ExistingInit = StructuredList->getInit(0);
-  SemaRef.Diag(ExistingInit->getLocStart(),
-   diag::note_previous_initializer)
-<< /*FIXME:has side effects=*/0
-<< ExistingInit->getSourceRange();
+  if (ExistingInit) {
+// We're about to throw away an initializer, emit warning.
+SemaRef.Diag(D->getFieldLoc(),
+ diag::warn_initializer_overrides)
+  << D->getSourceRange();
+SemaRef.Diag(ExistingInit->getLocStart(),
+ diag::note_previous_initializer)
+  << /*FIXME:has side effects=*/0
+  << ExistingInit->getSourceRange();
+  }
 
   // remove existing initializer
   StructuredList->resizeInits(SemaRef.Context, 0);


Index: SemaInit.cpp
===
--- SemaInit.cpp
+++ SemaInit.cpp
@@ -2260,15 +2260,17 @@
   assert(StructuredList->getNumInits() == 1
  && "A union should never have more than one initializer!");
 
-  // We're about to throw away an initializer, emit warning.
-  SemaRef.Diag(D->getFieldLoc(),
-   diag::warn_initializer_overrides)
-<< D->getSourceRange();
   Expr *ExistingInit = StructuredList->getInit(0);
-  SemaRef.Diag(ExistingInit->getLocStart(),
-   diag::note_previous_initializer)
-<< /*FIXME:has side effects=*/0
-<< ExistingInit->getSourceRange();
+  if (ExistingInit) {
+// We're about to throw away an initializer, emit warning.
+SemaRef.Diag(D->getFieldLoc(),
+ diag::warn_initializer_overrides)
+  << D->getSourceRange();
+SemaRef.Diag(ExistingInit->getLocStart(),
+ diag::note_previous_initializer)
+  << /*FIXME:has side effects=*/0
+  << ExistingInit->getSourceRange();
+  }
 
   // remove existing initializer
   StructuredList->resizeInits(SemaRef.Context, 0);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31591: Fix a bug which access nullptr and cause segmentation fault

2017-04-03 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 93864.
yamaguchi added a comment.

Made unified diff for the testcase and SemaInit.cpp.


https://reviews.llvm.org/D31591

Files:
  SemaInit.cpp
  sema-segvcheck.c


Index: sema-segvcheck.c
===
--- sema-segvcheck.c
+++ sema-segvcheck.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only %s; test $? -eq 1
+
+typedef struct {
+  union {
+unsigned long long house;
+struct {
+  unsigned cat1;
+  unsigned cat2;
+};
+  };
+} struct_0;
+
+
+typedef struct {
+  union {
+struct {
+  union {
+unsigned cows;
+struct {
+  unsigned char c:1;
+};
+  };
+};
+  };
+
+  union {
+struct {
+  unsigned bird0;
+  unsigned bird1;
+};
+  };
+} struct_1;
+
+
+typedef struct {
+  struct_0 s0;
+  struct_1 s1[1];
+} struct_2;
+
+struct_2 s = {
+  .s0 = {
+.dog = 0x, // expected-error{{field designator}}
+  },
+
+  .s1[0] = {
+.cows = 0x5050,
+.c = 1,
+  },
+};
Index: SemaInit.cpp
===
--- SemaInit.cpp
+++ SemaInit.cpp
@@ -2260,15 +2260,17 @@
   assert(StructuredList->getNumInits() == 1
  && "A union should never have more than one initializer!");
 
-  // We're about to throw away an initializer, emit warning.
-  SemaRef.Diag(D->getFieldLoc(),
-   diag::warn_initializer_overrides)
-<< D->getSourceRange();
   Expr *ExistingInit = StructuredList->getInit(0);
-  SemaRef.Diag(ExistingInit->getLocStart(),
-   diag::note_previous_initializer)
-<< /*FIXME:has side effects=*/0
-<< ExistingInit->getSourceRange();
+  if (ExistingInit) {
+// We're about to throw away an initializer, emit warning.
+SemaRef.Diag(D->getFieldLoc(),
+ diag::warn_initializer_overrides)
+  << D->getSourceRange();
+SemaRef.Diag(ExistingInit->getLocStart(),
+ diag::note_previous_initializer)
+  << /*FIXME:has side effects=*/0
+  << ExistingInit->getSourceRange();
+  }
 
   // remove existing initializer
   StructuredList->resizeInits(SemaRef.Context, 0);


Index: sema-segvcheck.c
===
--- sema-segvcheck.c
+++ sema-segvcheck.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only %s; test $? -eq 1
+
+typedef struct {
+  union {
+unsigned long long house;
+struct {
+  unsigned cat1;
+  unsigned cat2;
+};
+  };
+} struct_0;
+
+
+typedef struct {
+  union {
+struct {
+  union {
+unsigned cows;
+struct {
+  unsigned char c:1;
+};
+  };
+};
+  };
+
+  union {
+struct {
+  unsigned bird0;
+  unsigned bird1;
+};
+  };
+} struct_1;
+
+
+typedef struct {
+  struct_0 s0;
+  struct_1 s1[1];
+} struct_2;
+
+struct_2 s = {
+  .s0 = {
+.dog = 0x, // expected-error{{field designator}}
+  },
+
+  .s1[0] = {
+.cows = 0x5050,
+.c = 1,
+  },
+};
Index: SemaInit.cpp
===
--- SemaInit.cpp
+++ SemaInit.cpp
@@ -2260,15 +2260,17 @@
   assert(StructuredList->getNumInits() == 1
  && "A union should never have more than one initializer!");
 
-  // We're about to throw away an initializer, emit warning.
-  SemaRef.Diag(D->getFieldLoc(),
-   diag::warn_initializer_overrides)
-<< D->getSourceRange();
   Expr *ExistingInit = StructuredList->getInit(0);
-  SemaRef.Diag(ExistingInit->getLocStart(),
-   diag::note_previous_initializer)
-<< /*FIXME:has side effects=*/0
-<< ExistingInit->getSourceRange();
+  if (ExistingInit) {
+// We're about to throw away an initializer, emit warning.
+SemaRef.Diag(D->getFieldLoc(),
+ diag::warn_initializer_overrides)
+  << D->getSourceRange();
+SemaRef.Diag(ExistingInit->getLocStart(),
+ diag::note_previous_initializer)
+  << /*FIXME:has side effects=*/0
+  << ExistingInit->getSourceRange();
+  }
 
   // remove existing initializer
   StructuredList->resizeInits(SemaRef.Context, 0);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31591: Fix a bug which access nullptr and cause segmentation fault

2017-04-04 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 94090.
yamaguchi added a comment.

Add relative path to the file.


https://reviews.llvm.org/D31591

Files:
  clang/test/Sema/sema-segvcheck.c
  lib/Sema/SemaInit.cpp


Index: clang/test/Sema/sema-segvcheck.c
===
--- clang/test/Sema/sema-segvcheck.c
+++ clang/test/Sema/sema-segvcheck.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only %s; test $? -eq 1
+
+typedef struct {
+  union {
+unsigned long long house;
+struct {
+  unsigned cat1;
+  unsigned cat2;
+};
+  };
+} struct_0;
+
+
+typedef struct {
+  union {
+struct {
+  union {
+unsigned cows;
+struct {
+  unsigned char c:1;
+};
+  };
+};
+  };
+
+  union {
+struct {
+  unsigned bird0;
+  unsigned bird1;
+};
+  };
+} struct_1;
+
+
+typedef struct {
+  struct_0 s0;
+  struct_1 s1[1];
+} struct_2;
+
+struct_2 s = {
+  .s0 = {
+.dog = 0x, // expected-error{{field designator}}
+  },
+
+  .s1[0] = {
+.cows = 0x5050,
+.c = 1,
+  },
+};
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -2269,15 +2269,17 @@
   assert(StructuredList->getNumInits() == 1
  && "A union should never have more than one initializer!");
 
-  // We're about to throw away an initializer, emit warning.
-  SemaRef.Diag(D->getFieldLoc(),
-   diag::warn_initializer_overrides)
-<< D->getSourceRange();
   Expr *ExistingInit = StructuredList->getInit(0);
-  SemaRef.Diag(ExistingInit->getLocStart(),
-   diag::note_previous_initializer)
-<< /*FIXME:has side effects=*/0
-<< ExistingInit->getSourceRange();
+  if (ExistingInit) {
+// We're about to throw away an initializer, emit warning.
+SemaRef.Diag(D->getFieldLoc(),
+ diag::warn_initializer_overrides)
+  << D->getSourceRange();
+SemaRef.Diag(ExistingInit->getLocStart(),
+ diag::note_previous_initializer)
+  << /*FIXME:has side effects=*/0
+  << ExistingInit->getSourceRange();
+  }
 
   // remove existing initializer
   StructuredList->resizeInits(SemaRef.Context, 0);


Index: clang/test/Sema/sema-segvcheck.c
===
--- clang/test/Sema/sema-segvcheck.c
+++ clang/test/Sema/sema-segvcheck.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only %s; test $? -eq 1
+
+typedef struct {
+  union {
+unsigned long long house;
+struct {
+  unsigned cat1;
+  unsigned cat2;
+};
+  };
+} struct_0;
+
+
+typedef struct {
+  union {
+struct {
+  union {
+unsigned cows;
+struct {
+  unsigned char c:1;
+};
+  };
+};
+  };
+
+  union {
+struct {
+  unsigned bird0;
+  unsigned bird1;
+};
+  };
+} struct_1;
+
+
+typedef struct {
+  struct_0 s0;
+  struct_1 s1[1];
+} struct_2;
+
+struct_2 s = {
+  .s0 = {
+.dog = 0x, // expected-error{{field designator}}
+  },
+
+  .s1[0] = {
+.cows = 0x5050,
+.c = 1,
+  },
+};
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -2269,15 +2269,17 @@
   assert(StructuredList->getNumInits() == 1
  && "A union should never have more than one initializer!");
 
-  // We're about to throw away an initializer, emit warning.
-  SemaRef.Diag(D->getFieldLoc(),
-   diag::warn_initializer_overrides)
-<< D->getSourceRange();
   Expr *ExistingInit = StructuredList->getInit(0);
-  SemaRef.Diag(ExistingInit->getLocStart(),
-   diag::note_previous_initializer)
-<< /*FIXME:has side effects=*/0
-<< ExistingInit->getSourceRange();
+  if (ExistingInit) {
+// We're about to throw away an initializer, emit warning.
+SemaRef.Diag(D->getFieldLoc(),
+ diag::warn_initializer_overrides)
+  << D->getSourceRange();
+SemaRef.Diag(ExistingInit->getLocStart(),
+ diag::note_previous_initializer)
+  << /*FIXME:has side effects=*/0
+  << ExistingInit->getSourceRange();
+  }
 
   // remove existing initializer
   StructuredList->resizeInits(SemaRef.Context, 0);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31591: Fix a bug which access nullptr and cause segmentation fault

2017-04-12 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 95064.
yamaguchi added a comment.

I've been trying to minimal the testcase, add comments to describe what it is 
testing, and fix styles of the testcase properly. 
However, I don't have clear idea what will be the best. I would like to ask for 
the advice.


https://reviews.llvm.org/D31591

Files:
  lib/Sema/SemaInit.cpp
  test/Sema/designated-initializers.c


Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -2269,15 +2269,17 @@
   assert(StructuredList->getNumInits() == 1
  && "A union should never have more than one initializer!");
 
-  // We're about to throw away an initializer, emit warning.
-  SemaRef.Diag(D->getFieldLoc(),
-   diag::warn_initializer_overrides)
-<< D->getSourceRange();
   Expr *ExistingInit = StructuredList->getInit(0);
-  SemaRef.Diag(ExistingInit->getLocStart(),
-   diag::note_previous_initializer)
-<< /*FIXME:has side effects=*/0
-<< ExistingInit->getSourceRange();
+  if (ExistingInit) {
+// We're about to throw away an initializer, emit warning.
+SemaRef.Diag(D->getFieldLoc(),
+ diag::warn_initializer_overrides)
+  << D->getSourceRange();
+SemaRef.Diag(ExistingInit->getLocStart(),
+ diag::note_previous_initializer)
+  << /*FIXME:has side effects=*/0
+  << ExistingInit->getSourceRange();
+  }
 
   // remove existing initializer
   StructuredList->resizeInits(SemaRef.Context, 0);
Index: test/Sema/designated-initializers.c
===
--- test/Sema/designated-initializers.c
+++ test/Sema/designated-initializers.c
@@ -351,3 +351,20 @@
   { { 'f', 'o', 'o' }, 1 },
   [0].L[4] = 'x' // no-warning
 };
+
+struct {
+  struct { } s1;
+  union {
+int a;
+int b;
+  } u1;
+} s = {
+  .s1 = {
+.x = 0, // expected-error{{field designator}}
+  },
+
+  .u1 = {
+.a = 0,
+.b = 0,
+  },
+};


Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -2269,15 +2269,17 @@
   assert(StructuredList->getNumInits() == 1
  && "A union should never have more than one initializer!");
 
-  // We're about to throw away an initializer, emit warning.
-  SemaRef.Diag(D->getFieldLoc(),
-   diag::warn_initializer_overrides)
-<< D->getSourceRange();
   Expr *ExistingInit = StructuredList->getInit(0);
-  SemaRef.Diag(ExistingInit->getLocStart(),
-   diag::note_previous_initializer)
-<< /*FIXME:has side effects=*/0
-<< ExistingInit->getSourceRange();
+  if (ExistingInit) {
+// We're about to throw away an initializer, emit warning.
+SemaRef.Diag(D->getFieldLoc(),
+ diag::warn_initializer_overrides)
+  << D->getSourceRange();
+SemaRef.Diag(ExistingInit->getLocStart(),
+ diag::note_previous_initializer)
+  << /*FIXME:has side effects=*/0
+  << ExistingInit->getSourceRange();
+  }
 
   // remove existing initializer
   StructuredList->resizeInits(SemaRef.Context, 0);
Index: test/Sema/designated-initializers.c
===
--- test/Sema/designated-initializers.c
+++ test/Sema/designated-initializers.c
@@ -351,3 +351,20 @@
   { { 'f', 'o', 'o' }, 1 },
   [0].L[4] = 'x' // no-warning
 };
+
+struct {
+  struct { } s1;
+  union {
+int a;
+int b;
+  } u1;
+} s = {
+  .s1 = {
+.x = 0, // expected-error{{field designator}}
+  },
+
+  .u1 = {
+.a = 0,
+.b = 0,
+  },
+};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31591: Fix a bug which access nullptr and cause segmentation fault

2017-04-13 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added a comment.

I don't have a commit access. Can you commit?


https://reviews.llvm.org/D31591



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


[PATCH] D32113: Add path from clang to doxygen document include header

2017-04-16 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added a comment.

Doxygen couldn't handle @abs_srcsdir@/../ , so I changed it to @abs_arcdir@/.. 
in Diff 95410, then it worked OK.
Document will now show the path of #include "include/clang/Sema/Sema.h" .


https://reviews.llvm.org/D32113



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


[PATCH] D32113: Add path from clang to doxygen document include header

2017-04-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 95434.
yamaguchi added a comment.

It worked, and this code generates #include "Sema/Sema.h".


https://reviews.llvm.org/D32113

Files:
  docs/doxygen.cfg.in


Index: docs/doxygen.cfg.in
===
--- docs/doxygen.cfg.in
+++ docs/doxygen.cfg.in
@@ -132,7 +132,7 @@
 # shortest path that makes the file name unique will be used
 # The default value is: YES.
 
-FULL_PATH_NAMES= NO
+FULL_PATH_NAMES= YES
 
 # The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
 # Stripping is only done if one of the specified strings matches the left-hand
@@ -144,16 +144,18 @@
 # will be relative from the directory where doxygen is started.
 # This tag requires that the tag FULL_PATH_NAMES is set to YES.
 
-STRIP_FROM_PATH= ../..
+STRIP_FROM_PATH= @abs_srcdir@/..
 
 # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
 # path mentioned in the documentation of a class, which tells the reader which
 # header file to include in order to use a class. If left blank only the name 
of
 # the header file containing the class definition is used. Otherwise one should
 # specify the list of include paths that are normally passed to the compiler
 # using the -I flag.
 
-STRIP_FROM_INC_PATH=
+STRIP_FROM_INC_PATH= @abs_srcdir@/..
+STRIP_FROM_INC_PATH+= @abs_srcdir@/../include/clang
+STRIP_FROM_INC_PATH+= @abs_srcdir@/../include/clang-c
 
 # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
 # less readable) file names. This can be useful is your file systems doesn't
@@ -513,7 +515,7 @@
 # files with double quotes in the documentation rather than with sharp 
brackets.
 # The default value is: NO.
 
-FORCE_LOCAL_INCLUDES   = NO
+FORCE_LOCAL_INCLUDES   = YES
 
 # If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
 # documentation for inline members.


Index: docs/doxygen.cfg.in
===
--- docs/doxygen.cfg.in
+++ docs/doxygen.cfg.in
@@ -132,7 +132,7 @@
 # shortest path that makes the file name unique will be used
 # The default value is: YES.
 
-FULL_PATH_NAMES= NO
+FULL_PATH_NAMES= YES
 
 # The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
 # Stripping is only done if one of the specified strings matches the left-hand
@@ -144,16 +144,18 @@
 # will be relative from the directory where doxygen is started.
 # This tag requires that the tag FULL_PATH_NAMES is set to YES.
 
-STRIP_FROM_PATH= ../..
+STRIP_FROM_PATH= @abs_srcdir@/..
 
 # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
 # path mentioned in the documentation of a class, which tells the reader which
 # header file to include in order to use a class. If left blank only the name of
 # the header file containing the class definition is used. Otherwise one should
 # specify the list of include paths that are normally passed to the compiler
 # using the -I flag.
 
-STRIP_FROM_INC_PATH=
+STRIP_FROM_INC_PATH= @abs_srcdir@/..
+STRIP_FROM_INC_PATH+= @abs_srcdir@/../include/clang
+STRIP_FROM_INC_PATH+= @abs_srcdir@/../include/clang-c
 
 # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
 # less readable) file names. This can be useful is your file systems doesn't
@@ -513,7 +515,7 @@
 # files with double quotes in the documentation rather than with sharp brackets.
 # The default value is: NO.
 
-FORCE_LOCAL_INCLUDES   = NO
+FORCE_LOCAL_INCLUDES   = YES
 
 # If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
 # documentation for inline members.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32113: Add path from clang to doxygen document include header

2017-04-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: docs/doxygen.cfg.in:158
+STRIP_FROM_INC_PATH+= @abs_srcdir@/../include/clang
+STRIP_FROM_INC_PATH+= @abs_srcdir@/../include/clang-c
 

v.g.vassilev wrote:
> We should be stripping `@abs_srcdir@/../include` because in reality the way 
> the user will include those files is via `#include "clang/Sema/Sema.h" for 
> instance.
Do you mean we should be stripping 
```
@abs_srcdir@/../include
```
rather than

```
@abs_srcdir@/..
@abs_srcdir@/../include/clang
@abs_srcdir@/../include/clang-c
```
?


https://reviews.llvm.org/D32113



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


[PATCH] D32113: Add path from clang to doxygen document include header

2017-04-17 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 95436.
yamaguchi added a comment.

This will generate #include "clang/Sema/Sema.h" .


https://reviews.llvm.org/D32113

Files:
  docs/doxygen.cfg.in


Index: docs/doxygen.cfg.in
===
--- docs/doxygen.cfg.in
+++ docs/doxygen.cfg.in
@@ -132,7 +132,7 @@
 # shortest path that makes the file name unique will be used
 # The default value is: YES.
 
-FULL_PATH_NAMES= NO
+FULL_PATH_NAMES= YES
 
 # The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
 # Stripping is only done if one of the specified strings matches the left-hand
@@ -144,16 +144,16 @@
 # will be relative from the directory where doxygen is started.
 # This tag requires that the tag FULL_PATH_NAMES is set to YES.
 
-STRIP_FROM_PATH= ../..
+STRIP_FROM_PATH= @abs_srcdir@/..
 
 # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
 # path mentioned in the documentation of a class, which tells the reader which
 # header file to include in order to use a class. If left blank only the name 
of
 # the header file containing the class definition is used. Otherwise one should
 # specify the list of include paths that are normally passed to the compiler
 # using the -I flag.
 
-STRIP_FROM_INC_PATH=
+STRIP_FROM_INC_PATH= @abs_srcdir@/../include
 
 # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
 # less readable) file names. This can be useful is your file systems doesn't
@@ -513,7 +513,7 @@
 # files with double quotes in the documentation rather than with sharp 
brackets.
 # The default value is: NO.
 
-FORCE_LOCAL_INCLUDES   = NO
+FORCE_LOCAL_INCLUDES   = YES
 
 # If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
 # documentation for inline members.


Index: docs/doxygen.cfg.in
===
--- docs/doxygen.cfg.in
+++ docs/doxygen.cfg.in
@@ -132,7 +132,7 @@
 # shortest path that makes the file name unique will be used
 # The default value is: YES.
 
-FULL_PATH_NAMES= NO
+FULL_PATH_NAMES= YES
 
 # The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
 # Stripping is only done if one of the specified strings matches the left-hand
@@ -144,16 +144,16 @@
 # will be relative from the directory where doxygen is started.
 # This tag requires that the tag FULL_PATH_NAMES is set to YES.
 
-STRIP_FROM_PATH= ../..
+STRIP_FROM_PATH= @abs_srcdir@/..
 
 # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
 # path mentioned in the documentation of a class, which tells the reader which
 # header file to include in order to use a class. If left blank only the name of
 # the header file containing the class definition is used. Otherwise one should
 # specify the list of include paths that are normally passed to the compiler
 # using the -I flag.
 
-STRIP_FROM_INC_PATH=
+STRIP_FROM_INC_PATH= @abs_srcdir@/../include
 
 # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
 # less readable) file names. This can be useful is your file systems doesn't
@@ -513,7 +513,7 @@
 # files with double quotes in the documentation rather than with sharp brackets.
 # The default value is: NO.
 
-FORCE_LOCAL_INCLUDES   = NO
+FORCE_LOCAL_INCLUDES   = YES
 
 # If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
 # documentation for inline members.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34607: [Bash-autocompletion] Check clang version in Bash

2017-06-28 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306555: [Bash-autocompletion] Check clang version in Bash 
(authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D34607?vs=103884&id=104435#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34607

Files:
  cfe/trunk/utils/bash-autocomplete.sh


Index: cfe/trunk/utils/bash-autocomplete.sh
===
--- cfe/trunk/utils/bash-autocomplete.sh
+++ cfe/trunk/utils/bash-autocomplete.sh
@@ -1,7 +1,7 @@
 # Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use 
this.
 _clang()
 {
-  local cur prev words cword arg
+  local cur prev words cword arg flags
   _init_completion -n : || return
 
   # bash always separates '=' as a token even if there's no space before/after 
'='.
@@ -24,7 +24,14 @@
 arg="$w2=,$cur"
   fi
 
-  local flags=$( clang --autocomplete="$arg" )
+  flags=$( clang --autocomplete="$arg" 2>/dev/null )
+  # If clang is old that it does not support --autocomplete,
+  # fall back to the filename completion.
+  if [[ "$?" != 0 ]]; then
+_filedir
+return
+  fi
+
   if [[ "$cur" == '=' ]]; then
 COMPREPLY=( $( compgen -W "$flags" -- "") )
   elif [[ "$flags" == "" || "$arg" == "" ]]; then


Index: cfe/trunk/utils/bash-autocomplete.sh
===
--- cfe/trunk/utils/bash-autocomplete.sh
+++ cfe/trunk/utils/bash-autocomplete.sh
@@ -1,7 +1,7 @@
 # Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use this.
 _clang()
 {
-  local cur prev words cword arg
+  local cur prev words cword arg flags
   _init_completion -n : || return
 
   # bash always separates '=' as a token even if there's no space before/after '='.
@@ -24,7 +24,14 @@
 arg="$w2=,$cur"
   fi
 
-  local flags=$( clang --autocomplete="$arg" )
+  flags=$( clang --autocomplete="$arg" 2>/dev/null )
+  # If clang is old that it does not support --autocomplete,
+  # fall back to the filename completion.
+  if [[ "$?" != 0 ]]; then
+_filedir
+return
+  fi
+
   if [[ "$cur" == '=' ]]; then
 COMPREPLY=( $( compgen -W "$flags" -- "") )
   elif [[ "$flags" == "" || "$arg" == "" ]]; then
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34761: [Bash-autocompletion] Invoke clang where user called

2017-06-28 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

When user build clang and used completion Eg. `build/bin/clang
-fno[tab]`, we want to invoke `build/bin/clang --autocomplete=-fno`,

  rather than `clang --autocomplete=-fno`.


https://reviews.llvm.org/D34761

Files:
  clang/utils/bash-autocomplete.sh


Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -24,7 +24,7 @@
 arg="$w2=,$cur"
   fi
 
-  flags=$( clang --autocomplete="$arg" 2>/dev/null )
+  flags=$( "${COMP_WORDS[0]}" --autocomplete="$arg" 2>/dev/null )
   # If clang is old that it does not support --autocomplete,
   # fall back to the filename completion.
   if [[ "$?" != 0 ]]; then


Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -24,7 +24,7 @@
 arg="$w2=,$cur"
   fi
 
-  flags=$( clang --autocomplete="$arg" 2>/dev/null )
+  flags=$( "${COMP_WORDS[0]}" --autocomplete="$arg" 2>/dev/null )
   # If clang is old that it does not support --autocomplete,
   # fall back to the filename completion.
   if [[ "$?" != 0 ]]; then
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34761: [Bash-autocompletion] Invoke clang where user called

2017-06-28 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306559: [Bash-autocompletion] Invoke clang where user called 
(authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D34761?vs=104438&id=104439#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34761

Files:
  cfe/trunk/utils/bash-autocomplete.sh


Index: cfe/trunk/utils/bash-autocomplete.sh
===
--- cfe/trunk/utils/bash-autocomplete.sh
+++ cfe/trunk/utils/bash-autocomplete.sh
@@ -24,7 +24,7 @@
 arg="$w2=,$cur"
   fi
 
-  flags=$( clang --autocomplete="$arg" 2>/dev/null )
+  flags=$( "${COMP_WORDS[0]}" --autocomplete="$arg" 2>/dev/null )
   # If clang is old that it does not support --autocomplete,
   # fall back to the filename completion.
   if [[ "$?" != 0 ]]; then


Index: cfe/trunk/utils/bash-autocomplete.sh
===
--- cfe/trunk/utils/bash-autocomplete.sh
+++ cfe/trunk/utils/bash-autocomplete.sh
@@ -24,7 +24,7 @@
 arg="$w2=,$cur"
   fi
 
-  flags=$( clang --autocomplete="$arg" 2>/dev/null )
+  flags=$( "${COMP_WORDS[0]}" --autocomplete="$arg" 2>/dev/null )
   # If clang is old that it does not support --autocomplete,
   # fall back to the filename completion.
   if [[ "$?" != 0 ]]; then
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34770: [Bash-autocompletion] Auto complete cc1 options if -cc1 is specified

2017-06-28 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
Herald added a subscriber: hiraditya.

We don't want to autocomplete flags whose Flags class has `NoDriverOption` when 
argv[1] is not `-cc1`.

Another idea for this implementation is to make --autocomplete a cc1
option and handle it in clang Frontend, by porting --autocomplete
handler from Driver to Frontend, so that we can handle Driver options
and CC1 options in unified manner.


https://reviews.llvm.org/D34770

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/Option/OptTable.cpp

Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -225,11 +225,15 @@
   return {};
 }
 
-std::vector OptTable::findByPrefix(StringRef Cur) const {
+std::vector
+OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
   std::vector Ret;
   for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
 if (!In.Prefixes)
   continue;
+if (In.Flags & DisableFlags)
+  continue;
+
 for (int I = 0; In.Prefixes[I]; I++) {
   std::string S = std::string(In.Prefixes[I]) + std::string(In.Name);
   if (StringRef(S).startswith(Cur))
Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -140,7 +140,8 @@
   //  to start with.
   ///
   /// \return The vector of flags which start with Cur.
-  std::vector findByPrefix(StringRef Cur) const;
+  std::vector findByPrefix(StringRef Cur,
+unsigned short DisableFlags) const;
 
   /// \brief Parse a single argument; returning the new argument and
   /// updating Index.
Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -10,18 +10,23 @@
   # So, we need to partially undo bash tokenization here for integrity.
   local w1="${COMP_WORDS[$cword - 1]}"
   local w2="${COMP_WORDS[$cword - 2]}"
+  # Clang want to know if -cc1 option is specified or not, because we don't want to show
+  # cc1 options otherwise.
+  if [[ "${COMP_WORDS[1]}" == "-cc1" ]]; then
+arg="#"
+  fi
   if [[ "$cur" == -* ]]; then
 # -foo
-arg="$cur"
+arg="$arg$cur"
   elif [[ "$w1" == -*  && "$cur" == '=' ]]; then
 # -foo=
-arg="$w1=,"
+arg="$arg$w1=,"
   elif [[ "$w1" == -* ]]; then
 # -foo  or -foo bar
-arg="$w1,$cur"
+arg="$arg$w1,$cur"
   elif [[ "$w2" == -* && "$w1" == '=' ]]; then
 # -foo=bar
-arg="$w2=,$cur"
+arg="$arg$w2=,$cur"
   fi
 
   flags=$( "${COMP_WORDS[0]}" --autocomplete="$arg" 2>/dev/null )
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -36,3 +36,7 @@
 // MTHREADMODELALL: posix single
 // RUN: %clang --autocomplete=-mrelocation-model, | FileCheck %s -check-prefix=MRELOCMODELALL
 // MRELOCMODELALL: dynamic-no-pic pic ropi ropi-rwpi rwpi static
+// RUN: %clang --autocomplete=-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CLANG
+// MRELOCMODEL_CLANG-NOT: -mrelocation-model
+// RUN: %clang --autocomplete=#-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CC1
+// MRELOCMODEL_CC1: -mrelocation-model
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1231,11 +1231,20 @@
 StringRef PassedFlags = A->getValue();
 std::vector SuggestedCompletions;
 
+unsigned short DisableFlags = options::NoDriverOption;
+// We want to show cc1-only options only when clang is invoked as "clang -cc1".
+// When clang is invoked as "clang -cc1", we add "#" to ther beginning of an --autocomplete
+// option so that the clang driver can distinguish whether it is requested to show cc1-only options or not.
+if (PassedFlags[0] == '#') {
+  DisableFlags = 0;
+  PassedFlags = PassedFlags.substr(1);
+}
+
 if (PassedFlags.find(',') == StringRef::npos) {
   // If the flag is in the form of "--autocomplete=-foo",
   // we were requested to print out all option names that start with "-foo".
   // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
-  SuggestedCompletions = Opts->findByPrefix(PassedFlags);
+  SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
 } else {
   // If the flag is in the form of "--autocomplete=foo,bar", we were
   // requested to print out all option values for "-foo" that start with
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http:/

  1   2   >