llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Daniel Cederman (doac)

<details>
<summary>Changes</summary>

Used by glibc for example.

I also have an alternative option where I extend SparcCPUInfo with a family 
field instead that can be checked, if that would be more suitable than the 
switch statement.

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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/Sparc.cpp (+16) 
- (modified) clang/test/Preprocessor/predefined-arch-macros.c (+9) 


``````````diff
diff --git a/clang/lib/Basic/Targets/Sparc.cpp 
b/clang/lib/Basic/Targets/Sparc.cpp
index cd5ef7bbda457..f0b497d3eb432 100644
--- a/clang/lib/Basic/Targets/Sparc.cpp
+++ b/clang/lib/Basic/Targets/Sparc.cpp
@@ -154,12 +154,28 @@ void SparcV8TargetInfo::getTargetDefines(const 
LangOptions &Opts,
     case CG_V8:
       Builder.defineMacro("__sparcv8");
       Builder.defineMacro("__sparcv8__");
+      Builder.defineMacro("__sparc_v8__");
       break;
     case CG_V9:
       Builder.defineMacro("__sparc_v9__");
       break;
     }
   }
+  switch (CPU) {
+  case CK_LEON2:
+  case CK_LEON2_AT697E:
+  case CK_LEON2_AT697F:
+  case CK_LEON3:
+  case CK_LEON3_UT699:
+  case CK_LEON3_GR712RC:
+  case CK_LEON4:
+  case CK_LEON4_GR740:
+  case CK_LEON5:
+    Builder.defineMacro("__leon__");
+    break;
+  default:
+    break;
+  }
   if (getCPUGeneration(CPU) == CG_V9) {
     Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
     Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
diff --git a/clang/test/Preprocessor/predefined-arch-macros.c 
b/clang/test/Preprocessor/predefined-arch-macros.c
index c9295a5f2ab3c..c732348450075 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -4809,6 +4809,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC-V9
 // CHECK_SPARC-V9-NOT: #define __sparcv8 1
 // CHECK_SPARC-V9-NOT: #define __sparcv8__ 1
+// CHECK_SPARC-V9-NOT: #define __sparc_v8__ 1
 // CHECK_SPARC-V9: #define __sparc_v9__ 1
 // CHECK_SPARC-V9-NOT: #define __sparcv9 1
 // CHECK_SPARC-V9-NOT: #define __sparcv9__ 1
@@ -4833,10 +4834,18 @@
 // RUN:     -target sparcel-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARCEL
 // CHECK_SPARCEL: #define __LITTLE_ENDIAN__ 1
+// CHECK_SPARCEL-NOT: #define __leon__ 1
 // CHECK_SPARCEL: #define __sparc 1
 // CHECK_SPARCEL: #define __sparc__ 1
+// CHECK_SPARCEL: #define __sparc_v8__ 1
 // CHECK_SPARCEL: #define __sparcv8 1
 
+// RUN: %clang -mcpu=leon3 -E -dM %s -o - 2>&1 \
+// RUN:     -target sparc-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC-LEON
+// CHECK_SPARC-LEON: #define __leon__ 1
+// CHECK_SPARC-LEON: #define __sparc_v8__ 1
+
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN:     -target sparcv9-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARCV9

``````````

</details>


https://github.com/llvm/llvm-project/pull/234574
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to