Page MenuHomeFreeBSD

Constify a number of accesses in aesni to avoid cast-qual warnings
AbandonedPublic

Authored by dim on Jan 29 2015, 6:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
May 21 2024, 5:59 PM
Unknown Object (File)
May 19 2024, 10:30 AM
Unknown Object (File)
May 19 2024, 10:30 AM
Unknown Object (File)
May 19 2024, 3:55 AM
Unknown Object (File)
Jan 3 2024, 10:00 PM
Unknown Object (File)
May 14 2023, 6:37 AM
Unknown Object (File)
Apr 25 2023, 6:35 PM
Unknown Object (File)
Jul 2 2016, 10:23 AM
Subscribers
None

Details

Reviewers
kib
jmg
Summary

When testing with clang 3.6.0, I got a number of the following -Wcast-qual warnings (just a few shown):

sys/crypto/aesni/aesni_ghash.c:279:27: error: cast from 'const unsigned char *' to '__attribute__((__vector_size__(2 * sizeof(long long)))) long long *' drops const qualifier [-Werror,-Wcast-qual]
        __m128i *KEY = (__m128i*)key;
                                 ^
sys/crypto/aesni/aesni_ghash.c:292:33: error: cast from 'const unsigned char *' to '__attribute__((__vector_size__(2 * sizeof(long long)))) long long *' drops const qualifier [-Werror,-Wcast-qual]
                Y = _mm_loadu_si128((__m128i*)ivec);
                                              ^
sys/crypto/aesni/aesni_ghash.c:321:39: error: cast from 'const unsigned char *' to '__attribute__((__vector_size__(2 * sizeof(long long)))) long long *' drops const qualifier [-Werror,-Wcast-qual]
                        tmp1 = _mm_loadu_si128(&((__m128i*)ivec)[i]);
                                                           ^
sys/crypto/aesni/aesni_ghash.c:351:38: error: cast from 'const unsigned char *' to '__attribute__((__vector_size__(2 * sizeof(long long)))) long long *' drops const qualifier [-Werror,-Wcast-qual]
                tmp1 = _mm_loadu_si128(&((__m128i*)addt)[i*4]);
                                                   ^
sys/crypto/aesni/aesni_ghash.c:352:38: error: cast from 'const unsigned char *' to '__attribute__((__vector_size__(2 * sizeof(long long)))) long long *' drops const qualifier [-Werror,-Wcast-qual]
                tmp2 = _mm_loadu_si128(&((__m128i*)addt)[i*4+1]);
                                                   ^

In all cases I could find in aesni_ghash.c, it is no problem to use const casts, and declare a few specific variables as const, to fix all these warnings.

No functional change.

Test Plan

Compile and boot.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

dim retitled this revision from to Constify a number of accesses in aesni to avoid cast-qual warnings.
dim updated this object.
dim edited the test plan for this revision. (Show Details)
dim added reviewers: jmg, kib.

Added one additional const cast in aesni_wrap.c.

It is fine with me, but I am not an author of the code.

jmg requested changes to this revision.Jan 30 2015, 5:42 PM
jmg edited edge metadata.

actually, I consider this a bug in clang.. requiring to cast a point to add const is stupid.. I understand requiring to remove it, but adding const should not generate a warning… This just adds const for no benefit and no change..

So, no, I reject the change…

I was originally fine w/ the _wrap.c but not the _ghash.c as all the _ghash.c code is copied from the white paper, and making minor changes like these creates excessive diffs, but this case is just wrong...

This revision now requires changes to proceed.Jan 30 2015, 5:42 PM

I think clang is perfectly right about these warnings, since you *are* dropping const qualifiers. But if you don't want this change, we'll just disable -Wcast-qual for aesni instead.

Sorry, I'll accept the _wrap.c change, but would prefer not to change _ghash.c as it's contributed code…

Sorry for the misunderstanding on what was happening.. I had this compiling cleanly, and am surprised that this is a new error/warning, and did not expect that we'd get this new error/warning when we've previously had such aggressive warnings..

In D1726#12, @jmg wrote:

Sorry, I'll accept the _wrap.c change, but would prefer not to change _ghash.c as it's contributed code…

Sorry for the misunderstanding on what was happening.. I had this compiling cleanly, and am surprised that this is a new error/warning, and did not expect that we'd get this new error/warning when we've previously had such aggressive warnings..

This is a result from building the kernel in the projects/clang360-import branch. In previous versions, clang did not have a -Wcast-qual warning, but it was now implemented before 3.6.0, and it catches more instances of dropping qualifiers than gcc does (or at least, version 4.2.1 which we have in base).

In this case, it is apparently easier to just not warn about const dropping, since it is not important for the code, and since it is (partially) contributed.

I would have had to add support for disabling such warnings in the kernel anyway, sooner or later, so I might as well put it in now. That also requires no changes to sys/crypto/aesni, just a few minor additions to the Makefiles.