Improve detection of builtin defines from compiler command
Needs RevisionPublic

Authored by arichardson on Apr 18 2017, 11:10 AM.

Details

Reviewers
kfunk
mwolff
Group Reviewers
KDevelop
Summary

Flags such as -fno-exceptions or -target mips64-unknown-freebsd change the value of lots of defines so should also be added to the compiler invocation that detects the builtin defines. Additionally we also detect the -x flag correctly for some -std= flags that weren't handled before such as cl1.0.

Test Plan

New test passes (at least on my system with clang 3.9)

Diff Detail

Repository
R32 KDevelop
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
arichardson created this revision.Apr 18 2017, 11:10 AM
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptApr 18 2017, 11:10 AM

It might be that some OpenCL compilers support "clx.y", but the standard doesn't seem to allow it. (Even older standards don't: https://www.khronos.org/registry/OpenCL/sdk/1.1/docs/man/xhtml/clBuildProgram.html#idp145296)

languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
63
languages/plugins/custom-definesandincludes/compilerprovider/tests/test_compilerprovider.cpp
335

Again, I think it must be capital letters. This should be unnecessary.

mwolff edited edge metadata.Apr 18 2017, 2:59 PM

excellent test coverage, much appreciated, some nitpick notes

languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
41

make the diff easier to read by keeping the old function as a per-argument version and introduce a new function that only adds the loop over the args?

102–103

does this need to be a warning?

114

? what are you worried about here?

129

QStringLiteral, also below

153

dito

174

dito

arichardson added inline comments.Apr 18 2017, 3:22 PM
languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
63

I just looked at what clang accepts, and there are probably some build systems that use it lower case. I don't think it does any harm to also accept it lowercase but I don't mind removing it.

102–103

It should of course only be a debug message (or completely silent if you prefer)

114

Can multiple threads call GccLikeCompiler::defines() at the same time? If so we would need a mutex to protect m_definesIncludes to avoid data corruption

skalinichev added inline comments.
languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
114

This code should be used from main thread only, because caller code is not thread safe (project model is used IIRC)

aaronpuchert added inline comments.Apr 18 2017, 6:35 PM
languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
63

I think that depends on whether we want full compatibility with Clang or rather stick to the OpenCL standard. I think sticking to the standard is generally the safer bet, since Clang might decide to change this anytime, but the standard won't change.

I found over the years that cross-platform development is easiest when sticking close to standards and having tools that strictly enforce the standards instead of being permissive.

arichardson marked 12 inline comments as done.

Addressed comments and made test more reliable. It will now also pass on systems that don't have CUDA stuff installed

skalinichev added inline comments.Apr 20 2017, 5:25 PM
languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
50

Does it mean that now we provide arguments like "-ferror-limit=100 -fspell-checking -Wdocumentation" to the compiler?

It won't work with gcc and old clang versions

languages/plugins/custom-definesandincludes/compilerprovider/tests/test_compilerprovider.cpp
417

Please, add tests for gcc too. Ideally all test should work equally well with clang/gcc

kfunk requested changes to this revision.Apr 27 2017, 8:20 AM

Waiting for tests for GCC

This revision now requires changes to proceed.Apr 27 2017, 8:20 AM
aaronpuchert added inline comments.Aug 13 2017, 7:44 PM
languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
45

This function is pretty complex and full of hacks, even before this change. But what bothers me most: why do we try to guess the language here?

As far as I can see, it's only used in GccLikeCompiler::defines and GccLikeCompiler::includes, which are used in CompilerProvider::defines and CompilerProvider::includes, respectively. But there we know the language (it's just languageType), so why do we try to detect it again?

I think this can be made a lot easier by redesigning some of the methods a bit.

63

There is no standard beginning with cuda, as far as I know. (See the Clang documentation.) It seems that Cuda just uses the already known C and C++ standards, if we are to believe the comments in D5210: Proper CUDA handling. I don't think we can detect Cuda from the arguments, but I also think we don't need to. (See my other comment.)

this code has changed recently, is this patch still required?

Will close next week given no-one has cared for 2 years and the affected code also changed.