New warning in clang 3.8svn breaks compiling ThirdParty/libJPG/jpgd.cpp

Not sure if you want bugreports for new clang/llvm versions, but this is going to be relevant once it’s released anyway, so might as well report it now.

Here is the change: ⚙ D10938 [Sema] Warn when shifting a negative value. Tl;dr: Stuff like “-1 << 3” will be reported as a warning in clang 3.8 so compiling with -Werror will fail:

[172/775] Compile Module.TargetPlatform.cpp
In file included from /mnt/backup/stuff/unreal/UnrealEngine/Engine/Intermediate/Build/Linux/x86_64-unknown-linux-gnu/UE4Editor/Development/ImageWrapper/Module.ImageWrapper.cpp:9:
In file included from /mnt/backup/stuff/unreal/UnrealEngine/Engine/Source/Developer/ImageWrapper/Private/JpegImageWrapper.cpp:14:
ThirdParty/libJPG/jpgd.cpp:569:51: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
        static const int s_extend_offset[16] = { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
                                                     ~~~~^

In the whole Unreal Editor source this is the only line that has a problem with current clang 3.8svn.

Hey haagch-

Did this occur when building a project or trying to build the engine? If this was when building a project were you building a new project or an existing one? Does this error occur with other versions of the engine as well?

Cheers

I didn’t say but it was on linux and I did what the wiki says to compile the editor:
make UE4Editor UE4Game UnrealPak CrashReportClient ShaderCompileWorker UnrealLightmass

From the error message it’s in the third party jpeg-compressor library that is used by the editor.

Note: This is with a development version of clang 3.8 which is not yet released. I believe that with the current stable releases of clang this warning does not exist yet and the build succeeds (I haven’t tested it).

The code probably still relies on undefined behavior so fixing it wouldn’t be a bad thing anyway.

It will help us to know if this is only happening when you try to build the 4.9 engine or if it happens with other engines versions as well.

Well, jpgd.cpp has been used since 4.0, so I assume it would happen in every version.

https://github.com/EpicGames/UnrealEngine/blob/4.0/Engine/Source/Developer/ImageWrapper/Private/JpegImageWrapper.cpp#L21

Not sure how this is supposed to help. It’s just something that should be fixed before the llvm/clang 3.8 releae. Considering 3.7 was only released about 2 days ago, that will be quite some time in the future, so lots of time until then…

Hey haagch-

Thank you for the information. It will help us fix this when we test with 3.8. If you come across a solution to fix this in the mean time then you can enter a pull request for your fix to be included into the engine.

Cheers

Same thing with clang package on Arch (ie. clang 3.7) btw.

There is pull request on the Unreal Engine github account with a fix.

Yep, I just did some research to and came up with this:

being the ‘problematic’ clang commit. Hope it gets merged, while this I will cherry-pick it

Man, i have installer clang-3.7 for works with cry engine but i don’t know ho compile UnrealEngine with it.
When i do ./GenerateProjectFiles.sh i have the next error:

*** This version of the engine can only be compiled by clang - refusing to register the Linux toolchain.

Generating data for project indexing... 0%
UnrealBuildTool Exception: ERROR: GetPlatformToolChain: No tool chain found for Linux

Problem still present(Arch, clang 3.7.0-5, UE branch 4.10). Stupid but working solution just replace 569 line in Engine/Source/ThirdParty/libJPG/jpgd.cpp for

static const int s_extend_offset[16] = { 0, (-(1<<1)) + 1, (-(1<<2)) + 1, (-(1<<3)) + 1, (-(1<<4)) + 1, (-(1<<5)) + 1, (-(1<<6)) + 1, (-(1<<7)) + 1, (-(1<<8)) + 1, (-(1<<9)) + 1, (-(1<<10)) + 1, (-(1<<11)) + 1, (-(1<<12)) + 1, (-(1<<13)) + 1, (-(1<<14)) + 1, (-(1<<15)) + 1 };

Hey Kitsu-

I’m glad you were able to find a solution that worked for you. The engine currently does not support versions of Clang beyond 3.6 however we do plan to include support for other versions in the future. It is recommended to use 3.6 for the time being, though as you’ve pointed out it is possible to edit the source code to work with other versions.

Cheers

Would be nice to actually link to the pull request. I randomly found it:
https://github.com/EpicGames/UnrealEngine/pull/1704 with a commit
“disable “-Wshift-negative-value” for clang >= 3.7.0 which makes possible to compile libJPG,”

There’s also a pull request in the upstream jpeg-compressor project that simply replaces the shifts with the intended values: new "shifting a negative signed value is undefined" warning in clang 3.8svn · Issue #8 · richgel999/jpeg-compressor · GitHub

I have just made the equivalent change in one of our internal streams, rather than disabling the warning. It will make its way into our GitHub repo at some future point, and presumably the 4.11 release.

Steve