[Bug sanitizer/93246] New: Unexpected program behavior when -fsanitize=address and -O2/O3 used

2020-01-13 Thread mtekieli+gcc at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93246

Bug ID: 93246
   Summary: Unexpected program behavior when -fsanitize=address
and -O2/O3 used
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: sanitizer
  Assignee: unassigned at gcc dot gnu.org
  Reporter: mtekieli+gcc at gmail dot com
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at 
gcc dot gnu.org
  Target Milestone: ---

#include 

/*
$ g++-9 -O2 -fsanitize=address main.cpp && ./a.out
x=0, y=0, z=1
$ g++-8 -O2 -fsanitize=address main.cpp && ./a.out
x=1, y=1, z=1
$ clang++-9 -O2 -fsanitize=address main.cpp && ./a.out
x=1, y=1, z=1
*/

template  struct Optional {
  auto is_present() const { return inner.present; }

  auto set_present() {
if (not is_present())
  inner.present = true;
  }

  struct InnerType {
bool present = false;
char padding[1] = {0};
  };

  using inner_t = InnerType;
  // InnerType inner = {}; // this works as expected!
  inner_t inner = {}; // this doesn't!
};

template  struct Wrapper {
  auto operator-> () { return value; }

  WrappedType *value;
};

int main() {
  Optional<> buf{};
  Wrapper> wo = {&buf};

  wo->set_present();

  auto x = wo->is_present();
  auto y = wo->is_present();
  std::cout << "x=" << x << ", y=" << y;
  auto z = wo->is_present();
  std::cout << ", z=" << z << "\n";
}

/*
Above code produces expected results when:
* -fsanitize=address is not used
* -O1 instead of -O2/O3 is used
* gcc8 is used
* InnerType instead of inner_t alias is used
*/

[Bug c++/100646] New: gcc -E -fdirectives-only causes "error: unterminated comment" when no new line at the end of file

2021-05-17 Thread mtekieli+gcc at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100646

Bug ID: 100646
   Summary: gcc -E -fdirectives-only causes "error: unterminated
comment" when no new line at the end of file
   Product: gcc
   Version: 11.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: mtekieli+gcc at gmail dot com
  Target Milestone: ---

$ cat test_gcc11.cpp 
int main()
{
}
// namespace

$ g++ -E -fdirectives-only test_gcc11.cpp -o test_gcc11.o
test_gcc11.cpp:4:1: error: unterminated comment
4 | // namespace
  | ^

Above error occurs when test_gcc11.cpp or anything included in test_gcc11.cpp
has a comment with no new line at the end of file.

It looks like this patch does not help:
https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=b6ecd493886891f8150905a2fd3b7d54e88fc7be

It worked fine with gcc 10.