Fix -Wundef for FEATURE_INDEX_1.

Message ID 5362DA44.3090507@redhat.com
State Committed
Headers

Commit Message

Carlos O'Donell May 1, 2014, 11:35 p.m. UTC
  On 04/30/2014 01:55 PM, Roland McGrath wrote:
>> This is the simplest patch I can come up with to fix FEATURE_INDEX_1
>> -Wundef warnings. The constant definition is duplicated because we
>> can't use the enum constant in assembly nor in the other macros.
> 
> What does "nor in the other macros" mean?  Of course a macro can be
> based on arithmetic plus use of another constant that is usable in the
> contexts where the macro is used.  enum constants cannot be used in
> assembly, nor in #if contexts.  Did you mean to say that the other
> macros are used in #if contexts and therefore must not use enum
> constants?

Correct.

>> The down side is the slight duplication. I considered adding another
>> macro e.g.
>> #define __FEATURE_INDEX_1 0
>> ...
>> # define FEATURE_INDEX_1 __FEATURE_INDEX_1
>> ...
>> However, that just seemed ugly, so I left the duplication.
> 
> When "duplication" concretely means two instances of one macro whose
> value is zero, then it seems less ugly than many other things.  But in
> the general case, duplication is worse than most other things.
> 
> In this situation, the question is, what are we getting from
> FEATURE_INDEX_* being enum constants rather than macros at all?

Good point. Nothing really.

The enum constant use was likely a first step at making this
typo-proof, but you need to convert everything and use sym
files for assembly. Thus I find this easier and equally typo-proof.

> This is internal-only code, so ease of maintenance is really the only
> issue that we care much about.  The general reason to have enum
> constants for things is so that you can use them in the debugger rather
> than either looking up values in the source by hand or relying on -g3
> macro info.  That is far less useful than the general case when its an
> anonymous enum, so there is no type to which you can cast an integer
> value to get the symbolic name trivially in gdb.  Hence, literally the
> only benefit is typing FEATURE_INDEX_1 in gdb.  If we cared about that,
> we'd make all the macros in init-arch.h be enum constants.  So I think
> we just aren't getting anything worthwhile from having it be an enum.
> Let's eliminate the duplication by just having one unconditional #define.

Done. I've removed only the FEATURE_INDEX enum which is the only
problematic case for -Wundef.

This fixes all FEATURE_INDEX* warnings.

No regressions on x86-64 (and you'd notice, I messed this up once
and the whole testsuite falls over because it breaks ifuncs).

2014-05-01  Carlos O'Donell  <carlos@redhat.com>

	* sysdeps/x86_64/multiarch/init-arch.h:	Define FEATURE_INDEX_1 to 0.
	[!__ASSEMBLER__]: Remove anonymous enum for FEATURE_INDEX_*.

---

Cheers,
Carlos.
  

Comments

Roland McGrath May 2, 2014, 6:16 p.m. UTC | #1
That looks fine.
  
Carlos O'Donell May 3, 2014, 4:27 a.m. UTC | #2
On 05/01/2014 07:35 PM, Carlos O'Donell wrote:
> 2014-05-01  Carlos O'Donell  <carlos@redhat.com>
> 
> 	* sysdeps/x86_64/multiarch/init-arch.h:	Define FEATURE_INDEX_1 to 0.
> 	[!__ASSEMBLER__]: Remove anonymous enum for FEATURE_INDEX_*.

Fixed.

commit 8f1df5cf9d8d30c0747532301dca3cf9c99fbc8e
Author: Carlos O'Donell <carlos@redhat.com>
Date:   Sat May 3 00:25:21 2014 -0400

    Fix -Wundef warning for FEATURE_INDEX_1.
    
    Define FEATURE_INDEX_1 and FEATURE_INDEX_MAX as macros
    for use by both assembly and C code. This fixes the
    -Wundef error for cases where FEATURE_INDEX_1 was not
    defined but used the correct value of 0 for an undefined
    macro.

Cheers,
Carlos.
  

Patch

diff --git a/sysdeps/x86_64/multiarch/init-arch.h b/sysdeps/x86_64/multiarch/init-arch.h
index 813b6de..e4d265d 100644
--- a/sysdeps/x86_64/multiarch/init-arch.h
+++ b/sysdeps/x86_64/multiarch/init-arch.h
@@ -47,6 +47,12 @@ 
 #define bit_XMM_state  (1 << 1)
 #define bit_YMM_state  (2 << 1)
 
+/* The integer bit array index for the first set of internal feature bits.  */
+# define FEATURE_INDEX_1 0
+
+/* The current maximum size of the feature integer bit array.  */
+# define FEATURE_INDEX_MAX 1
+
 #ifdef __ASSEMBLER__
 
 # include <ifunc-defines.h>
@@ -82,13 +88,6 @@  enum
     COMMON_CPUID_INDEX_MAX
   };
 
-enum
-  {
-    FEATURE_INDEX_1 = 0,
-    /* Keep the following line at the end.  */
-    FEATURE_INDEX_MAX
-  };
-
 extern struct cpu_features
 {
   enum cpu_features_kind