[clang] [llvm] [ARM] Adding diagnostics for mcmodel=tiny when used in invalid targets (PR #125643)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 10 23:59:59 PST 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/6] 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 11fd6ab7f52a795..ac8d8be572012bb 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/6] 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 ac8d8be572012bb..1242073ea67461d 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/6] 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 1242073ea67461d..15d382620d2792e 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/6] 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 15d382620d2792e..f858ec2234cb5de 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/6] 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 f858ec2234cb5de..48f66931af06cec 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/6] 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 000000000000000..e45dabeb2e2418b
--- /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 dc8439b28895759..11ae801602ea1e9 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}}
 ===============================================================
 



More information about the llvm-commits mailing list