Skip to content

Commit a6cd46b

Browse files
androm3dac-rhodes
authored andcommitted
[Hexagon] Fix B0 macro conflict between hexagon_types.h and termios.h (#184539)
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 (cherry picked from commit b84ea71)
1 parent 4592b0b commit a6cd46b

2 files changed

Lines changed: 61 additions & 20 deletions

File tree

clang/lib/Headers/hexagon_types.h

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
#include <hexagon_protos.h>
1313

14+
// Save and undefine B0 to avoid conflicts with POSIX termios.h which
15+
// defines B0 as a macro for baud rate 0.
16+
#pragma push_macro("B0")
17+
#undef B0
18+
1419
/* Hexagon names */
1520
#define HEXAGON_Vect HEXAGON_Vect64
1621
#define HEXAGON_V_GET_D HEXAGON_V64_GET_D
@@ -697,9 +702,8 @@ class HEXAGON_Vect64C {
697702
};
698703

699704
// Extract byte methods
700-
signed char B0(void) {
701-
return HEXAGON_V64_GET_B0(data);
702-
};
705+
signed char b0(void) { return HEXAGON_V64_GET_B0(data); };
706+
signed char B0(void) { return b0(); };
703707
signed char B1(void) {
704708
return HEXAGON_V64_GET_B1(data);
705709
};
@@ -776,9 +780,10 @@ class HEXAGON_Vect64C {
776780
};
777781

778782
// Set byte methods
779-
HEXAGON_Vect64C B0(signed char b) {
783+
HEXAGON_Vect64C b0(signed char b) {
780784
return HEXAGON_Vect64C(HEXAGON_V64_PUT_B0(data, b));
781785
};
786+
HEXAGON_Vect64C B0(signed char b) { return b0(b); };
782787
HEXAGON_Vect64C B1(signed char b) {
783788
return HEXAGON_Vect64C(HEXAGON_V64_PUT_B1(data, b));
784789
};
@@ -1121,9 +1126,8 @@ class HEXAGON_Vect32C {
11211126
};
11221127

11231128
// Extract byte methods
1124-
signed char B0(void) {
1125-
return HEXAGON_V32_GET_B0(data);
1126-
};
1129+
signed char b0(void) { return HEXAGON_V32_GET_B0(data); };
1130+
signed char B0(void) { return b0(); };
11271131
signed char B1(void) {
11281132
return HEXAGON_V32_GET_B1(data);
11291133
};
@@ -1162,9 +1166,10 @@ class HEXAGON_Vect32C {
11621166
};
11631167

11641168
// Set byte methods
1165-
HEXAGON_Vect32C B0(signed char b) {
1169+
HEXAGON_Vect32C b0(signed char b) {
11661170
return HEXAGON_Vect32C(HEXAGON_V32_PUT_B0(data, b));
11671171
};
1172+
HEXAGON_Vect32C B0(signed char b) { return b0(b); };
11681173
HEXAGON_Vect32C B1(signed char b) {
11691174
return HEXAGON_Vect32C(HEXAGON_V32_PUT_B1(data, b));
11701175
};
@@ -1924,9 +1929,8 @@ class Q6Vect64C {
19241929
};
19251930

19261931
// Extract byte methods
1927-
signed char B0(void) {
1928-
return Q6V64_GET_B0(data);
1929-
};
1932+
signed char b0(void) { return Q6V64_GET_B0(data); };
1933+
signed char B0(void) { return b0(); };
19301934
signed char B1(void) {
19311935
return Q6V64_GET_B1(data);
19321936
};
@@ -2003,9 +2007,8 @@ class Q6Vect64C {
20032007
};
20042008

20052009
// Set byte methods
2006-
Q6Vect64C B0(signed char b) {
2007-
return Q6Vect64C(Q6V64_PUT_B0(data, b));
2008-
};
2010+
Q6Vect64C b0(signed char b) { return Q6Vect64C(Q6V64_PUT_B0(data, b)); };
2011+
Q6Vect64C B0(signed char b) { return b0(b); };
20092012
Q6Vect64C B1(signed char b) {
20102013
return Q6Vect64C(Q6V64_PUT_B1(data, b));
20112014
};
@@ -2348,9 +2351,8 @@ class Q6Vect32C {
23482351
};
23492352

23502353
// Extract byte methods
2351-
signed char B0(void) {
2352-
return Q6V32_GET_B0(data);
2353-
};
2354+
signed char b0(void) { return Q6V32_GET_B0(data); };
2355+
signed char B0(void) { return b0(); };
23542356
signed char B1(void) {
23552357
return Q6V32_GET_B1(data);
23562358
};
@@ -2389,9 +2391,8 @@ class Q6Vect32C {
23892391
};
23902392

23912393
// Set byte methods
2392-
Q6Vect32C B0(signed char b) {
2393-
return Q6Vect32C(Q6V32_PUT_B0(data, b));
2394-
};
2394+
Q6Vect32C b0(signed char b) { return Q6Vect32C(Q6V32_PUT_B0(data, b)); };
2395+
Q6Vect32C B0(signed char b) { return b0(b); };
23952396
Q6Vect32C B1(signed char b) {
23962397
return Q6Vect32C(Q6V32_PUT_B1(data, b));
23972398
};
@@ -2622,4 +2623,6 @@ typedef struct hexagon_udma_descriptor_type1_s
26222623
unsigned int dstwidthoffset:16;
26232624
} hexagon_udma_descriptor_type1_t;
26242625

2626+
#pragma pop_macro("B0")
2627+
26252628
#endif /* !HEXAGON_TYPES_H */
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// REQUIRES: hexagon-registered-target
2+
3+
// Verify that hexagon_types.h can be included after a B0 macro definition
4+
// without conflicts, that B0 is restored afterward, and that the
5+
// lowercase b0() alias is usable even while B0 is still a macro.
6+
7+
// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/../../lib/Headers/ \
8+
// RUN: -target-cpu hexagonv68 -triple hexagon-unknown-linux-musl \
9+
// RUN: -verify %s
10+
11+
// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/../../lib/Headers/ \
12+
// RUN: -target-cpu hexagonv68 -triple hexagon-unknown-linux-musl \
13+
// RUN: -x c++ -verify %s
14+
15+
// expected-no-diagnostics
16+
17+
// Simulate the POSIX termios.h B0 macro definition.
18+
#define B0 0000000
19+
20+
#include <hexagon_types.h>
21+
22+
// Verify B0 is restored after including hexagon_types.h.
23+
#ifndef B0
24+
#error "B0 should be defined after including hexagon_types.h"
25+
#endif
26+
27+
_Static_assert(B0 == 0, "B0 should still be 0 after including hexagon_types.h");
28+
29+
// In C++ mode, verify the lowercase b0() alias works even with B0 defined.
30+
#ifdef __cplusplus
31+
void test_b0_alias(void) {
32+
HEXAGON_Vect64C v(0x0807060504030201LL);
33+
signed char got = v.b0();
34+
(void)got;
35+
HEXAGON_Vect64C v2 = v.b0(0x42);
36+
(void)v2;
37+
}
38+
#endif

0 commit comments

Comments
 (0)