https://github.com/saksham-joshi updated 
https://github.com/llvm/llvm-project/pull/138649

>From 8bba07d817d4dd583122d7ed831de276da8801e0 Mon Sep 17 00:00:00 2001
From: SAKSHAM JOSHI <social.sakshamjo...@gmail.com>
Date: Tue, 6 May 2025 12:43:34 +0530
Subject: [PATCH 1/3] FEAT: one byte for "true" & "false"

In C programming language,

The size of "true" and "false" macros is 4 byte and size of "_Bool" datatype is 
1 byte.

By this simple change, we can set the size of "true" and "false" to 1 byte.
---
 clang/lib/Headers/stdbool.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/stdbool.h b/clang/lib/Headers/stdbool.h
index dfaad2b65a9b5..e9142327f0ffd 100644
--- a/clang/lib/Headers/stdbool.h
+++ b/clang/lib/Headers/stdbool.h
@@ -22,8 +22,8 @@
  */
 #elif !defined(__cplusplus)
 #define bool _Bool
-#define true 1
-#define false 0
+#define true (bool)1
+#define false (bool)0
 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
 /* Define _Bool as a GNU extension. */
 #define _Bool bool

>From 890f5b7cb698fe6ae167247ff6453940b8f71af9 Mon Sep 17 00:00:00 2001
From: SAKSHAM JOSHI <social.sakshamjo...@gmail.com>
Date: Tue, 6 May 2025 21:24:03 +0530
Subject: [PATCH 2/3] Update stdbool.h

---
 clang/lib/Headers/stdbool.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/stdbool.h b/clang/lib/Headers/stdbool.h
index e9142327f0ffd..4b81e4ba820d1 100644
--- a/clang/lib/Headers/stdbool.h
+++ b/clang/lib/Headers/stdbool.h
@@ -22,8 +22,8 @@
  */
 #elif !defined(__cplusplus)
 #define bool _Bool
-#define true (bool)1
-#define false (bool)0
+#define true ((bool)1)
+#define false ((bool)0)
 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
 /* Define _Bool as a GNU extension. */
 #define _Bool bool

>From 1ad7042ac9c09aa7274c9c40084fc496b5ed93a4 Mon Sep 17 00:00:00 2001
From: SAKSHAM JOSHI <social.sakshamjo...@gmail.com>
Date: Wed, 7 May 2025 07:40:16 +0530
Subject: [PATCH 3/3] FEAT: 1 byte for "true" & "false"

In C language,

the size of "true" and "false" macro is 4 bytes (for x64 arch)

but the size of "bool" (typedef _Bool) is 1 byte.

In order to decrease the memory usage, we can set the size of "true" and 
"false" macros to 1 byte using explicit typecasting in macro definition.
---
 clang/lib/Headers/stdbool.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/stdbool.h b/clang/lib/Headers/stdbool.h
index 4b81e4ba820d1..0aa017e58c3c7 100644
--- a/clang/lib/Headers/stdbool.h
+++ b/clang/lib/Headers/stdbool.h
@@ -22,8 +22,10 @@
  */
 #elif !defined(__cplusplus)
 #define bool _Bool
-#define true ((bool)1)
-#define false ((bool)0)
+#define true 1
+#define false 0
+#define true_1 ((bool)1)
+#define false_1 ((bool)0)
 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
 /* Define _Bool as a GNU extension. */
 #define _Bool bool

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

Reply via email to