[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-25 Thread via cfe-commits

https://github.com/yronglin closed 
https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-24 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/88602

>From 9d0656461683c4a6af76aa3990def06b04eb1b0a Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 13 Apr 2024 15:46:36 +0800
Subject: [PATCH 1/3] [Clang] Diagnose apply AST consume actions on LLVM IR

Signed-off-by: yronglin 
---
 .../clang/Basic/DiagnosticFrontendKinds.td|  3 ++
 clang/lib/Frontend/FrontendAction.cpp |  7 +++--
 clang/test/Frontend/ast-dump-on-llvm.ll   | 29 +++
 3 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Frontend/ast-dump-on-llvm.ll

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 14b08d4927ec5e..2cf4ddfa4e805d 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 
+  DefaultFatal;
 }
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index b7c9967316f0b8..4d5a6aaf0b5f71 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -757,8 +757,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance ,
 
   // IR files bypass the rest of initialization.
   if (Input.getKind().getLanguage() == Language::LLVM_IR) {
-assert(hasIRSupport() &&
-   "This action does not have IR file support!");
+if (!hasIRSupport()) {
+  CI.getDiagnostics().Report(diag::err_ast_action_on_unparsable_source)
+  << Input.getFile();
+  return false;
+}
 
 // Inform the diagnostic client we are processing a source file.
 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
diff --git a/clang/test/Frontend/ast-dump-on-llvm.ll 
b/clang/test/Frontend/ast-dump-on-llvm.ll
new file mode 100644
index 00..72aafc361cde84
--- /dev/null
+++ b/clang/test/Frontend/ast-dump-on-llvm.ll
@@ -0,0 +1,29 @@
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-DUMP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=json %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=default %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-DEFAULT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=json %s -o 
- 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=default %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-DEFAULT
+
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-print %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-PRINT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-view %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-VIEW
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-list %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-LIST
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-lookups %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-LOOKUP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown 
-ast-dump-filter=FunctionDecl %s -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK-AST-DUMP-FILTER-EQ
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-decl-types %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-DECL-TYPES
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-SYNTAX-ONLY
+
+
+; CHECK-AST-DUMP: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-EQ-JSON: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-EQ-DEFAULT: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-ALL: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-JSON: fatal error: can not apply ast actions to LLVM 
IR file '{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-DEFAULT: fatal error: can not apply ast actions to 
LLVM IR file '{{.*}}'
+; CHECK-AST-PRINT: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-VIEW: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-LIST: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-LOOKUP: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-FILTER-EQ: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; 

[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-24 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/88602

>From 9d0656461683c4a6af76aa3990def06b04eb1b0a Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 13 Apr 2024 15:46:36 +0800
Subject: [PATCH 1/3] [Clang] Diagnose apply AST consume actions on LLVM IR

Signed-off-by: yronglin 
---
 .../clang/Basic/DiagnosticFrontendKinds.td|  3 ++
 clang/lib/Frontend/FrontendAction.cpp |  7 +++--
 clang/test/Frontend/ast-dump-on-llvm.ll   | 29 +++
 3 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Frontend/ast-dump-on-llvm.ll

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 14b08d4927ec5e..2cf4ddfa4e805d 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 
+  DefaultFatal;
 }
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index b7c9967316f0b8..4d5a6aaf0b5f71 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -757,8 +757,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance ,
 
   // IR files bypass the rest of initialization.
   if (Input.getKind().getLanguage() == Language::LLVM_IR) {
-assert(hasIRSupport() &&
-   "This action does not have IR file support!");
+if (!hasIRSupport()) {
+  CI.getDiagnostics().Report(diag::err_ast_action_on_unparsable_source)
+  << Input.getFile();
+  return false;
+}
 
 // Inform the diagnostic client we are processing a source file.
 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
diff --git a/clang/test/Frontend/ast-dump-on-llvm.ll 
b/clang/test/Frontend/ast-dump-on-llvm.ll
new file mode 100644
index 00..72aafc361cde84
--- /dev/null
+++ b/clang/test/Frontend/ast-dump-on-llvm.ll
@@ -0,0 +1,29 @@
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-DUMP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=json %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=default %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-DEFAULT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=json %s -o 
- 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=default %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-DEFAULT
+
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-print %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-PRINT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-view %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-VIEW
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-list %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-LIST
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-lookups %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-LOOKUP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown 
-ast-dump-filter=FunctionDecl %s -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK-AST-DUMP-FILTER-EQ
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-decl-types %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-DECL-TYPES
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-SYNTAX-ONLY
+
+
+; CHECK-AST-DUMP: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-EQ-JSON: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-EQ-DEFAULT: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-ALL: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-JSON: fatal error: can not apply ast actions to LLVM 
IR file '{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-DEFAULT: fatal error: can not apply ast actions to 
LLVM IR file '{{.*}}'
+; CHECK-AST-PRINT: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-VIEW: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-LIST: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-LOOKUP: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-FILTER-EQ: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; 

[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-23 Thread via cfe-commits

yronglin wrote:

Thanks for your review and confirmation! @AaronBallman @jansvoboda11 

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-23 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/88602

>From 9d0656461683c4a6af76aa3990def06b04eb1b0a Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 13 Apr 2024 15:46:36 +0800
Subject: [PATCH 1/3] [Clang] Diagnose apply AST consume actions on LLVM IR

Signed-off-by: yronglin 
---
 .../clang/Basic/DiagnosticFrontendKinds.td|  3 ++
 clang/lib/Frontend/FrontendAction.cpp |  7 +++--
 clang/test/Frontend/ast-dump-on-llvm.ll   | 29 +++
 3 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Frontend/ast-dump-on-llvm.ll

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 14b08d4927ec5e..2cf4ddfa4e805d 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 
+  DefaultFatal;
 }
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index b7c9967316f0b8..4d5a6aaf0b5f71 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -757,8 +757,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance ,
 
   // IR files bypass the rest of initialization.
   if (Input.getKind().getLanguage() == Language::LLVM_IR) {
-assert(hasIRSupport() &&
-   "This action does not have IR file support!");
+if (!hasIRSupport()) {
+  CI.getDiagnostics().Report(diag::err_ast_action_on_unparsable_source)
+  << Input.getFile();
+  return false;
+}
 
 // Inform the diagnostic client we are processing a source file.
 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
diff --git a/clang/test/Frontend/ast-dump-on-llvm.ll 
b/clang/test/Frontend/ast-dump-on-llvm.ll
new file mode 100644
index 00..72aafc361cde84
--- /dev/null
+++ b/clang/test/Frontend/ast-dump-on-llvm.ll
@@ -0,0 +1,29 @@
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-DUMP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=json %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=default %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-DEFAULT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=json %s -o 
- 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=default %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-DEFAULT
+
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-print %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-PRINT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-view %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-VIEW
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-list %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-LIST
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-lookups %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-LOOKUP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown 
-ast-dump-filter=FunctionDecl %s -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK-AST-DUMP-FILTER-EQ
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-decl-types %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-DECL-TYPES
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-SYNTAX-ONLY
+
+
+; CHECK-AST-DUMP: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-EQ-JSON: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-EQ-DEFAULT: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-ALL: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-JSON: fatal error: can not apply ast actions to LLVM 
IR file '{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-DEFAULT: fatal error: can not apply ast actions to 
LLVM IR file '{{.*}}'
+; CHECK-AST-PRINT: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-VIEW: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-LIST: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-LOOKUP: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-FILTER-EQ: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; 

[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-22 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 approved this pull request.


https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-22 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM!

> I still have some questions, should we give tips to the user that which 
> options cannot apply on LLVM IR files?

I think the diagnostic you've got is reasonable -- these options are CC1 
options which are not something we typically expect users to specify themselves.

> Do we have any precedent or design principles for dealing with mutually 
> exclusive options?

When they're cc1 only options, we basically just don't want to cause crashes or 
assertions. If they're driver options, we want to issue reasonable diagnostics 
to help the user identify what the issue is so they know how to resolve it (and 
ideally, we'd document the mutual exclusion explicitly in the user's manual).

CC @jansvoboda11 as options code owner

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-22 Thread via cfe-commits

yronglin wrote:

Friendly ping~

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread via cfe-commits

yronglin wrote:

@tbaederr @Sirraide Thanks for your review! I still have some questions, should 
we give tips to the user that which options cannot apply on LLVM IR files? Do 
we have any precedent or design principles for dealing with mutually exclusive 
options?

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread via cfe-commits


@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 

yronglin wrote:

done

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread via cfe-commits


@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 

yronglin wrote:

done

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread via cfe-commits


@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<

yronglin wrote:

Agree, I've changed the name to `err_ast_action_on_llvm_ir`

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/88602

>From 9d0656461683c4a6af76aa3990def06b04eb1b0a Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 13 Apr 2024 15:46:36 +0800
Subject: [PATCH 1/2] [Clang] Diagnose apply AST consume actions on LLVM IR

Signed-off-by: yronglin 
---
 .../clang/Basic/DiagnosticFrontendKinds.td|  3 ++
 clang/lib/Frontend/FrontendAction.cpp |  7 +++--
 clang/test/Frontend/ast-dump-on-llvm.ll   | 29 +++
 3 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Frontend/ast-dump-on-llvm.ll

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 14b08d4927ec5e..2cf4ddfa4e805d 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 
+  DefaultFatal;
 }
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index b7c9967316f0b8..4d5a6aaf0b5f71 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -757,8 +757,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance ,
 
   // IR files bypass the rest of initialization.
   if (Input.getKind().getLanguage() == Language::LLVM_IR) {
-assert(hasIRSupport() &&
-   "This action does not have IR file support!");
+if (!hasIRSupport()) {
+  CI.getDiagnostics().Report(diag::err_ast_action_on_unparsable_source)
+  << Input.getFile();
+  return false;
+}
 
 // Inform the diagnostic client we are processing a source file.
 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
diff --git a/clang/test/Frontend/ast-dump-on-llvm.ll 
b/clang/test/Frontend/ast-dump-on-llvm.ll
new file mode 100644
index 00..72aafc361cde84
--- /dev/null
+++ b/clang/test/Frontend/ast-dump-on-llvm.ll
@@ -0,0 +1,29 @@
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-DUMP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=json %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=default %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-DEFAULT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=json %s -o 
- 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=default %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-DEFAULT
+
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-print %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-PRINT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-view %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-VIEW
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-list %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-LIST
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-lookups %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-LOOKUP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown 
-ast-dump-filter=FunctionDecl %s -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK-AST-DUMP-FILTER-EQ
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-decl-types %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-DECL-TYPES
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-SYNTAX-ONLY
+
+
+; CHECK-AST-DUMP: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-EQ-JSON: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-EQ-DEFAULT: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-ALL: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-JSON: fatal error: can not apply ast actions to LLVM 
IR file '{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-DEFAULT: fatal error: can not apply ast actions to 
LLVM IR file '{{.*}}'
+; CHECK-AST-PRINT: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-VIEW: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-LIST: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-LOOKUP: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-FILTER-EQ: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; 

[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread Timm Baeder via cfe-commits


@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 

tbaederr wrote:

```suggestion
  "cannot apply ast actions to LLVM IR file '%0'">, 
```

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread via cfe-commits

https://github.com/Sirraide edited 
https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread via cfe-commits

Sirraide wrote:

> I'm not sure if this diagnostic information makes sense, do you have any 
> suggestions?

If passing a specific command-line to Clang causes it to assert, then I’d say 
issuing a diagnostic instead is better, yeah (if this assert was only reachable 
by using Clang as a library then it’d be a different matter imo), so I think it 
does make sense, yeah.

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread via cfe-commits


@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<

Sirraide wrote:

nit: Maybe a different name for this would be better? It’s not really 
‘unparseable’, seeing as we can parse LLVM IR just fine; it’s just not C++. 

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread via cfe-commits

https://github.com/Sirraide commented:

Not too familiar w/ the driver, but this looks fine to me except for two minor 
things.

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread via cfe-commits


@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 

Sirraide wrote:

```suggestion
  "can not apply AST actions to LLVM IR file '%0'">, 
```

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-16 Thread via cfe-commits

https://github.com/Sirraide edited 
https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-15 Thread via cfe-commits

yronglin wrote:

I'm not sure if this diagnostic information makes sense, do you have any 
suggestions?

https://github.com/llvm/llvm-project/pull/88602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-15 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/88602

>From 9d0656461683c4a6af76aa3990def06b04eb1b0a Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 13 Apr 2024 15:46:36 +0800
Subject: [PATCH] [Clang] Diagnose apply AST consume actions on LLVM IR

Signed-off-by: yronglin 
---
 .../clang/Basic/DiagnosticFrontendKinds.td|  3 ++
 clang/lib/Frontend/FrontendAction.cpp |  7 +++--
 clang/test/Frontend/ast-dump-on-llvm.ll   | 29 +++
 3 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Frontend/ast-dump-on-llvm.ll

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 14b08d4927ec5e..2cf4ddfa4e805d 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 
+  DefaultFatal;
 }
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index b7c9967316f0b8..4d5a6aaf0b5f71 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -757,8 +757,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance ,
 
   // IR files bypass the rest of initialization.
   if (Input.getKind().getLanguage() == Language::LLVM_IR) {
-assert(hasIRSupport() &&
-   "This action does not have IR file support!");
+if (!hasIRSupport()) {
+  CI.getDiagnostics().Report(diag::err_ast_action_on_unparsable_source)
+  << Input.getFile();
+  return false;
+}
 
 // Inform the diagnostic client we are processing a source file.
 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
diff --git a/clang/test/Frontend/ast-dump-on-llvm.ll 
b/clang/test/Frontend/ast-dump-on-llvm.ll
new file mode 100644
index 00..72aafc361cde84
--- /dev/null
+++ b/clang/test/Frontend/ast-dump-on-llvm.ll
@@ -0,0 +1,29 @@
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-DUMP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=json %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=default %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-DEFAULT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=json %s -o 
- 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=default %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-DEFAULT
+
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-print %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-PRINT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-view %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-VIEW
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-list %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-LIST
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-lookups %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-LOOKUP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown 
-ast-dump-filter=FunctionDecl %s -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK-AST-DUMP-FILTER-EQ
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-decl-types %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-DECL-TYPES
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-SYNTAX-ONLY
+
+
+; CHECK-AST-DUMP: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-EQ-JSON: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-EQ-DEFAULT: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-ALL: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-JSON: fatal error: can not apply ast actions to LLVM 
IR file '{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-DEFAULT: fatal error: can not apply ast actions to 
LLVM IR file '{{.*}}'
+; CHECK-AST-PRINT: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-VIEW: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-LIST: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-LOOKUP: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-FILTER-EQ: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; 

[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-14 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/88602

>From 8ce52d73896d332a1899c59760118a8cf5b620cb Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 13 Apr 2024 15:46:36 +0800
Subject: [PATCH] [Clang] Diagnose apply AST consume actions on LLVM IR

Signed-off-by: yronglin 
---
 .../clang/Basic/DiagnosticFrontendKinds.td|  3 ++
 clang/lib/Frontend/FrontendAction.cpp |  7 +++--
 clang/test/Frontend/ast-dump-on-llvm.ll   | 29 +++
 3 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Frontend/ast-dump-on-llvm.ll

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 14b08d4927ec5e..2cf4ddfa4e805d 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 
+  DefaultFatal;
 }
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index b7c9967316f0b8..4d5a6aaf0b5f71 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -757,8 +757,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance ,
 
   // IR files bypass the rest of initialization.
   if (Input.getKind().getLanguage() == Language::LLVM_IR) {
-assert(hasIRSupport() &&
-   "This action does not have IR file support!");
+if (!hasIRSupport()) {
+  CI.getDiagnostics().Report(diag::err_ast_action_on_unparsable_source)
+  << Input.getFile();
+  return false;
+}
 
 // Inform the diagnostic client we are processing a source file.
 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
diff --git a/clang/test/Frontend/ast-dump-on-llvm.ll 
b/clang/test/Frontend/ast-dump-on-llvm.ll
new file mode 100644
index 00..72aafc361cde84
--- /dev/null
+++ b/clang/test/Frontend/ast-dump-on-llvm.ll
@@ -0,0 +1,29 @@
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-DUMP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=json %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=default %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-DEFAULT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=json %s -o 
- 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=default %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-DEFAULT
+
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-print %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-PRINT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-view %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-VIEW
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-list %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-LIST
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-lookups %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-LOOKUP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown 
-ast-dump-filter=FunctionDecl %s -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK-AST-DUMP-FILTER-EQ
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-decl-types %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-DECL-TYPES
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-SYNTAX-ONLY
+
+
+; CHECK-AST-DUMP: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-EQ-JSON: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-EQ-DEFAULT: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-ALL: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-JSON: fatal error: can not apply ast actions to LLVM 
IR file '{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-DEFAULT: fatal error: can not apply ast actions to 
LLVM IR file '{{.*}}'
+; CHECK-AST-PRINT: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-VIEW: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-LIST: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-LOOKUP: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-FILTER-EQ: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; 

[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (yronglin)


Changes

Fixes https://github.com/llvm/llvm-project/issues/88522

This PR introduce a new diagnostic to report apply AST consume actions on LLVM 
IR.

---
Full diff: https://github.com/llvm/llvm-project/pull/88602.diff


3 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticFrontendKinds.td (+3) 
- (modified) clang/lib/Frontend/FrontendAction.cpp (+5-2) 
- (added) clang/test/Frontend/ast-dump-on-llvm.ll (+29) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 14b08d4927ec5e..2cf4ddfa4e805d 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 
+  DefaultFatal;
 }
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index b7c9967316f0b8..4d5a6aaf0b5f71 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -757,8 +757,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance ,
 
   // IR files bypass the rest of initialization.
   if (Input.getKind().getLanguage() == Language::LLVM_IR) {
-assert(hasIRSupport() &&
-   "This action does not have IR file support!");
+if (!hasIRSupport()) {
+  CI.getDiagnostics().Report(diag::err_ast_action_on_unparsable_source)
+  << Input.getFile();
+  return false;
+}
 
 // Inform the diagnostic client we are processing a source file.
 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
diff --git a/clang/test/Frontend/ast-dump-on-llvm.ll 
b/clang/test/Frontend/ast-dump-on-llvm.ll
new file mode 100644
index 00..72aafc361cde84
--- /dev/null
+++ b/clang/test/Frontend/ast-dump-on-llvm.ll
@@ -0,0 +1,29 @@
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-DUMP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=json %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=default %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-DEFAULT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=json %s -o 
- 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=default %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-DEFAULT
+
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-print %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-PRINT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-view %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-VIEW
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-list %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-LIST
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-lookups %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-LOOKUP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown 
-ast-dump-filter=FunctionDecl %s -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK-AST-DUMP-FILTER-EQ
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-decl-types %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-DECL-TYPES
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-SYNTAX-ONLY
+
+
+; CHECK-AST-DUMP: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-EQ-JSON: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-EQ-DEFAULT: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-ALL: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-JSON: fatal error: can not apply ast actions to LLVM 
IR file '{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-DEFAULT: fatal error: can not apply ast actions to 
LLVM IR file '{{.*}}'
+; CHECK-AST-PRINT: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-VIEW: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-LIST: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-LOOKUP: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-FILTER-EQ: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-DECL-TYPES: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; 

[clang] [Clang] Diagnose apply AST consume actions on LLVM IR (PR #88602)

2024-04-13 Thread via cfe-commits

https://github.com/yronglin created 
https://github.com/llvm/llvm-project/pull/88602

Fixes https://github.com/llvm/llvm-project/issues/88522

This PR introduce a new diagnostic to report apply AST consume actions on LLVM 
IR.

>From a180c067d36b731cbd075651ca4ecd903a643ffa Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 13 Apr 2024 15:46:36 +0800
Subject: [PATCH] [Clang] Diagnose apply AST consume actions on LLVM IR

Signed-off-by: yronglin 
---
 .../clang/Basic/DiagnosticFrontendKinds.td|  3 ++
 clang/lib/Frontend/FrontendAction.cpp |  7 +++--
 clang/test/Frontend/ast-dump-on-llvm.ll   | 29 +++
 3 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Frontend/ast-dump-on-llvm.ll

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 14b08d4927ec5e..2cf4ddfa4e805d 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -370,4 +370,7 @@ def warn_missing_symbol_graph_dir : Warning<
   "Missing symbol graph output directory, defaulting to working directory">,
   InGroup;
 
+def err_ast_action_on_unparsable_source : Error<
+  "can not apply ast actions to LLVM IR file '%0'">, 
+  DefaultFatal;
 }
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index b7c9967316f0b8..4d5a6aaf0b5f71 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -757,8 +757,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance ,
 
   // IR files bypass the rest of initialization.
   if (Input.getKind().getLanguage() == Language::LLVM_IR) {
-assert(hasIRSupport() &&
-   "This action does not have IR file support!");
+if (!hasIRSupport()) {
+  CI.getDiagnostics().Report(diag::err_ast_action_on_unparsable_source)
+  << Input.getFile();
+  return false;
+}
 
 // Inform the diagnostic client we are processing a source file.
 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
diff --git a/clang/test/Frontend/ast-dump-on-llvm.ll 
b/clang/test/Frontend/ast-dump-on-llvm.ll
new file mode 100644
index 00..72aafc361cde84
--- /dev/null
+++ b/clang/test/Frontend/ast-dump-on-llvm.ll
@@ -0,0 +1,29 @@
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-DUMP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=json %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=default %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-EQ-DEFAULT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=json %s -o 
- 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-JSON
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-all=default %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-ALL-EQ-DEFAULT
+
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-print %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-PRINT
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-view %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-VIEW
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-list %s -o - 2>&1 | 
FileCheck %s --check-prefix=CHECK-AST-LIST
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-lookups %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-LOOKUP
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown 
-ast-dump-filter=FunctionDecl %s -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK-AST-DUMP-FILTER-EQ
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump-decl-types %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-AST-DUMP-DECL-TYPES
+; RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only %s -o - 
2>&1 | FileCheck %s --check-prefix=CHECK-SYNTAX-ONLY
+
+
+; CHECK-AST-DUMP: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-EQ-JSON: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-EQ-DEFAULT: fatal error: can not apply ast actions to LLVM IR 
file '{{.*}}'
+; CHECK-AST-DUMP-ALL: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-JSON: fatal error: can not apply ast actions to LLVM 
IR file '{{.*}}'
+; CHECK-AST-DUMP-ALL-EQ-DEFAULT: fatal error: can not apply ast actions to 
LLVM IR file '{{.*}}'
+; CHECK-AST-PRINT: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-VIEW: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-LIST: fatal error: can not apply ast actions to LLVM IR file 
'{{.*}}'
+; CHECK-AST-DUMP-LOOKUP: fatal error: can not apply ast