Bug 1672630 - Clang fails to build correctly with gcc-9
Summary: Clang fails to build correctly with gcc-9
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 31
Hardware: ppc64le
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-02-05 13:37 UTC by serge_sans_paille
Modified: 2020-11-24 16:41 UTC (History)
12 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2020-11-24 16:41:25 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
preprocessed file (2.36 MB, text/plain)
2019-02-06 07:56 UTC, serge_sans_paille
no flags Details

Description serge_sans_paille 2019-02-05 13:37:40 UTC
When building clang (7 or 8) with the newly shipped gcc-9 compiler, the build failed during validation (see for instance https://koji.fedoraproject.org/koji/taskinfo?taskID=32504081).

I've been reproducing the error on a ppc64le machine, installing gcc-9 from source through

$ svn export svn://gcc.gnu.org/svn/gcc/branches/redhat/gcc-9-branch@268371
$ cd gcc-9-branch/
$ mkdir _build && cd _build
$ ../configure --prefix=$HOME/gcc-install
$ make
$ make install

then compiling llvm with the generated gcc

$ export LD_LIBRARY_PATH=$HOME/gcc-install/lib:$HOME/gcc-install/lib64
$ git clone https://github.com/llvm/llvm-project.git
$ git checkout release/8.x
$ mkdir _build && cd _build
$ cmake ../llvm -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_C_COMPILER=$HOME/gcc-install/bin/gcc -DCMAKE_CXX_COMPILER=$HOME/gcc-install/bin/g++
$ make
$ make check-clang

Fails on a single test case, but not always (!)

Running valgrind on the faulty test brings me the following log:

$ valgrind --track-origins=yes /home/sergesanspaille/llvm-project/_build/bin/c-index-test -test-annotate-tokens=/home/sergesanspaille/llvm-project/clang/test/Index/annotate-deep-statements.cpp:1:1:1000:1 /home/sergesanspaille/llvm-project/clang/test/Index/annotate-deep-statements.cpp
[...]
=4645== Thread 3:
==4645== Conditional jump or move depends on uninitialised value(s)
==4645==    at 0x4B855F4: reset (unique_ptr.h:398)
==4645==    by 0x4B855F4: clang::DiagnosticsEngine::setClient(clang::DiagnosticConsumer*, bool) (Diagnostic.cpp:102)
==4645==    by 0x4BE9B1B: ~CaptureDroppedDiagnostics (ASTUnit.cpp:661)
==4645==    by 0x4BE9B1B: clang::ASTUnit::LoadFromCommandLine(char const**, char const**, std::shared_ptr<clang::PCHContainerOperations>, llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>, llvm::StringRef, bool, bool, llvm::ArrayRef<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, llvm::MemoryBuffer*> >, bool, unsigned int, clang::TranslationUnitKind, bool, bool, bool, clang::SkipFunctionBodiesScope, bool, bool, bool, llvm::Optional<llvm::StringRef>, std::unique_ptr<clang::ASTUnit, std::default_delete<clang::ASTUnit> >*, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) (ASTUnit.cpp:1722)
==4645==    by 0x47BDECB: clang_parseTranslationUnit_Impl(void*, char const*, char const* const*, int, llvm::ArrayRef<CXUnsavedFile>, unsigned int, CXTranslationUnitImpl**) (CIndex.cpp:3497)
==4645==    by 0x47BEA13: operator() (CIndex.cpp:3570)
==4645==    by 0x47BEA13: void llvm::function_ref<void ()>::callback_fn<clang_parseTranslationUnit2FullArgv::{lambda()#1}>(long) (STLExtras.h:126)
==4645==    by 0x6EFC5BF: operator() (STLExtras.h:143)
==4645==    by 0x6EFC5BF: llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (CrashRecoveryContext.cpp:359)
==4645==    by 0x6EFC69B: RunSafelyOnThread_Dispatch(void*) (CrashRecoveryContext.cpp:402)
==4645==    by 0x6F874B7: ExecuteOnThread_Dispatch(void*) (Threading.inc:53)
==4645==    by 0x40D8B93: start_thread (in /usr/lib64/libpthread-2.17.so)
==4645==    by 0xB7985F3: clone (in /usr/lib64/libc-2.17.so)
==4645==  Uninitialised value was created by a heap allocation
==4645==    at 0x40846F4: operator new(unsigned long) (vg_replace_malloc.c:334)
==4645==    by 0x4BF2907: clang::CompilerInstance::createDiagnostics(clang::DiagnosticOptions*, clang::DiagnosticConsumer*, bool, clang::CodeGenOptions const*) (CompilerInstance.cpp:282)
==4645==    by 0x47BD6FF: clang_parseTranslationUnit_Impl(void*, char const*, char const* const*, int, llvm::ArrayRef<CXUnsavedFile>, unsigned int, CXTranslationUnitImpl**) (CIndex.cpp:3409)
==4645==    by 0x47BEA13: operator() (CIndex.cpp:3570)
==4645==    by 0x47BEA13: void llvm::function_ref<void ()>::callback_fn<clang_parseTranslationUnit2FullArgv::{lambda()#1}>(long) (STLExtras.h:126)
==4645==    by 0x6EFC5BF: operator() (STLExtras.h:143)
==4645==    by 0x6EFC5BF: llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (CrashRecoveryContext.cpp:359)
==4645==    by 0x6EFC69B: RunSafelyOnThread_Dispatch(void*) (CrashRecoveryContext.cpp:402)
==4645==    by 0x6F874B7: ExecuteOnThread_Dispatch(void*) (Threading.inc:53)
==4645==    by 0x40D8B93: start_thread (in /usr/lib64/libpthread-2.17.so)
==4645==    by 0xB7985F3: clone (in /usr/lib64/libc-2.17.so)
==4645== 


Modifying clang/include/clang/Frontend/TextDiagnosticPrinter.h from

class TextDiagnosticPrinter : public DiagnosticConsumer {
  raw_ostream &OS;
  IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;

  /// Handle to the currently active text diagnostic emitter.
  std::unique_ptr<TextDiagnostic> TextDiag;

  /// A string to prefix to error messages.
  std::string Prefix;

  unsigned OwnsOutputStream : 1;
/*...*/


to

class TextDiagnosticPrinter : public DiagnosticConsumer {
  raw_ostream &OS;
  IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;

  /// Handle to the currently active text diagnostic emitter.
  std::unique_ptr<TextDiagnostic> TextDiag;

  /// A string to prefix to error messages.
  std::string Prefix;

  bool OwnsOutputStream;
/*...*/

removes the valgrind warning. Compiling with -O1 or -O0 also removes the warning. Would it be possible for gcc-9 to somehow miscompile bitfields?

Comment 1 serge_sans_paille 2019-02-05 14:24:28 UTC
NOTE: the bug does *not appear when compiling with -O0 -g -fsanitize=undefined

Comment 2 serge_sans_paille 2019-02-06 07:56:04 UTC
Created attachment 1527438 [details]
preprocessed file

Comment 3 serge_sans_paille 2019-02-06 07:59:33 UTC
So the valgrind warnings triggers when the whole code base is compiled with -O2. The attached preprocessed file contains a push/pop options pragma combined with GCC optimize("-O0") on a single function. When compiled with -O0, the warning disappears, when compiled with -O2 (and even -O1) the warning pops up in valgrind.

Hope it helps...

Original command line was 

 /home/sergesanspaille/gcc-install/bin/g++  -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/lib/Basic -I/home/sergesanspaille/llvm-project/clang/lib/Basic -I/home/sergesanspaille/llvm-project/clang/include -Itools/clang/include -Iinclude -I/home/sergesanspaille/llvm-project/llvm/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -fno-common -Woverloaded-virtual -fno-strict-aliasing -g -O2 -fPIC    -fno-exceptions -fno-rtti -MD -MT tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/Diagnostic.cpp.o -MF tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/Diagnostic.cpp.o.d -o tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/Diagnostic.cpp.o -c /home/sergesanspaille/llvm-project/clang/lib/Basic/Diagnostic.cpp

Comment 4 Jakub Jelinek 2019-02-06 16:43:00 UTC
This has been determined to be a valgrind bug, small testcase:
__attribute__((noipa)) void foo (void **q, void *p, bool x)
{
  *q = x ? p : 0;
}

__attribute__((noipa)) int bar (void) { return 0; }

int
main ()
{
  void *q;
  void *z = __builtin_malloc (64);
  if (z == 0)
    return 0;
  register void *p __asm ("r9");
  /* Technically load of uninitialized data, but the data is ignored.  */
  asm volatile ("" : "=r" (p) : "0" (*(void **) z));
  foo (&q, z, true);
  int ret = 1;
  if (q != 0)
    ret = bar ();
  __builtin_free (z);
  return ret;
}
(assumes for foo it emits subfe 9,9,9 instruction, otherwise needs tweaks in main).
subfe reg1,reg1,reg{1,2} instruction, similarly to x86 sbb reg1,reg1 instruction or various others doesn't really depend on the previous content of reg1, always produces 0 or -1 depending on the carry flag.
So, if carry is not uninitialized, the result is well defined, even if all or some of reg1 bits are uninitialized.

Now, if clang test fails somewhere else, we need either something without valgrind, or wait until valgrind is fixed.

Comment 5 Ben Cotton 2019-08-13 17:06:29 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to '31'.

Comment 6 Ben Cotton 2019-08-13 19:13:11 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to 31.

Comment 7 Ben Cotton 2020-11-03 15:09:03 UTC
This message is a reminder that Fedora 31 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 31 on 2020-11-24.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
Fedora 'version' of '31'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 31 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 8 Ben Cotton 2020-11-24 16:41:25 UTC
Fedora 31 changed to end-of-life (EOL) status on 2020-11-24. Fedora 31 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.


Note You need to log in before you can comment on or make changes to this bug.