[clang] [Hexagon] Fix B0 macro conflict between hexagon_types.h and termios.h (PR #184539)
Brian Cain via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 5 08:35:00 PST 2026
https://github.com/androm3da updated https://github.com/llvm/llvm-project/pull/184539
>From a1737c87f1ecde69f401a584971d89e1bf4885fe Mon Sep 17 00:00:00 2001
From: Brian Cain <brian.cain at oss.qualcomm.com>
Date: Sun, 1 Mar 2026 16:27:47 -0800
Subject: [PATCH 1/2] [Hexagon] Fix B0 macro conflict between hexagon_types.h
and termios.h
POSIX termios.h defines `#define B0 0000000` for baud rate 0. This
conflicts with the B0() member functions in hexagon_types.h vector
classes, causing compilation failures when both headers are included.
Use #pragma push_macro/pop_macro to save, undefine, and restore B0
around the class definitions so the header is safe to use alongside
termios.h without losing the macro afterward.
Fixes #183815
---
clang/lib/Headers/hexagon_types.h | 7 +++++
.../test/Headers/hexagon-types-b0-conflict.c | 26 +++++++++++++++++++
2 files changed, 33 insertions(+)
create mode 100644 clang/test/Headers/hexagon-types-b0-conflict.c
diff --git a/clang/lib/Headers/hexagon_types.h b/clang/lib/Headers/hexagon_types.h
index 8e73fad4bcd42..2076a2331126e 100644
--- a/clang/lib/Headers/hexagon_types.h
+++ b/clang/lib/Headers/hexagon_types.h
@@ -11,6 +11,11 @@
#include <hexagon_protos.h>
+// Save and undefine B0 to avoid conflicts with POSIX termios.h which
+// defines B0 as a macro for baud rate 0.
+#pragma push_macro("B0")
+#undef B0
+
/* Hexagon names */
#define HEXAGON_Vect HEXAGON_Vect64
#define HEXAGON_V_GET_D HEXAGON_V64_GET_D
@@ -2622,4 +2627,6 @@ typedef struct hexagon_udma_descriptor_type1_s
unsigned int dstwidthoffset:16;
} hexagon_udma_descriptor_type1_t;
+#pragma pop_macro("B0")
+
#endif /* !HEXAGON_TYPES_H */
diff --git a/clang/test/Headers/hexagon-types-b0-conflict.c b/clang/test/Headers/hexagon-types-b0-conflict.c
new file mode 100644
index 0000000000000..ea8c349c7ec64
--- /dev/null
+++ b/clang/test/Headers/hexagon-types-b0-conflict.c
@@ -0,0 +1,26 @@
+// REQUIRES: hexagon-registered-target
+
+// Verify that hexagon_types.h can be included after termios.h without
+// B0 macro conflicts, and that B0 is restored afterward.
+
+// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/../../lib/Headers/ \
+// RUN: -target-cpu hexagonv68 -triple hexagon-unknown-linux-musl \
+// RUN: -verify %s
+
+// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/../../lib/Headers/ \
+// RUN: -target-cpu hexagonv68 -triple hexagon-unknown-linux-musl \
+// RUN: -x c++ -verify %s
+
+// expected-no-diagnostics
+
+// Simulate the POSIX termios.h B0 macro definition.
+#define B0 0000000
+
+#include <hexagon_types.h>
+
+// Verify B0 is restored after including hexagon_types.h.
+#ifndef B0
+#error "B0 should be defined after including hexagon_types.h"
+#endif
+
+_Static_assert(B0 == 0, "B0 should still be 0 after including hexagon_types.h");
>From bb4ead5c7266650e4be390ac836ddec8c51857ae Mon Sep 17 00:00:00 2001
From: Brian Cain <brian.cain at oss.qualcomm.com>
Date: Thu, 5 Mar 2026 08:34:14 -0800
Subject: [PATCH 2/2] fixup! [Hexagon] Fix B0 macro conflict between
hexagon_types.h and termios.h
fixup! [Hexagon] Fix B0 macro conflict between hexagon_types.h and termios.h
Add lowercase b0() aliases as the primary implementation for the B0()
getter/setter member functions across all four vector classes. The
uppercase B0() now delegates to b0(), providing a macro-safe alternative
for code that also includes termios.h.
---
clang/lib/Headers/hexagon_types.h | 36 +++++++++----------
.../test/Headers/hexagon-types-b0-conflict.c | 16 +++++++--
2 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/clang/lib/Headers/hexagon_types.h b/clang/lib/Headers/hexagon_types.h
index 2076a2331126e..54e8c1dd6937b 100644
--- a/clang/lib/Headers/hexagon_types.h
+++ b/clang/lib/Headers/hexagon_types.h
@@ -702,9 +702,8 @@ class HEXAGON_Vect64C {
};
// Extract byte methods
- signed char B0(void) {
- return HEXAGON_V64_GET_B0(data);
- };
+ signed char b0(void) { return HEXAGON_V64_GET_B0(data); };
+ signed char B0(void) { return b0(); };
signed char B1(void) {
return HEXAGON_V64_GET_B1(data);
};
@@ -781,9 +780,10 @@ class HEXAGON_Vect64C {
};
// Set byte methods
- HEXAGON_Vect64C B0(signed char b) {
+ HEXAGON_Vect64C b0(signed char b) {
return HEXAGON_Vect64C(HEXAGON_V64_PUT_B0(data, b));
};
+ HEXAGON_Vect64C B0(signed char b) { return b0(b); };
HEXAGON_Vect64C B1(signed char b) {
return HEXAGON_Vect64C(HEXAGON_V64_PUT_B1(data, b));
};
@@ -1126,9 +1126,8 @@ class HEXAGON_Vect32C {
};
// Extract byte methods
- signed char B0(void) {
- return HEXAGON_V32_GET_B0(data);
- };
+ signed char b0(void) { return HEXAGON_V32_GET_B0(data); };
+ signed char B0(void) { return b0(); };
signed char B1(void) {
return HEXAGON_V32_GET_B1(data);
};
@@ -1167,9 +1166,10 @@ class HEXAGON_Vect32C {
};
// Set byte methods
- HEXAGON_Vect32C B0(signed char b) {
+ HEXAGON_Vect32C b0(signed char b) {
return HEXAGON_Vect32C(HEXAGON_V32_PUT_B0(data, b));
};
+ HEXAGON_Vect32C B0(signed char b) { return b0(b); };
HEXAGON_Vect32C B1(signed char b) {
return HEXAGON_Vect32C(HEXAGON_V32_PUT_B1(data, b));
};
@@ -1929,9 +1929,8 @@ class Q6Vect64C {
};
// Extract byte methods
- signed char B0(void) {
- return Q6V64_GET_B0(data);
- };
+ signed char b0(void) { return Q6V64_GET_B0(data); };
+ signed char B0(void) { return b0(); };
signed char B1(void) {
return Q6V64_GET_B1(data);
};
@@ -2008,9 +2007,8 @@ class Q6Vect64C {
};
// Set byte methods
- Q6Vect64C B0(signed char b) {
- return Q6Vect64C(Q6V64_PUT_B0(data, b));
- };
+ Q6Vect64C b0(signed char b) { return Q6Vect64C(Q6V64_PUT_B0(data, b)); };
+ Q6Vect64C B0(signed char b) { return b0(b); };
Q6Vect64C B1(signed char b) {
return Q6Vect64C(Q6V64_PUT_B1(data, b));
};
@@ -2353,9 +2351,8 @@ class Q6Vect32C {
};
// Extract byte methods
- signed char B0(void) {
- return Q6V32_GET_B0(data);
- };
+ signed char b0(void) { return Q6V32_GET_B0(data); };
+ signed char B0(void) { return b0(); };
signed char B1(void) {
return Q6V32_GET_B1(data);
};
@@ -2394,9 +2391,8 @@ class Q6Vect32C {
};
// Set byte methods
- Q6Vect32C B0(signed char b) {
- return Q6Vect32C(Q6V32_PUT_B0(data, b));
- };
+ Q6Vect32C b0(signed char b) { return Q6Vect32C(Q6V32_PUT_B0(data, b)); };
+ Q6Vect32C B0(signed char b) { return b0(b); };
Q6Vect32C B1(signed char b) {
return Q6Vect32C(Q6V32_PUT_B1(data, b));
};
diff --git a/clang/test/Headers/hexagon-types-b0-conflict.c b/clang/test/Headers/hexagon-types-b0-conflict.c
index ea8c349c7ec64..a27712ab9d3a2 100644
--- a/clang/test/Headers/hexagon-types-b0-conflict.c
+++ b/clang/test/Headers/hexagon-types-b0-conflict.c
@@ -1,7 +1,8 @@
// REQUIRES: hexagon-registered-target
-// Verify that hexagon_types.h can be included after termios.h without
-// B0 macro conflicts, and that B0 is restored afterward.
+// Verify that hexagon_types.h can be included after a B0 macro definition
+// without conflicts, that B0 is restored afterward, and that the
+// lowercase b0() alias is usable even while B0 is still a macro.
// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/../../lib/Headers/ \
// RUN: -target-cpu hexagonv68 -triple hexagon-unknown-linux-musl \
@@ -24,3 +25,14 @@
#endif
_Static_assert(B0 == 0, "B0 should still be 0 after including hexagon_types.h");
+
+// In C++ mode, verify the lowercase b0() alias works even with B0 defined.
+#ifdef __cplusplus
+void test_b0_alias(void) {
+ HEXAGON_Vect64C v(0x0807060504030201LL);
+ signed char got = v.b0();
+ (void)got;
+ HEXAGON_Vect64C v2 = v.b0(0x42);
+ (void)v2;
+}
+#endif
More information about the cfe-commits
mailing list