This code: _Bool bar (_Bool a); _Bool foo1 (_Bool a) { if (bar(a)) return 1; else return 0; } static short barshort (short a); short foo1short (short a) { if (barshort(a)) return 1; else return 0; } is transformed to: (when using -O -fdump-tree-generic) foo1 (a) { int T.17; _Bool T.18; T.17 = (int)a; <------ this is not needed T.18 = bar (T.17); if (T.18 != 0) { return 1; } else { return 0; } } foo1short (a) { int T.19; short int T.20; T.19 = (int)a; <------ this is not needed T.20 = barshort (T.19); if (T.20 != 0) { return 1; } else { return 0; } } the promotions shown are not needed, at least not at this point in the compilation process.
Confirmed.
The underlying ABI might require short & bool arguments to be passed as int. Some do, some don't. Anyway, that's an argument marshalling issue, which is not currently addressed at the tree level. The cast to int has been inserted by the front end, I think C requires that. This is a VRP issue, not an argument marshalling one.
(In reply to comment #2) > The underlying ABI might require short & bool arguments to be passed as int. > Some do, some don't. Anyway, that's an argument marshalling issue, which is not > currently addressed at the tree level. > > The cast to int has been inserted by the front end, I think C requires that. > > This is a VRP issue, not an argument marshalling one. A discussion about this is at: http://gcc.gnu.org/ml/gcc/2004-05/msg00752.html in that thread Jim Wilson has some more explanations about what is going on. A patch that seems to work is also in that mail, but I won't have time to properly test it to try to get it committed anytime soon. If someone wants to play with this, it would be great. The problem is that the C and C++ front-ends generate casts to int when c_promoting_integer_type_p returns true. Those casts are generated too early (if they are needed at all, and they might not be needed). Iff the casts are needed they should be when lowering to RTL.
Maybe the same problem results in static inline bool wrap(bool f) { return f; } bool bar(bool f) { return wrap(f); } producing return (int) (bool) (int) (bool) (int) f; (and more, if you add another wrap())
How is this related to VRP at all? Removing dependency on 18373.
Still happens in 4.4.
(In reply to comment #6) > Still happens in 4.4. But as mentioned this is not really a bug.