From f1aaf92afb58e9fee330ede36b9775fe2a6e5a27 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Sat, 31 Oct 2015 19:40:33 +0000 Subject: Improve diagnostics if IWYU is enabled Few small cleanups from clang --- src/shared/stackdata.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/shared/stackdata.cpp') diff --git a/src/shared/stackdata.cpp b/src/shared/stackdata.cpp index 6c5a0968..18daaf7b 100644 --- a/src/shared/stackdata.cpp +++ b/src/shared/stackdata.cpp @@ -24,7 +24,7 @@ static void initDbgIfNecess() firstCall = false; } if (!::SymInitialize(process, NULL, TRUE)) { - printf("failed to initialize symbols: %d", ::GetLastError()); + printf("failed to initialize symbols: %lu", ::GetLastError()); } initialized.insert(::GetCurrentProcessId()); } -- cgit v1.3.1 From a284cbf232f34cc1a83b85ec45baafc1ce6518ec Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Mon, 9 Nov 2015 18:16:58 +0000 Subject: Yet more changes for include what you use, including a moderate hack for compiling stackdata with clang --- SConstruct | 43 +++++++++++++++++++++++-------------------- massage_messages.py | 41 +++++++++++++++++++++++++++++------------ src/shared/stackdata.cpp | 3 ++- 3 files changed, 54 insertions(+), 33 deletions(-) (limited to 'src/shared/stackdata.cpp') diff --git a/SConstruct b/SConstruct index 7af00c82..57111773 100644 --- a/SConstruct +++ b/SConstruct @@ -337,8 +337,7 @@ def setup_IWYU(env): # except it eats errors iwyu = SCons.Builder.Builder( action=[ - '$IWYU_MASSAGE $IWYU $IWYU_FLAGS $IWYU_MAPPINGS $IWYU_COMCOM $SOURCE', - Touch('$TARGET') + '$IWYU_MASSAGE $TARGET $IWYU $IWYU_FLAGS $IWYU_MAPPINGS $IWYU_COMCOM $SOURCE' ], emitter=emitter, suffix='.iwyu', @@ -346,27 +345,26 @@ def setup_IWYU(env): env.Append(BUILDERS={'IWYU': iwyu}) - # Sigh - IWYU is a right bum as it doesn't recognise /I so I have to duplicate most of the usual stuff. Worse, half the - # flags are irrelevant immaterial and incompetent and I can't use an environment clone because it takes stuff from the - # wrong environment. + # Sigh - IWYU is a right bum as it doesn't recognise /I so I have to + # duplicate most of the usual stuff - # There has to be a better way of doing this. 'begins with Q means system header'??? - # Also, I can't get this to show issues in the issue window which sucks env['IWYU_FLAGS'] = [ # This might turn down the output a bit. I hope '-Xiwyu', '--transitive_includes_only', + # Seem to be needed for a windows build '-D_MT', '-D_DLL', '-m32', # This is something to do with clang, windows and boost headers '-DBOOST_USE_WINDOWS_H', # There's a lot of this, disabled for now '-Wno-inconsistent-missing-override', + # Mark boost and Qt headers as system headers to disable a lot of noise. + # I'm sure there has to be a better way than saying 'prefix=Q' '--system-header-prefix=Q', '--system-header-prefix=boost/', - # clang says it sets this to 1700 but pretty sure vc12 is 1800 - #'-fmsc-version=1800', '-D_MSC_VER=1800', - '-fmsc-version=1700', - # clang and qt don't agree about these because clang says its gcc 4.2 and - # QT doesn't realise it's clang + # Should be able to get this info from our setup really + '-fmsc-version=1800', '-D_MSC_VER=1800', + # clang and qt don't agree about these because clang says its gcc 4.2 + # and QT doesn't realise it's clang '-DQ_COMPILER_INITIALIZER_LISTS', '-DQ_COMPILER_DECLTYPE', '-DQ_COMPILER_VARIADIC_TEMPLATES', @@ -376,22 +374,27 @@ def setup_IWYU(env): env['IWYU_DEFPREFIX'] = '-D' env['IWYU_DEFSUFFIX'] = '' + env['IWYU_CPPDEFFLAGS'] = '${_defines(IWYU_DEFPREFIX, CPPDEFINES, IWYU_DEFSUFFIX, __env__)}' + env['IWYU_INCPREFIX'] = '-I' env['IWYU_INCSUFFIX'] = '' - env['IWYU_INCLUDEPREFIX'] = '-include' # Amazingly this works without a space - env['IWYU_INCLUDESUFFIX'] = '' - env['IWYU_COMCOM'] = '$IWYU_CPPDEFFLAGS $IWYU_CPPINCFLAGS $IWYU_PCHFILES $CCPDBFLAGS' - env['IWYU_CPPDEFFLAGS'] = '${_defines(IWYU_DEFPREFIX, CPPDEFINES, IWYU_DEFSUFFIX, __env__)}' env['IWYU_CPPINCFLAGS'] = '$( ${_concat(IWYU_INCPREFIX, CPPPATH, IWYU_INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)' - env['IWYU_PCHFILES'] = '$( ${_concat(IWYU_INCLUDEPREFIX, PCHSTOP, IWYU_INCLUDESUFFIX, __env__, target=TARGET, source=SOURCE)} $)' + + env['IWYU_PCH_PREFIX'] = '-include' # Amazingly this works without a space + env['IWYU_PCH_SUFFIX'] = '' + env['IWYU_PCHFILES'] = '$( ${_concat(IWYU_PCH_PREFIX, PCHSTOP, IWYU_PCH_SUFFIX, __env__, target=TARGET, source=SOURCE)} $)' + + env['IWYU_COMCOM'] = '$IWYU_CPPDEFFLAGS $IWYU_CPPINCFLAGS $IWYU_PCHFILES $CCPDBFLAGS' + env['IWYU_MAPPING_PREFIX'] = ['-Xiwyu', '--mapping_file='] + env['IWYU_MAPPING_SUFFIX'] = '' + env['IWYU_MAPPINGS'] = '$( ${_concat_list(IWYU_MAPPING_PREFIX, IWYU_MAPPING_FILE, IWYU_MAPPING_SUFFIX, __env__, f=lambda l: [ str(x) for x in l], target=TARGET, source=SOURCE)} $)' + env['IWYU_MAPPING_FILE'] = [ env.File('#/modorganizer/qt5_4.imp'), env.File('#/modorganizer/win.imp'), env.File('#/modorganizer/mappings.imp') ] - env['IWYU_MAPPING_PREFIX'] = ['-Xiwyu', '--mapping_file='] - env['IWYU_MAPPING_SUFFIX'] = '' - env['IWYU_MAPPINGS'] = '$( ${_concat_list(IWYU_MAPPING_PREFIX, IWYU_MAPPING_FILE, IWYU_MAPPING_SUFFIX, __env__, f=lambda l: [ str(x) for x in l], target=TARGET, source=SOURCE)} $)' + env['IWYU_MASSAGE'] = env.File('#/modorganizer/massage_messages.py') # Create base environment diff --git a/massage_messages.py b/massage_messages.py index 708c09cc..249068ba 100644 --- a/massage_messages.py +++ b/massage_messages.py @@ -34,7 +34,9 @@ includes = dict foundline = 0 -def process_next_line(line): +errors = False + +def process_next_line(line, outfile): """ Read a line of output/error from include-what-you use Turn clang errors into a form QT creator recognises Raise warnings for unneeded includes @@ -42,37 +44,48 @@ def process_next_line(line): global removing global includes global foundline + global errors line = line.rstrip() + print >> outfile, line if removing: if line == '': removing = None print return else: - # Really we should stash these so that if we get a 'class xxx' in the - # add lines we can print it here. also we could do the case fixing. + # Really we should stash these so that if we get a 'class xxx' in + # the add lines we can print it here. also we could do the case + # fixing. m = re.match(r'- #include [<"](.*)[">] +// lines (.*)-', line) if m: # If there is an added line with the same class, print it here - print '%s(%s) : warning I0001: Unnecessary include of %s' % (removing, m.group(2), m.group(1)) + print '%s(%s) : warning I0001: Unnecessary include of %s' %\ + (removing, m.group(2), m.group(1)) foundline = m.group(1) else: m = re.match(r'- (.*) +// lines (.*)-', line) if m: - print '%s(%s) : warning I0002: Unnecessary forward ref of %s' % (removing, m.group(2), m.group(1)) + print '%s(%s) : warning I0002: '\ + 'Unnecessary forward ref of %s' %\ + (removing, m.group(2), m.group(1)) foundline = m.group(1) else: print '********* I got confused **********' if line.startswith('In file included from'): - line = re.sub(r'^(In file included from)(.*):(\d+):', r' \2(\3) : \1 here', line) - # Note This doesnt appear to work if you get a string of them, not sure why. + line = re.sub(r'^(In file included from)(.*):(\d+):', + r' \2(\3) : \1 here', + line) + # Note; QT Creator seems to be unwilling to let you double click the + # line to select the code in question if you get a string of these, not + # sure why. elif ': note:' in line: line = ' ' + re.sub(r':(\d+):\d+: note:', r'(\1) : note:', line) else: # Replace clang :line:column: type: with ms (line) : type nnnn: line = re.sub(r':(\d+):\d+: ([^:]*):', r'(\1) : \2 I1234:', line) - + if ' : error I1234:' in line: + errors = True print line if line.endswith(' should remove these lines:'): @@ -84,16 +97,20 @@ def process_next_line(line): # added lines should come after the first entry with a line number. -process = subprocess.Popen(sys.argv[1:], +outfile = open(sys.argv[1], 'w') +process = subprocess.Popen(sys.argv[2:], stdout = subprocess.PIPE, stderr = subprocess.STDOUT) while True: output = process.stdout.readline() if output == '' and process.poll() is not None: break if output: - process_next_line(output) + process_next_line(output, outfile) + rc = process.poll() # The return code you get appears to be more to do with the amount of output -# generated than any real error. We should error if any ': error:' lines are -# detected +# generated than any real error, so instead we should error if any ': error:' +# lines are detected +if errors: + sys.exit(1) diff --git a/src/shared/stackdata.cpp b/src/shared/stackdata.cpp index 18daaf7b..b336593a 100644 --- a/src/shared/stackdata.cpp +++ b/src/shared/stackdata.cpp @@ -99,7 +99,8 @@ void StackData::initTrace() { CONTEXT context; std::memset(&context, 0, sizeof(CONTEXT)); context.ContextFlags = CONTEXT_CONTROL; -#if BOOST_ARCH_X86_64 + //Why only for 64 bit? +#if BOOST_ARCH_X86_64 || defined(__clang__) ::RtlCaptureContext(&context); #else __asm -- cgit v1.3.1