https://github.com/Ami-zhang created 
https://github.com/llvm/llvm-project/pull/143821

When '-march' with LASX feature and '-mno-lsx' options are used together, 
'-mno-lsx' fails to disable LASX, leaving 'HasFeatureLASX=true' and causing 
incorrect '__loongarch_sx/asx=1' macro definition.

Fixes https://github.com/loongson-community/discussions/issues/95

>From 494e4c9d3d83d08d86c04a6771fb929b0186c8a1 Mon Sep 17 00:00:00 2001
From: Ami-zhang <zhangli...@loongson.cn>
Date: Wed, 11 Jun 2025 17:30:23 +0800
Subject: [PATCH] [LoongArch] Fix '-mno-lsx' option not disabling LASX feature

When '-march' with LASX feature and '-mno-lsx' options are used
together, '-mno-lsx' fails to disable LASX, leaving
'HasFeatureLASX=true' and causing incorrect '__loongarch_sx/asx=1'
macro definition.

Fixes https://github.com/loongson-community/discussions/issues/95
---
 clang/lib/Driver/ToolChains/Arch/LoongArch.cpp | 1 +
 clang/test/Preprocessor/init-loongarch.c       | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 3318e498a74f9..33a655870b01b 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -252,6 +252,7 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
         Features.push_back("+lsx");
     } else /*-mno-lsx*/ {
       Features.push_back("-lsx");
+      Features.push_back("-lasx");
     }
   }
 
diff --git a/clang/test/Preprocessor/init-loongarch.c 
b/clang/test/Preprocessor/init-loongarch.c
index ac461b371162f..ab80449410e5c 100644
--- a/clang/test/Preprocessor/init-loongarch.c
+++ b/clang/test/Preprocessor/init-loongarch.c
@@ -946,6 +946,8 @@
 // RUN:   | FileCheck --match-full-lines --check-prefix=MNO-LSX %s
 // RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -x c -E -dM %s -o - \
 // RUN:   | FileCheck --match-full-lines --check-prefix=MNO-LSX %s
+// RUN: %clang --target=loongarch64 -march=la464 -mno-lsx -x c -E -dM %s -o - \
+// RUN:   | FileCheck --match-full-lines --check-prefix=MNO-LSX %s
 // MNO-LSX-NOT: #define __loongarch_asx
 // MNO-LSX-NOT: #define __loongarch_simd_width
 // MNO-LSX-NOT: #define __loongarch_sx

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

Reply via email to