[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh created https://github.com/llvm/llvm-project/pull/97846 Set `static` storage class specifier for such decls to have `internal` linkage in produced IR and then in the object file. Fix #97830 >From ec1f0f0fe626db9da1437ed414f8d080c750cb45 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH] [clang] Use internal linkage for c23 constexpr vars. Set `static` storage class specifier for such decls to have `internal` linkage in produced IR and then in the object file. Fix #97830 --- clang/lib/Parse/ParseDecl.cpp | 11 --- .../CodeGen/constexpr-c23-internal-linkage.c| 17 + 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index a07f7ad2233fe..a4e66bb78d6df 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4428,10 +4428,15 @@ void Parser::ParseDeclarationSpecifiers( // constexpr, consteval, constinit specifiers case tok::kw_constexpr: - if (getLangOpts().C23) + if (getLangOpts().C23) { Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName(); - isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, - PrevSpec, DiagID); +isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, +PrevSpec, DiagID); + +isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc, + PrevSpec, DiagID, Policy); +isStorageClass = true; + } break; case tok::kw_consteval: isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Consteval, Loc, diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 0..cf2dd48a5dce6 --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,17 @@ +/* RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/97846 >From ec1f0f0fe626db9da1437ed414f8d080c750cb45 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH] [clang] Use internal linkage for c23 constexpr vars. Set `static` storage class specifier for such decls to have `internal` linkage in produced IR and then in the object file. Fix #97830 --- clang/lib/Parse/ParseDecl.cpp | 11 --- .../CodeGen/constexpr-c23-internal-linkage.c| 17 + 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index a07f7ad2233fe..a4e66bb78d6df 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4428,10 +4428,15 @@ void Parser::ParseDeclarationSpecifiers( // constexpr, consteval, constinit specifiers case tok::kw_constexpr: - if (getLangOpts().C23) + if (getLangOpts().C23) { Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName(); - isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, - PrevSpec, DiagID); +isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, +PrevSpec, DiagID); + +isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc, + PrevSpec, DiagID, Policy); +isStorageClass = true; + } break; case tok::kw_consteval: isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Consteval, Loc, diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 0..cf2dd48a5dce6 --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,17 @@ +/* RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/97846 >From 20adb1c05dc59cc0a4b3969824f75c2d9c612755 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH] [clang] Use internal linkage for c23 constexpr vars. Set `static` storage class specifier for such decls to have `internal` linkage in produced IR and then in the object file. Fix #97830 --- clang/lib/Parse/ParseDecl.cpp | 11 --- .../CodeGen/constexpr-c23-internal-linkage.c | 18 ++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index a07f7ad2233fe..a4e66bb78d6df 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4428,10 +4428,15 @@ void Parser::ParseDeclarationSpecifiers( // constexpr, consteval, constinit specifiers case tok::kw_constexpr: - if (getLangOpts().C23) + if (getLangOpts().C23) { Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName(); - isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, - PrevSpec, DiagID); +isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, +PrevSpec, DiagID); + +isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc, + PrevSpec, DiagID, Policy); +isStorageClass = true; + } break; case tok::kw_consteval: isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Consteval, Loc, diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 0..1236062272a2d --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,18 @@ +/* + * RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/97846 >From 20adb1c05dc59cc0a4b3969824f75c2d9c612755 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH] [clang] Use internal linkage for c23 constexpr vars. Set `static` storage class specifier for such decls to have `internal` linkage in produced IR and then in the object file. Fix #97830 --- clang/lib/Parse/ParseDecl.cpp | 11 --- .../CodeGen/constexpr-c23-internal-linkage.c | 18 ++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index a07f7ad2233fe..a4e66bb78d6df 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4428,10 +4428,15 @@ void Parser::ParseDeclarationSpecifiers( // constexpr, consteval, constinit specifiers case tok::kw_constexpr: - if (getLangOpts().C23) + if (getLangOpts().C23) { Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName(); - isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, - PrevSpec, DiagID); +isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, +PrevSpec, DiagID); + +isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc, + PrevSpec, DiagID, Policy); +isStorageClass = true; + } break; case tok::kw_consteval: isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Consteval, Loc, diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 0..1236062272a2d --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,18 @@ +/* + * RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/97846 >From ecf8360b1ca201eeb8887214477eb8ffeb5f088f Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH] [clang] Use internal linkage for c23 constexpr vars. Set `static` storage class specifier for such decls to have `internal` linkage in produced IR and then in the object file. Fix #97830 --- clang/lib/Parse/ParseDecl.cpp | 10 +++--- .../CodeGen/constexpr-c23-internal-linkage.c | 18 ++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index a07f7ad2233fe6..8222e0c96e3f1b 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4428,10 +4428,14 @@ void Parser::ParseDeclarationSpecifiers( // constexpr, consteval, constinit specifiers case tok::kw_constexpr: - if (getLangOpts().C23) + if (getLangOpts().C23) { Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName(); - isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, - PrevSpec, DiagID); +isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, +PrevSpec, DiagID); + +isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc, + PrevSpec, DiagID, Policy); + } break; case tok::kw_consteval: isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Consteval, Loc, diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 00..1236062272a2d5 --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,18 @@ +/* + * RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh converted_to_draft https://github.com/llvm/llvm-project/pull/97846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
@@ -4428,10 +4428,14 @@ void Parser::ParseDeclarationSpecifiers( // constexpr, consteval, constinit specifiers case tok::kw_constexpr: - if (getLangOpts().C23) + if (getLangOpts().C23) { Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName(); - isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, - PrevSpec, DiagID); +isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, +PrevSpec, DiagID); + +isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc, chestnykh wrote: I need to rework this PR a little bit https://github.com/llvm/llvm-project/pull/97846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/97846 >From 70a5e96c9489ef46c5c17106178bf703eab8f8ad Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH] [clang] Use internal linkage for c23 constexpr vars. Set `static` storage class specifier for such decls to have `internal` linkage in produced IR and then in the object file. Fix #97830 --- clang/lib/AST/Decl.cpp | 11 +-- .../CodeGen/constexpr-c23-internal-linkage.c | 18 ++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 16ed6d88d1cb1..470b5b9b2f7d7 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -612,19 +612,26 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, assert(D->getDeclContext()->getRedeclContext()->isFileContext() && "Not a name having namespace scope"); ASTContext &Context = D->getASTContext(); + const auto *Var = dyn_cast(D); // C++ [basic.link]p3: // A name having namespace scope (3.3.6) has internal linkage if it // is the name of - if (getStorageClass(D->getCanonicalDecl()) == SC_Static) { + if ((getStorageClass(D->getCanonicalDecl()) == SC_Static) || + (Context.getLangOpts().C23 && Var && Var->isConstexpr())) { // - a variable, variable template, function, or function template // that is explicitly declared static; or // (This bullet corresponds to C99 6.2.2p3.) + +// C23 6.2.2p3 +// If the declaration of a file scope identifier for +// an object contains any of the storage-class specifiers static or constexpr +// then the identifier has internal linkage. return LinkageInfo::internal(); } - if (const auto *Var = dyn_cast(D)) { + if (Var) { // - a non-template variable of non-volatile const-qualified type, unless // - it is explicitly declared extern, or // - it is declared in the purview of a module interface unit diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 0..1236062272a2d --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,18 @@ +/* + * RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh ready_for_review https://github.com/llvm/llvm-project/pull/97846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/97846 >From b8252ed88a15cda147b2f62329a9369130a8d694 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH] [clang] Use internal linkage for c23 constexpr vars. See C23 std 6.2.2p3. Fix #97830 --- clang/lib/AST/Decl.cpp | 11 +-- .../CodeGen/constexpr-c23-internal-linkage.c | 18 ++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 16ed6d88d1cb1e..470b5b9b2f7d78 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -612,19 +612,26 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, assert(D->getDeclContext()->getRedeclContext()->isFileContext() && "Not a name having namespace scope"); ASTContext &Context = D->getASTContext(); + const auto *Var = dyn_cast(D); // C++ [basic.link]p3: // A name having namespace scope (3.3.6) has internal linkage if it // is the name of - if (getStorageClass(D->getCanonicalDecl()) == SC_Static) { + if ((getStorageClass(D->getCanonicalDecl()) == SC_Static) || + (Context.getLangOpts().C23 && Var && Var->isConstexpr())) { // - a variable, variable template, function, or function template // that is explicitly declared static; or // (This bullet corresponds to C99 6.2.2p3.) + +// C23 6.2.2p3 +// If the declaration of a file scope identifier for +// an object contains any of the storage-class specifiers static or constexpr +// then the identifier has internal linkage. return LinkageInfo::internal(); } - if (const auto *Var = dyn_cast(D)) { + if (Var) { // - a non-template variable of non-volatile const-qualified type, unless // - it is explicitly declared extern, or // - it is declared in the purview of a module interface unit diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 00..1236062272a2d5 --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,18 @@ +/* + * RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh edited https://github.com/llvm/llvm-project/pull/97846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
@@ -4428,10 +4428,14 @@ void Parser::ParseDeclarationSpecifiers( // constexpr, consteval, constinit specifiers case tok::kw_constexpr: - if (getLangOpts().C23) + if (getLangOpts().C23) { Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName(); - isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, - PrevSpec, DiagID); +isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc, +PrevSpec, DiagID); + +isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc, chestnykh wrote: Done https://github.com/llvm/llvm-project/pull/97846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/97846 >From 7a3f28574377bb6139971039ca6da5d299c2228d Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH] [clang] Use internal linkage for c23 constexpr vars. See C23 std 6.2.2p3. Fix #97830 --- clang/lib/AST/Decl.cpp | 11 +-- .../CodeGen/constexpr-c23-internal-linkage.c | 18 ++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 16ed6d88d1cb1..490c4a2fc525c 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -612,19 +612,26 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, assert(D->getDeclContext()->getRedeclContext()->isFileContext() && "Not a name having namespace scope"); ASTContext &Context = D->getASTContext(); + const auto *Var = dyn_cast(D); // C++ [basic.link]p3: // A name having namespace scope (3.3.6) has internal linkage if it // is the name of - if (getStorageClass(D->getCanonicalDecl()) == SC_Static) { + if ((getStorageClass(D->getCanonicalDecl()) == SC_Static) || + (Context.getLangOpts().C23 && Var && Var->isConstexpr())) { // - a variable, variable template, function, or function template // that is explicitly declared static; or // (This bullet corresponds to C99 6.2.2p3.) + +// C23 6.2.2p3 +// If the declaration of a file scope identifier for +// an object contains any of the storage-class specifiers static or +// constexpr then the identifier has internal linkage. return LinkageInfo::internal(); } - if (const auto *Var = dyn_cast(D)) { + if (Var) { // - a non-template variable of non-volatile const-qualified type, unless // - it is explicitly declared extern, or // - it is declared in the purview of a module interface unit diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 0..1236062272a2d --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,18 @@ +/* + * RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
chestnykh wrote: > LGTM but please add a release note to clang/docs/ReleaseNotes.rst so users > know about the fix as well. > > Once that's added, will you need someone to land the changes on your behalf? @AaronBallman , yes, i will need this. I'm going to add release notes right now. https://github.com/llvm/llvm-project/pull/97846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/97846 >From 7a3f28574377bb6139971039ca6da5d299c2228d Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH 1/2] [clang] Use internal linkage for c23 constexpr vars. See C23 std 6.2.2p3. Fix #97830 --- clang/lib/AST/Decl.cpp | 11 +-- .../CodeGen/constexpr-c23-internal-linkage.c | 18 ++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 16ed6d88d1cb1..490c4a2fc525c 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -612,19 +612,26 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, assert(D->getDeclContext()->getRedeclContext()->isFileContext() && "Not a name having namespace scope"); ASTContext &Context = D->getASTContext(); + const auto *Var = dyn_cast(D); // C++ [basic.link]p3: // A name having namespace scope (3.3.6) has internal linkage if it // is the name of - if (getStorageClass(D->getCanonicalDecl()) == SC_Static) { + if ((getStorageClass(D->getCanonicalDecl()) == SC_Static) || + (Context.getLangOpts().C23 && Var && Var->isConstexpr())) { // - a variable, variable template, function, or function template // that is explicitly declared static; or // (This bullet corresponds to C99 6.2.2p3.) + +// C23 6.2.2p3 +// If the declaration of a file scope identifier for +// an object contains any of the storage-class specifiers static or +// constexpr then the identifier has internal linkage. return LinkageInfo::internal(); } - if (const auto *Var = dyn_cast(D)) { + if (Var) { // - a non-template variable of non-volatile const-qualified type, unless // - it is explicitly declared extern, or // - it is declared in the purview of a module interface unit diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 0..1236062272a2d --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,18 @@ +/* + * RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + >From 023032965f116f70c0e874674ba07701c95e8698 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Mon, 8 Jul 2024 17:05:02 +0300 Subject: [PATCH 2/2] [clang][C23] Add release notes to bugfix. Add note that bug with incorrect linkage type of C23 constexpr vars is fixed. --- clang/docs/ReleaseNotes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 36cf615a4287c..3d81d0a190ffe 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -762,6 +762,9 @@ Bug Fixes in This Version - Fixed `static_cast` to array of unknown bound. Fixes (#GH62863). +- Fixed a bug with incorrect linkage type of constexpr objects. Now the linkage of such + objects is internal in accordance with the standard (#GH97846). + Bug Fixes to Compiler Builtins ^^ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
chestnykh wrote: Release notes added https://github.com/llvm/llvm-project/pull/97846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/97846 >From 7a3f28574377bb6139971039ca6da5d299c2228d Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH 1/2] [clang] Use internal linkage for c23 constexpr vars. See C23 std 6.2.2p3. Fix #97830 --- clang/lib/AST/Decl.cpp | 11 +-- .../CodeGen/constexpr-c23-internal-linkage.c | 18 ++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 16ed6d88d1cb1..490c4a2fc525c 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -612,19 +612,26 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, assert(D->getDeclContext()->getRedeclContext()->isFileContext() && "Not a name having namespace scope"); ASTContext &Context = D->getASTContext(); + const auto *Var = dyn_cast(D); // C++ [basic.link]p3: // A name having namespace scope (3.3.6) has internal linkage if it // is the name of - if (getStorageClass(D->getCanonicalDecl()) == SC_Static) { + if ((getStorageClass(D->getCanonicalDecl()) == SC_Static) || + (Context.getLangOpts().C23 && Var && Var->isConstexpr())) { // - a variable, variable template, function, or function template // that is explicitly declared static; or // (This bullet corresponds to C99 6.2.2p3.) + +// C23 6.2.2p3 +// If the declaration of a file scope identifier for +// an object contains any of the storage-class specifiers static or +// constexpr then the identifier has internal linkage. return LinkageInfo::internal(); } - if (const auto *Var = dyn_cast(D)) { + if (Var) { // - a non-template variable of non-volatile const-qualified type, unless // - it is explicitly declared extern, or // - it is declared in the purview of a module interface unit diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 0..1236062272a2d --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,18 @@ +/* + * RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + >From 94eb71de0ca4931de1ce6094440e939f6c02f732 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Mon, 8 Jul 2024 17:05:02 +0300 Subject: [PATCH 2/2] [clang][C23] Add release notes to bugfix. Add note that bug with incorrect linkage type of C23 constexpr vars is fixed. --- clang/docs/ReleaseNotes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 36cf615a4287c..ef701fc41287a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -762,6 +762,9 @@ Bug Fixes in This Version - Fixed `static_cast` to array of unknown bound. Fixes (#GH62863). +- Fixed a bug with incorrect linkage type of C23 `constexpr`` objects. Now the linkage of such + objects is internal in accordance with the standard (#GH97846). + Bug Fixes to Compiler Builtins ^^ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/97846 >From 7a3f28574377bb6139971039ca6da5d299c2228d Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH 1/2] [clang] Use internal linkage for c23 constexpr vars. See C23 std 6.2.2p3. Fix #97830 --- clang/lib/AST/Decl.cpp | 11 +-- .../CodeGen/constexpr-c23-internal-linkage.c | 18 ++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 16ed6d88d1cb1..490c4a2fc525c 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -612,19 +612,26 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, assert(D->getDeclContext()->getRedeclContext()->isFileContext() && "Not a name having namespace scope"); ASTContext &Context = D->getASTContext(); + const auto *Var = dyn_cast(D); // C++ [basic.link]p3: // A name having namespace scope (3.3.6) has internal linkage if it // is the name of - if (getStorageClass(D->getCanonicalDecl()) == SC_Static) { + if ((getStorageClass(D->getCanonicalDecl()) == SC_Static) || + (Context.getLangOpts().C23 && Var && Var->isConstexpr())) { // - a variable, variable template, function, or function template // that is explicitly declared static; or // (This bullet corresponds to C99 6.2.2p3.) + +// C23 6.2.2p3 +// If the declaration of a file scope identifier for +// an object contains any of the storage-class specifiers static or +// constexpr then the identifier has internal linkage. return LinkageInfo::internal(); } - if (const auto *Var = dyn_cast(D)) { + if (Var) { // - a non-template variable of non-volatile const-qualified type, unless // - it is explicitly declared extern, or // - it is declared in the purview of a module interface unit diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 0..1236062272a2d --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,18 @@ +/* + * RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + >From 317b3e2f2ff6be20b35da008a6ef243b2c84ec18 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Mon, 8 Jul 2024 17:05:02 +0300 Subject: [PATCH 2/2] [clang][C23] Add release notes to bugfix. Add note that bug with incorrect linkage type of C23 constexpr vars is fixed. --- clang/docs/ReleaseNotes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 36cf615a4287c..cb8bd5e6f3a04 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -762,6 +762,9 @@ Bug Fixes in This Version - Fixed `static_cast` to array of unknown bound. Fixes (#GH62863). +- Fixed a bug with incorrect linkage type of C23 `constexpr` objects. Now the linkage of such + objects is internal in accordance with the standard (#GH97846). + Bug Fixes to Compiler Builtins ^^ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
chestnykh wrote: > > > LGTM but please add a release note to clang/docs/ReleaseNotes.rst so > > > users know about the fix as well. > > > > > > Note that only clang 19 has `constexpr` support in C23. > > https://godbolt.org/z/4bThdsqK5 Release note saying that support has been > > implemented is already there. > > Ooh oops, I thought we had this in Clang 18 Should I change anything? https://github.com/llvm/llvm-project/pull/97846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/97846 >From 0619f787112c18c559959eb50086b412ebad5839 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 5 Jul 2024 20:40:32 +0300 Subject: [PATCH] [clang][C23] Use internal linkage for C23 constexpr vars. See C23 std 6.2.2p3. Fix #97830 --- clang/lib/AST/Decl.cpp | 11 +-- .../CodeGen/constexpr-c23-internal-linkage.c | 18 ++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/constexpr-c23-internal-linkage.c diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 16ed6d88d1cb1..490c4a2fc525c 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -612,19 +612,26 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, assert(D->getDeclContext()->getRedeclContext()->isFileContext() && "Not a name having namespace scope"); ASTContext &Context = D->getASTContext(); + const auto *Var = dyn_cast(D); // C++ [basic.link]p3: // A name having namespace scope (3.3.6) has internal linkage if it // is the name of - if (getStorageClass(D->getCanonicalDecl()) == SC_Static) { + if ((getStorageClass(D->getCanonicalDecl()) == SC_Static) || + (Context.getLangOpts().C23 && Var && Var->isConstexpr())) { // - a variable, variable template, function, or function template // that is explicitly declared static; or // (This bullet corresponds to C99 6.2.2p3.) + +// C23 6.2.2p3 +// If the declaration of a file scope identifier for +// an object contains any of the storage-class specifiers static or +// constexpr then the identifier has internal linkage. return LinkageInfo::internal(); } - if (const auto *Var = dyn_cast(D)) { + if (Var) { // - a non-template variable of non-volatile const-qualified type, unless // - it is explicitly declared extern, or // - it is declared in the purview of a module interface unit diff --git a/clang/test/CodeGen/constexpr-c23-internal-linkage.c b/clang/test/CodeGen/constexpr-c23-internal-linkage.c new file mode 100644 index 0..1236062272a2d --- /dev/null +++ b/clang/test/CodeGen/constexpr-c23-internal-linkage.c @@ -0,0 +1,18 @@ +/* + * RUN: %clang_cc1 -std=c23 -emit-llvm -o - %s | FileCheck %s + */ + +constexpr int var_int = 1; +constexpr char var_char = 'a'; +constexpr float var_float = 2.5; + +const int *p_i = &var_int; +const char *p_c = &var_char; +const float *p_f = &var_float; + +/* +CHECK: @var_int = internal constant i32 1{{.*}} +CHECK: @var_char = internal constant i8 97{{.*}} +CHECK: @var_float = internal constant float 2.5{{.*}} +*/ + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use internal linkage for c23 constexpr vars. (PR #97846)
chestnykh wrote: > > > > > LGTM but please add a release note to clang/docs/ReleaseNotes.rst so > > > > > users know about the fix as well. > > > > > > > > > > > > Note that only clang 19 has `constexpr` support in C23. > > > > https://godbolt.org/z/4bThdsqK5 Release note saying that support has > > > > been implemented is already there. > > > > > > > > > Ooh oops, I thought we had this in Clang 18 > > > > > > Should I change anything? > > Sorry for the back-and-forth -- no new release note needed, so you can remove > what you added. Removed :) https://github.com/llvm/llvm-project/pull/97846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
https://github.com/chestnykh created https://github.com/llvm/llvm-project/pull/98439 Currently clang crashes with `-module-file-info` and input file which is not a module Emit error instead of segfaulting. Fix #98365 >From 716e8b7b71422b5850d2f9c3710a28bcf18ffccb Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Thu, 11 Jul 2024 09:55:55 +0300 Subject: [PATCH] [Clang] Don't crash if input file is not a module. Currently clang crashes with `-module-file-info` and input file which is not a module Emit error instead of segfaulting. Fix #98365 --- clang/include/clang/Basic/DiagnosticFrontendKinds.td | 1 + clang/lib/Frontend/FrontendActions.cpp | 10 -- clang/test/Frontend/module-file-info-not-a-module.c | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 clang/test/Frontend/module-file-info-not-a-module.c diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 85c32e55bdab3..029ae6457699e 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -226,6 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; def err_missing_module : Error< "no module named '%0' declared in module map file '%1'">, DefaultFatal; def err_no_submodule : Error<"no submodule named %0 in module '%1'">; diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 4f064321997a2..ddefa07569c55 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -841,9 +841,15 @@ static StringRef ModuleKindName(Module::ModuleKind MK) { } void DumpModuleInfoAction::ExecuteAction() { - assert(isCurrentFileAST() && "dumping non-AST?"); - // Set up the output file. CompilerInstance &CI = getCompilerInstance(); + + // Don't process files of type other than module to avoid crash + if (!isCurrentFileAST()) { +CI.getDiagnostics().Report(diag::err_file_is_not_module) << getCurrentFile(); +return; + } + + // Set up the output file. StringRef OutputFileName = CI.getFrontendOpts().OutputFile; if (!OutputFileName.empty() && OutputFileName != "-") { std::error_code EC; diff --git a/clang/test/Frontend/module-file-info-not-a-module.c b/clang/test/Frontend/module-file-info-not-a-module.c new file mode 100644 index 0..67eba2a27051b --- /dev/null +++ b/clang/test/Frontend/module-file-info-not-a-module.c @@ -0,0 +1,3 @@ +// RUN: not %clang_cc1 -module-file-info %s 2>&1 | FileCheck %s + +// CHECK: fatal error: file '{{.*}}module-file-info-not-a-module.c' is not a module ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
chestnykh wrote: CC: @ChuanqiXu9 @shafik https://github.com/llvm/llvm-project/pull/98439 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/98439 >From 716e8b7b71422b5850d2f9c3710a28bcf18ffccb Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Thu, 11 Jul 2024 09:55:55 +0300 Subject: [PATCH 1/2] [Clang] Don't crash if input file is not a module. Currently clang crashes with `-module-file-info` and input file which is not a module Emit error instead of segfaulting. Fix #98365 --- clang/include/clang/Basic/DiagnosticFrontendKinds.td | 1 + clang/lib/Frontend/FrontendActions.cpp | 10 -- clang/test/Frontend/module-file-info-not-a-module.c | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 clang/test/Frontend/module-file-info-not-a-module.c diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 85c32e55bdab3..029ae6457699e 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -226,6 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; def err_missing_module : Error< "no module named '%0' declared in module map file '%1'">, DefaultFatal; def err_no_submodule : Error<"no submodule named %0 in module '%1'">; diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 4f064321997a2..ddefa07569c55 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -841,9 +841,15 @@ static StringRef ModuleKindName(Module::ModuleKind MK) { } void DumpModuleInfoAction::ExecuteAction() { - assert(isCurrentFileAST() && "dumping non-AST?"); - // Set up the output file. CompilerInstance &CI = getCompilerInstance(); + + // Don't process files of type other than module to avoid crash + if (!isCurrentFileAST()) { +CI.getDiagnostics().Report(diag::err_file_is_not_module) << getCurrentFile(); +return; + } + + // Set up the output file. StringRef OutputFileName = CI.getFrontendOpts().OutputFile; if (!OutputFileName.empty() && OutputFileName != "-") { std::error_code EC; diff --git a/clang/test/Frontend/module-file-info-not-a-module.c b/clang/test/Frontend/module-file-info-not-a-module.c new file mode 100644 index 0..67eba2a27051b --- /dev/null +++ b/clang/test/Frontend/module-file-info-not-a-module.c @@ -0,0 +1,3 @@ +// RUN: not %clang_cc1 -module-file-info %s 2>&1 | FileCheck %s + +// CHECK: fatal error: file '{{.*}}module-file-info-not-a-module.c' is not a module >From 7995f53068f6b2831f20f1b4519fe0cd924b Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Thu, 11 Jul 2024 10:00:31 +0300 Subject: [PATCH 2/2] [Clang] Correct code style --- clang/lib/Frontend/FrontendActions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index ddefa07569c55..e70210d55fe28 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -845,7 +845,8 @@ void DumpModuleInfoAction::ExecuteAction() { // Don't process files of type other than module to avoid crash if (!isCurrentFileAST()) { -CI.getDiagnostics().Report(diag::err_file_is_not_module) << getCurrentFile(); +CI.getDiagnostics().Report(diag::err_file_is_not_module) +<< getCurrentFile(); return; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/98439 >From 716e8b7b71422b5850d2f9c3710a28bcf18ffccb Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Thu, 11 Jul 2024 09:55:55 +0300 Subject: [PATCH 1/3] [Clang] Don't crash if input file is not a module. Currently clang crashes with `-module-file-info` and input file which is not a module Emit error instead of segfaulting. Fix #98365 --- clang/include/clang/Basic/DiagnosticFrontendKinds.td | 1 + clang/lib/Frontend/FrontendActions.cpp | 10 -- clang/test/Frontend/module-file-info-not-a-module.c | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 clang/test/Frontend/module-file-info-not-a-module.c diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 85c32e55bdab3..029ae6457699e 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -226,6 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; def err_missing_module : Error< "no module named '%0' declared in module map file '%1'">, DefaultFatal; def err_no_submodule : Error<"no submodule named %0 in module '%1'">; diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 4f064321997a2..ddefa07569c55 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -841,9 +841,15 @@ static StringRef ModuleKindName(Module::ModuleKind MK) { } void DumpModuleInfoAction::ExecuteAction() { - assert(isCurrentFileAST() && "dumping non-AST?"); - // Set up the output file. CompilerInstance &CI = getCompilerInstance(); + + // Don't process files of type other than module to avoid crash + if (!isCurrentFileAST()) { +CI.getDiagnostics().Report(diag::err_file_is_not_module) << getCurrentFile(); +return; + } + + // Set up the output file. StringRef OutputFileName = CI.getFrontendOpts().OutputFile; if (!OutputFileName.empty() && OutputFileName != "-") { std::error_code EC; diff --git a/clang/test/Frontend/module-file-info-not-a-module.c b/clang/test/Frontend/module-file-info-not-a-module.c new file mode 100644 index 0..67eba2a27051b --- /dev/null +++ b/clang/test/Frontend/module-file-info-not-a-module.c @@ -0,0 +1,3 @@ +// RUN: not %clang_cc1 -module-file-info %s 2>&1 | FileCheck %s + +// CHECK: fatal error: file '{{.*}}module-file-info-not-a-module.c' is not a module >From 7995f53068f6b2831f20f1b4519fe0cd924b Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Thu, 11 Jul 2024 10:00:31 +0300 Subject: [PATCH 2/3] [Clang] Correct code style --- clang/lib/Frontend/FrontendActions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index ddefa07569c55..e70210d55fe28 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -845,7 +845,8 @@ void DumpModuleInfoAction::ExecuteAction() { // Don't process files of type other than module to avoid crash if (!isCurrentFileAST()) { -CI.getDiagnostics().Report(diag::err_file_is_not_module) << getCurrentFile(); +CI.getDiagnostics().Report(diag::err_file_is_not_module) +<< getCurrentFile(); return; } >From 0e2e2e6916e46c8167b6a0edbe2e09f83af37e8d Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Thu, 11 Jul 2024 10:30:15 +0300 Subject: [PATCH 3/3] [Clang] Extend description of the diagnostic --- clang/include/clang/Basic/DiagnosticFrontendKinds.td | 2 +- clang/test/Frontend/module-file-info-not-a-module.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 029ae6457699e..12a4617c64d87 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -226,7 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; -def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module file">, DefaultFatal; def err_missing_module : Error< "no module named '%0' declared in module map file '%1'">, DefaultFatal; def err_no_submodule : Error<"no submodule named %0 in module '%1'">; diff --git a/clang/test/Frontend/module-file-info-not-a-module.c b/clang/test/Frontend/module-file-info-not-a-module.c inde
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
@@ -226,6 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; chestnykh wrote: Done. Extended the description https://github.com/llvm/llvm-project/pull/98439 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
@@ -226,6 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; chestnykh wrote: @ChuanqiXu9 FYI i don't have commit access so when PR is ready please commit it https://github.com/llvm/llvm-project/pull/98439 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` (PR #98607)
https://github.com/chestnykh created https://github.com/llvm/llvm-project/pull/98607 Emit warning that `-S` and/or `-c` arguments are not used if `-fsyntax-only` is also passed to clang `addPGOAndCoverageFlags` is not the right place to produce this warning Now `-fsyntax-only -c/-S` combination handles like `-fsyntax-only -E` in `BuildJobs()` driver function >From ae43fc67b7d9db848ec8c4ecbcab1db6af7fcb01 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 12 Jul 2024 12:25:16 +0300 Subject: [PATCH] [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` Emit warning that `-S` and/or `-c` arguments are not used if `-fsyntax-only` is also passed to clang `addPGOAndCoverageFlags` is not the right place to produce this warning Now `-fsyntax-only -c/-S` combination handles like `-fsyntax-only -E` in `BuildJobs()` driver function --- clang/lib/Driver/ToolChains/Clang.cpp | 4 clang/test/Driver/warn-fsyntax-only-c-S.c | 9 + 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 clang/test/Driver/warn-fsyntax-only-c-S.c diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4a674f67b8e1b..4440725ccd923 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -794,10 +794,6 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, Args.hasArg(options::OPT_coverage)) FProfileDir = Args.getLastArg(options::OPT_fprofile_dir); - // TODO: Don't claim -c/-S to warn about -fsyntax-only -c/-S, -E -c/-S, - // like we warn about -fsyntax-only -E. - (void)(Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)); - // Put the .gcno and .gcda files (if needed) next to the primary output file, // or fall back to a file in the current directory for `clang -c --coverage // d/a.c` in the absence of -o. diff --git a/clang/test/Driver/warn-fsyntax-only-c-S.c b/clang/test/Driver/warn-fsyntax-only-c-S.c new file mode 100644 index 0..bb1cd5fd1183c --- /dev/null +++ b/clang/test/Driver/warn-fsyntax-only-c-S.c @@ -0,0 +1,9 @@ +// RUN: %clang -fsyntax-only -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM +// RUN: %clang -fsyntax-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-OBJ +// RUN: %clang -fsyntax-only -S -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOTH + +// CHECK-ASM: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] +// CHECK-OBJ: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] + +// CHECK-BOTH: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] +// CHECK-NEXT: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` (PR #98607)
chestnykh wrote: CC: @shafik @ChuanqiXu9 https://github.com/llvm/llvm-project/pull/98607 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` (PR #98607)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/98607 >From ae43fc67b7d9db848ec8c4ecbcab1db6af7fcb01 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 12 Jul 2024 12:25:16 +0300 Subject: [PATCH 1/2] [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` Emit warning that `-S` and/or `-c` arguments are not used if `-fsyntax-only` is also passed to clang `addPGOAndCoverageFlags` is not the right place to produce this warning Now `-fsyntax-only -c/-S` combination handles like `-fsyntax-only -E` in `BuildJobs()` driver function --- clang/lib/Driver/ToolChains/Clang.cpp | 4 clang/test/Driver/warn-fsyntax-only-c-S.c | 9 + 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 clang/test/Driver/warn-fsyntax-only-c-S.c diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4a674f67b8e1b..4440725ccd923 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -794,10 +794,6 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, Args.hasArg(options::OPT_coverage)) FProfileDir = Args.getLastArg(options::OPT_fprofile_dir); - // TODO: Don't claim -c/-S to warn about -fsyntax-only -c/-S, -E -c/-S, - // like we warn about -fsyntax-only -E. - (void)(Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)); - // Put the .gcno and .gcda files (if needed) next to the primary output file, // or fall back to a file in the current directory for `clang -c --coverage // d/a.c` in the absence of -o. diff --git a/clang/test/Driver/warn-fsyntax-only-c-S.c b/clang/test/Driver/warn-fsyntax-only-c-S.c new file mode 100644 index 0..bb1cd5fd1183c --- /dev/null +++ b/clang/test/Driver/warn-fsyntax-only-c-S.c @@ -0,0 +1,9 @@ +// RUN: %clang -fsyntax-only -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM +// RUN: %clang -fsyntax-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-OBJ +// RUN: %clang -fsyntax-only -S -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOTH + +// CHECK-ASM: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] +// CHECK-OBJ: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] + +// CHECK-BOTH: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] +// CHECK-NEXT: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] >From 607a43381a39b4a6e18a247e7a1ab9ca87690bd5 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Mon, 15 Jul 2024 09:35:40 +0300 Subject: [PATCH 2/2] [Clang][Driver] Refactor test - Rename to warn-fsyntax-only.c - Add `-fsyntax-only -E` testcase - Remove `-c -S` case because we really don't need it --- .../Driver/{warn-fsyntax-only-c-S.c => warn-fsyntax-only.c} | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename clang/test/Driver/{warn-fsyntax-only-c-S.c => warn-fsyntax-only.c} (55%) diff --git a/clang/test/Driver/warn-fsyntax-only-c-S.c b/clang/test/Driver/warn-fsyntax-only.c similarity index 55% rename from clang/test/Driver/warn-fsyntax-only-c-S.c rename to clang/test/Driver/warn-fsyntax-only.c index bb1cd5fd1183c..633aebfc54d5d 100644 --- a/clang/test/Driver/warn-fsyntax-only-c-S.c +++ b/clang/test/Driver/warn-fsyntax-only.c @@ -1,9 +1,8 @@ +// RUN: %clang -fsyntax-only -E %s 2>&1 | FileCheck %s --check-prefix=CHECK-PP // RUN: %clang -fsyntax-only -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM // RUN: %clang -fsyntax-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-OBJ -// RUN: %clang -fsyntax-only -S -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOTH +// CHECK-PP: warning: argument unused during compilation: '-fsyntax-only' [-Wunused-command-line-argument] // CHECK-ASM: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] // CHECK-OBJ: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] -// CHECK-BOTH: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] -// CHECK-NEXT: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` (PR #98607)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/98607 >From ae43fc67b7d9db848ec8c4ecbcab1db6af7fcb01 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 12 Jul 2024 12:25:16 +0300 Subject: [PATCH 1/3] [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` Emit warning that `-S` and/or `-c` arguments are not used if `-fsyntax-only` is also passed to clang `addPGOAndCoverageFlags` is not the right place to produce this warning Now `-fsyntax-only -c/-S` combination handles like `-fsyntax-only -E` in `BuildJobs()` driver function --- clang/lib/Driver/ToolChains/Clang.cpp | 4 clang/test/Driver/warn-fsyntax-only-c-S.c | 9 + 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 clang/test/Driver/warn-fsyntax-only-c-S.c diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4a674f67b8e1b..4440725ccd923 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -794,10 +794,6 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, Args.hasArg(options::OPT_coverage)) FProfileDir = Args.getLastArg(options::OPT_fprofile_dir); - // TODO: Don't claim -c/-S to warn about -fsyntax-only -c/-S, -E -c/-S, - // like we warn about -fsyntax-only -E. - (void)(Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)); - // Put the .gcno and .gcda files (if needed) next to the primary output file, // or fall back to a file in the current directory for `clang -c --coverage // d/a.c` in the absence of -o. diff --git a/clang/test/Driver/warn-fsyntax-only-c-S.c b/clang/test/Driver/warn-fsyntax-only-c-S.c new file mode 100644 index 0..bb1cd5fd1183c --- /dev/null +++ b/clang/test/Driver/warn-fsyntax-only-c-S.c @@ -0,0 +1,9 @@ +// RUN: %clang -fsyntax-only -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM +// RUN: %clang -fsyntax-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-OBJ +// RUN: %clang -fsyntax-only -S -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOTH + +// CHECK-ASM: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] +// CHECK-OBJ: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] + +// CHECK-BOTH: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] +// CHECK-NEXT: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] >From 607a43381a39b4a6e18a247e7a1ab9ca87690bd5 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Mon, 15 Jul 2024 09:35:40 +0300 Subject: [PATCH 2/3] [Clang][Driver] Refactor test - Rename to warn-fsyntax-only.c - Add `-fsyntax-only -E` testcase - Remove `-c -S` case because we really don't need it --- .../Driver/{warn-fsyntax-only-c-S.c => warn-fsyntax-only.c} | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename clang/test/Driver/{warn-fsyntax-only-c-S.c => warn-fsyntax-only.c} (55%) diff --git a/clang/test/Driver/warn-fsyntax-only-c-S.c b/clang/test/Driver/warn-fsyntax-only.c similarity index 55% rename from clang/test/Driver/warn-fsyntax-only-c-S.c rename to clang/test/Driver/warn-fsyntax-only.c index bb1cd5fd1183c..633aebfc54d5d 100644 --- a/clang/test/Driver/warn-fsyntax-only-c-S.c +++ b/clang/test/Driver/warn-fsyntax-only.c @@ -1,9 +1,8 @@ +// RUN: %clang -fsyntax-only -E %s 2>&1 | FileCheck %s --check-prefix=CHECK-PP // RUN: %clang -fsyntax-only -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM // RUN: %clang -fsyntax-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-OBJ -// RUN: %clang -fsyntax-only -S -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOTH +// CHECK-PP: warning: argument unused during compilation: '-fsyntax-only' [-Wunused-command-line-argument] // CHECK-ASM: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] // CHECK-OBJ: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] -// CHECK-BOTH: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] -// CHECK-NEXT: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] >From 1bc1ee7e0b6980048196e246d51183e5a80a9170 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Mon, 15 Jul 2024 09:37:13 +0300 Subject: [PATCH 3/3] [Clang][Driver] Remove extra newline from the test --- clang/test/Driver/warn-fsyntax-only.c | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/test/Driver/warn-fsyntax-only.c b/clang/test/Driver/warn-fsyntax-only.c index 633aebfc54d5d..b4cf74fc59855 100644 --- a/clang/test/Driver/warn-fsyntax-only.c +++ b/clang/test/Driver/warn-fsyntax-only.c @@ -5,4 +5,3 @@ // CHECK-PP: warning: argument unused during compilation: '-fsyntax-only' [-Wunused-command-line-argument] // CHECK-ASM: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] // CHECK-OBJ: warning: argument unused duri
[clang] [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` (PR #98607)
@@ -0,0 +1,9 @@ +// RUN: %clang -fsyntax-only -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM chestnykh wrote: Renamed https://github.com/llvm/llvm-project/pull/98607 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` (PR #98607)
@@ -0,0 +1,9 @@ +// RUN: %clang -fsyntax-only -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM +// RUN: %clang -fsyntax-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-OBJ +// RUN: %clang -fsyntax-only -S -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOTH + +// CHECK-ASM: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] +// CHECK-OBJ: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] + +// CHECK-BOTH: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] +// CHECK-NEXT: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] chestnykh wrote: I've added `-fsyntax-only -E` case. `-c -S` i think is like duplication of `-c` and `-S` test cases https://github.com/llvm/llvm-project/pull/98607 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits