Re: [cfe-users] [EXT] Final C++20 rules and -Wambiguous-reversed-operator

2020-03-25 Thread Romain GEISSLER via cfe-users


> Le 15 mars 2020 à 20:14, Richard Smith  a écrit :
> 
> No, we still don't have a resolution from the C++ committee, but it's being 
> discussed by various implementers, and we hope to present to the committee a 
> suggested set of changes to minimize the pain to users as soon as we can. I 
> expect we will change /something/ as a DR fix against C++20, but the exact 
> details are unclear.

Hi,

Thanks for the heads up.

I am not sure how valid is my request, but I found a case where I wished 
-Wambiguous-reversed-operator would avoid what today with clang 10 is a strong 
error.

Consider this code: the == comparison warning is avoidable with 
-Wambiguous-reversed-operator, but not the != comparison. This make existing 
C++17 code behavior non-symetric when migrating to pack C++20, and a bit 
awkward for users:

template  struct A
{
bool operator==(const T&) const;
bool operator!=(const T&) const;
};

struct B : public A {};

bool f()
{
bool a1 = B() == B(); // Works, only a -Wambiguous-reversed-operator warning
bool a2 = B() != B(); // Strong error, which you can't avoid with 
-Wno-ambiguous-reversed-operator flag
}

Do you think that in the meantime while we wait for the C++ committee to 
standardize a real DR clang 10 should be update to also just warns in such 
cases involving != ?

Cheers,
Romain
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] clang-9 (MacOS 10.13) linker crash and optimization issues

2020-03-25 Thread Artur Shepilko via cfe-users
Hello,
First post on this mailing list...to report a crash-bug in clang-9.0.0
(x86_64-apple-darwin17.0.0) on MacOS 10.13 (High Sierra). The clang-9
was installed from the pre-built binary on llvm.org (not XCode).

There're two related issues uncovered:

1) clang-9 ld64.lld crashed when trying to link a default compiled
sample .c file, which has some switch statement cases. Hello-world
kind of .c test file is linking and running ok. The same crashing link
is successful when using clang-8 ld64.lld instead.

2) Executable of the sample file (same as above) produced with clang-9
(or clang-8, or even clang-7) results in "Segmentation Fault: 11",
when built with default compiler flags (apart from MacOS SDK
includes). The code appears to build and run ok with -O1 or -O2 or -O3
flags (-O0 yields SEGV in run-time). However, when bulding any real
application beyond the sample still results in some SEGV when trying
to run the built binaries at point or the other.

It took me some painful debugging to figure out at least one remedy
which appears to clear both of the issues listed above. Adding
"-fno-jump-tables"  compiler/optimizer option seems to result in
correct run-time behavior (for all of the clang versions tested:
7,8,9). This seems applicable to all optimization levels -O0 to -O3.

I wonder if at least the "-fno-jump-tables" option should be made part
of defaults in MacOS build, or maybe add some line in docs to alert
anyone that faces these issues.

Below is the sample code that triggered the linker crash and SEGV in
runtime (in the pre-built clang versions 7 through 9).  The resulting
run-time SEGV output (without -fno-jump-tables option) is shown after
that. Finally, the clang-9 linker crash dump is shown at the very end.

I also attached these outputs, just in case it gets wrapped on the mail-list.

I hope this could get fixed or maybe there're some other details about
these issues that I don't know.
I also tried the bugpoint way, but it seems to be quite challenging to
figure out given a rather terse documentation on how to use it.
Instead I had to resort to eyeballing the resulting asm files to see
the difference in switch handling between -O0 (crashing) and -O1
(somewhat ok) codes.

Thanks.

[swsegv.c]

#include 
#include 

void test_sw ();

enum tag {
  tag1 = 0,
  tag2,
  tag3,
  tag4,
};

struct data {
  int c;
  enum tag t;
};

int main (int argc, char **argv, char **envp)
{
  test_sw();
  printf("DBG:%s|done\n",__FUNCTION__);
  exit(EXIT_SUCCESS);
}

static void dump_data(const struct data *d)
{
  printf("DBG:%s|data::{\n", __FUNCTION__);
  for ( ; d && d->c != '\0'; ++d) {
const char *t = "";

switch (d->t) {
case tag1:
t = "tag1";
break;
case tag2:
t = "tag2";
break;
case tag3:
t = "tag3";
break;
case tag4:
t = "tag4";
break;
default:
break;
}
printf("  {'%c',%s},\n",d->c, t);
  }
  printf("}::data\n");
}

void test_sw ()
{
  struct data data[] = {
{ '1', tag1 },
{ '2', tag2 },
{ '3', tag3 },
{ '4', tag4 },
{ 0, tag1 }
  };

  struct data *d;
  d = data;
  dump_data(d);

  return;
}


[swsegv.c: ./swsegv run-time output without -fno-jump-tables]

DBG:dump_data|data::{
DBG:dump_data|data::{
Segmentation fault: 11


[swsegv.c: clang-9 link crash dump when building without -fno-jump-tables]

$CC -x c -v $CFLAGS swsegv.c $LDFLAGS
clang version 9.0.0 (git://github.com/llvm/llvm-project.git
0399d5a9682b3cef71c653373e38890c63c4c365)
Target: x86_64-apple-darwin17.0.0
Thread model: posix
InstalledDir: /usr/local/opt/clang+llvm-9.0.0/bin
 "/usr/local/opt/clang+llvm-9.0.0/bin/clang-9" -cc1 -triple
x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage
-Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free
-disable-llvm-verifier -discard-value-names -main-file-name swsegv.c
-mrelocation-model pic -pic-level 2 -mthread-model posix
-mdisable-fp-elim -masm-verbose -munwind-tables
-faligned-alloc-unavailable -target-cpu penryn -dwarf-column-info
-debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb
-ggnu-pubnames -target-linker-version 512.4 -v -resource-dir
/usr/local/opt/clang+llvm-9.0.0/lib/clang/9.0.0 -I
/usr/local/opt/clang+llvm-9.0.0/include -I
/usr/local/opt/clang+llvm-9.0.0/include/c++/v1 -I
/usr/local/opt/SDKs/MacOSX10.13.sdk/usr/include -D
__STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS
-F/usr/local/opt/SDKs/MacOSX10.13.sdk/System/Library/Frameworks
-internal-isystem /usr/local/include -internal-isystem
/usr/local/opt/clang+llvm-9.0.0/lib/clang/9.0.0/include
-internal-externc-isystem /usr/include -Wall
-Wno-nullability-completeness -fdebug-compilation-dir
/Users/tester/wor