[clang] [llvm] [ARM] Adding diagnostics for mcmodel=tiny when used in invalid targets (PR #125643)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 26 11:43:44 PDT 2025
https://github.com/ShashwathiNavada updated https://github.com/llvm/llvm-project/pull/125643
>From 0aebcd7119fbcd51154c5d9706752e8ff3f041bc Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Tue, 4 Feb 2025 00:16:09 -0600
Subject: [PATCH 1/7] Adding diagnostics for unsupported option
---
clang/lib/Frontend/CompilerInvocation.cpp | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 11fd6ab7f52a7..ac8d8be572012 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1897,6 +1897,15 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
Opts.setInlining(CodeGenOptions::NormalInlining);
}
+// -mcmodel option.
+if (const llvm::opt::Arg *A = Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ))
+{
+ llvm::StringRef modelName = A->getValue();
+ if(modelName=="tiny" && !T.isARM())
+ Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
+ << A->getSpelling() <<modelName<< T.getTriple();
+}
+
// PIC defaults to -fno-direct-access-external-data while non-PIC defaults to
// -fdirect-access-external-data.
Opts.DirectAccessExternalData =
>From f791b1d8e6006f0e5b616e5dd786c84ad34b29f3 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Tue, 4 Feb 2025 00:36:37 -0600
Subject: [PATCH 2/7] minor changes
---
clang/lib/Frontend/CompilerInvocation.cpp | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index ac8d8be572012..1242073ea6746 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1897,14 +1897,13 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
Opts.setInlining(CodeGenOptions::NormalInlining);
}
-// -mcmodel option.
-if (const llvm::opt::Arg *A = Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ))
-{
+ // -mcmodel option.
+ if (const llvm::opt::Arg *A = Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)){
llvm::StringRef modelName = A->getValue();
if(modelName=="tiny" && !T.isARM())
- Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
- << A->getSpelling() <<modelName<< T.getTriple();
-}
+ Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
+ << A->getSpelling() << modelName << T.getTriple();
+ }
// PIC defaults to -fno-direct-access-external-data while non-PIC defaults to
// -fdirect-access-external-data.
>From 689dc3a3472ff8270ee9631b235e776f5fa1a27f Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Tue, 4 Feb 2025 00:49:37 -0600
Subject: [PATCH 3/7] minor changes
---
clang/lib/Frontend/CompilerInvocation.cpp | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 1242073ea6746..15d382620d279 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1896,13 +1896,15 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
} else {
Opts.setInlining(CodeGenOptions::NormalInlining);
}
-
- // -mcmodel option.
- if (const llvm::opt::Arg *A = Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)){
+
+ // -mcmodel option.
+ if (const llvm::opt::Arg *A =
+ Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) {
llvm::StringRef modelName = A->getValue();
- if(modelName=="tiny" && !T.isARM())
+ if (modelName == "tiny" && !T.isARM()) {
Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
- << A->getSpelling() << modelName << T.getTriple();
+ << A->getSpelling() << modelName << T.getTriple();
+ }
}
// PIC defaults to -fno-direct-access-external-data while non-PIC defaults to
>From 28fcb0ee20645cd1d30dd15bfd7f6eff402ba2b9 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Tue, 4 Feb 2025 01:01:00 -0600
Subject: [PATCH 4/7] minor changes
---
clang/lib/Frontend/CompilerInvocation.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 15d382620d279..f858ec2234cb5 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1896,7 +1896,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
} else {
Opts.setInlining(CodeGenOptions::NormalInlining);
}
-
+
// -mcmodel option.
if (const llvm::opt::Arg *A =
Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) {
>From 843d4ccf4c41a78397e14eb5d9459a4921325741 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Tue, 4 Feb 2025 21:39:44 +0530
Subject: [PATCH 5/7] Addressed build fail
---
clang/lib/Frontend/CompilerInvocation.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index f858ec2234cb5..48f66931af06c 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1901,7 +1901,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
if (const llvm::opt::Arg *A =
Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) {
llvm::StringRef modelName = A->getValue();
- if (modelName == "tiny" && !T.isARM()) {
+ if (modelName == "tiny" && !(T.isARM() || T.isAArch64())) {
Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
<< A->getSpelling() << modelName << T.getTriple();
}
>From cb512f3df230d757d12421375f3d40a1243bbde3 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Tue, 11 Feb 2025 01:59:23 -0600
Subject: [PATCH 6/7] Added tests and releasenotes entry
---
clang/test/Driver/diag-mcmodel-tiny-x86.c | 2 ++
llvm/docs/ReleaseNotes.md | 3 +++
2 files changed, 5 insertions(+)
create mode 100644 clang/test/Driver/diag-mcmodel-tiny-x86.c
diff --git a/clang/test/Driver/diag-mcmodel-tiny-x86.c b/clang/test/Driver/diag-mcmodel-tiny-x86.c
new file mode 100644
index 0000000000000..e45dabeb2e241
--- /dev/null
+++ b/clang/test/Driver/diag-mcmodel-tiny-x86.c
@@ -0,0 +1,2 @@
+// RUN: not %clang --target=x86_64 -c -mcmodel=tiny %s 2>&1 | FileCheck %s
+// CHECK: error: unsupported argument 'tiny' to option '-mcmodel=' for target '{{.*}}'
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index dc8439b288957..11ae801602ea1 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -153,6 +153,9 @@ Changes to Sanitizers
Other Changes
-------------
+* The -mcmodel=tiny option for the x86 architecture now triggers a frontend diagnostic.
+
+
External Open Source Projects Using LLVM {{env.config.release}}
===============================================================
>From 0fa223c35f6f2bfcb1bc69f8bf2e7e17e2146efe Mon Sep 17 00:00:00 2001
From: Shashwathi N <nshashwa at pe31.hpc.amslabs.hpecorp.net>
Date: Wed, 26 Mar 2025 13:40:40 -0500
Subject: [PATCH 7/7] Added testcase in mcmodel.c file
---
clang/test/Driver/diag-mcmodel-tiny-x86.c | 2 --
clang/test/Driver/mcmodel.c | 3 +++
2 files changed, 3 insertions(+), 2 deletions(-)
delete mode 100644 clang/test/Driver/diag-mcmodel-tiny-x86.c
diff --git a/clang/test/Driver/diag-mcmodel-tiny-x86.c b/clang/test/Driver/diag-mcmodel-tiny-x86.c
deleted file mode 100644
index e45dabeb2e241..0000000000000
--- a/clang/test/Driver/diag-mcmodel-tiny-x86.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: not %clang --target=x86_64 -c -mcmodel=tiny %s 2>&1 | FileCheck %s
-// CHECK: error: unsupported argument 'tiny' to option '-mcmodel=' for target '{{.*}}'
diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c
index c6c8b5433d23b..b95b0f7e48cd6 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -4,6 +4,7 @@
// RUN: %clang --target=x86_64 -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=KERNEL %s
// RUN: %clang --target=x86_64 -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
// RUN: %clang --target=x86_64 -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s
+// RUN: not %clang --target=x86_64 -c -mcmodel=tiny %s 2>&1 | FileCheck %s
// RUN: not %clang -### -c --target=powerpc-linux-gnu -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s
// RUN: %clang --target=powerpc-unknown-aix -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=SMALL %s
// RUN: %clang --target=powerpc-unknown-aix -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s
@@ -44,3 +45,5 @@
// ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' for target 'aarch64_32-unknown-linux'
// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not allowed with '-fplt'
+
+// CHECK: error: unsupported argument 'tiny' to option '-mcmodel=' for target '{{.*}}'
More information about the llvm-commits
mailing list