Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 330635 - CDT parser has to interpret __attribute__ ((__mode__ (__DI__))), etc
Summary: CDT parser has to interpret __attribute__ ((__mode__ (__DI__))), etc
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 7.0.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 8.1.0   Edit
Assignee: Sergey Prigogin CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
: 375105 (view as bug list)
Depends on: 316230
Blocks:
  Show dependency tree
 
Reported: 2010-11-18 21:51 EST by Sergey Prigogin CLA
Modified: 2012-04-13 15:18 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Prigogin CLA 2010-11-18 21:51:49 EST
In recent versions of gcc int32_t and int64_t are defined (in sys/types.h) as:

typedef int int32_t __attribute__ ((__mode__ (__SI__)))
typedef int int64_t __attribute__ ((__mode__ (__DI__)))

Without taking the attributes into account int32_t and int64_t map to the same type, which causes name resolution problems for functions overloaded for these types.

There are more modes like __SI__ and __DI__. A complete list is available in http://gcc.gnu.org/onlinedocs/gccint/Machine-Modes.html#Machine-Modes.
Comment 1 Sergey Prigogin CLA 2010-11-18 22:13:40 EST
A workaround for this issue is to include stdint.h in the list of the files to index up-front before sys/resource.h. stdint.h provides alternative, easier to handle definitions for int32_t and int64_t:

/* There is some amount of overlap with <sys/types.h> as known by inet code */
#ifndef __int8_t_defined
# define __int8_t_defined
typedef signed char		int8_t;
typedef short int		int16_t;
typedef int			int32_t;
# if __WORDSIZE == 64
typedef long int		int64_t;
# else
__extension__
typedef long long int		int64_t;
# endif
#endif

sys/resource.h in my version of gcc includes sys/types.h, so stdint.h has to be in front of it.
Comment 2 Sergey Prigogin CLA 2010-11-20 16:40:15 EST
The workaround described in comment #1 doesn't solve the problem since the __int8_t_defined macro, which is defined in stdint.h becomes undefined again when sys/types.h is parsed. I don't quite understand why macro definitions don't propagate between files parsed up front. This seems problematic since, as this example shows, gcc includes contain conflicting definitions of some bindings.

Marcus, do you know why macro definitions don't propagate between files parsed up-front?

Given the current behavior for parsing files up-front, the last definition wins. This leads to an alternative workaround - adding stdint.h AFTER sys/types.h.
Comment 3 Sergey Prigogin CLA 2010-11-20 16:44:52 EST
For reference here is a code fragment from sys/types.h that defines int32_t and int64_t:

# define __intN_t(N, MODE) \
  typedef int int##N##_t __attribute__ ((__mode__ (MODE)))
# define __u_intN_t(N, MODE) \
  typedef unsigned int u_int##N##_t __attribute__ ((__mode__ (MODE)))

# ifndef __int8_t_defined
#  define __int8_t_defined
__intN_t (8, __QI__);
__intN_t (16, __HI__);
__intN_t (32, __SI__);
__intN_t (64, __DI__);
# endif
Comment 4 Markus Schorn CLA 2010-11-24 03:00:56 EST
(In reply to comment #2)
> ...
> Marcus, do you know why macro definitions don't propagate between files parsed
> up-front?
> ...
Macro definitions are always taken from the actual files included. I assume that <stdint.h> is not included where <sys/types.h> is parsed. As a workaround you can configure the indexer with:
-D__int8_t_defined "-Dint8_t=signed char" ...
Comment 5 Sergey Prigogin CLA 2010-11-24 21:51:47 EST
(In reply to comment #4)
Markus, do you know what would break if the files parsed up-front were parsed together, as if they were included in the same source file?
Comment 6 Markus Schorn CLA 2010-11-25 03:31:45 EST
(In reply to comment #5)
> (In reply to comment #4)
> Markus, do you know what would break if the files parsed up-front were parsed
> together, as if they were included in the same source file?
I'd expect no problems. You can try this by specifying a single file to be parsed up-front and put the includes in there. 

Off topic: The users don't understand the mechanism of parsing files up front, therefore I think we should remove the preference from the ui. Instead of that we could parse a file up-front that is located in the installation, where modifications can be made if necessary.
Comment 7 Sergey Prigogin CLA 2010-11-30 13:46:19 EST
(In reply to comment #6)
> Off topic: The users don't understand the mechanism of parsing files up front,
> therefore I think we should remove the preference from the ui. Instead of that
> we could parse a file up-front that is located in the installation, where
> modifications can be made if necessary.

Agree.
Comment 8 Sergey Prigogin CLA 2012-03-28 11:01:56 EDT
Attributes have to added to AST. Without the attribute there are name resolution problems with
overloaded functions, for example:

void foo(int i);
void foo(int64_t i);

Here are relevant documents:
http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html, C++11 (ISO/IEC 14882:2011) Section 7.6.
Comment 9 Sergey Prigogin CLA 2012-03-28 11:02:25 EDT
*** Bug 375105 has been marked as a duplicate of this bug. ***
Comment 10 Sergey Prigogin CLA 2012-04-13 15:18:53 EDT
Fixed in master.