Bugzilla – Bug 1388
LTE module doesn't build in optimized mode with GCC 4.7
Last modified: 2012-03-18 15:45:21 UTC
Created attachment 1352 [details] Introduce break in while loop [ 738/1225] cxx: src/lte/model/amc-module.cc -> build/optimized/src/lte/model/amc-module.cc.1.o ../../src/lte/model/amc-module.cc: In member function 'int ns3::AmcModule::GetCqiFromSpectralEfficiency(double)': ../../src/lte/model/amc-module.cc:123:43: error: array subscript is above array bounds [-Werror=array-bounds] cc1plus: all warnings being treated as errors To the best of my understanding, this patch produces functionality wise eqivalent code that builds with GCC 4.7. All tests pass.
Giuseppe, is this code OK for inclusion?
The patch is OK for me.
I'm not happy with the patch... sorry if I'm pedantic. The problem seems to be more subtle, and silencing the compiler by obfuscating the code isn't very wise. I have to confess that the compiler is smart indeed, and it found an obscure vector boundary issue. while (SpectralEfficiencyForCqiIndex[cqi] < s && cqi <= 14) { [...] } Problem: the check is done sequentially (it's an and), so when cqi is 15 the first vector will go out of boundaries. The second check will return false and the while will stop. A smarter solution is to invert the checks. while ( cqi <= 14 && SpectralEfficiencyForCqiIndex[cqi] < s ) { [...] } This should make the compiler happy again. I can't check, but if the error goes away, this is way cleaner. Cheers, T.
Tommaso, you are right, just tested it and it works. Talk about commutativity of && operation. While at being pedantic about this while (pun intended), let's go a bit further and make it like: while (cqi < 15 && SpectralEfficiencyForCqiIndex[cqi] < s) which is somewhat more C++ style. Whichever way, let's commit this.
+1, go ahead. T.
changeset: 7768:7d43ccc63a96 tag: tip user: Vedran Miletić <rivanvx@gmail.com> date: Sun Mar 18 20:43:18 2012 +0100 summary: Bug 1388 - LTE module doesn't build in optimized mode with GCC 4.7