[PATCH] D142947: [hexagon] add a -mcabac flag

2023-01-31 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz accepted this revision.
kparzysz added a comment.
This revision is now accepted and ready to land.

The cxx tests passed for me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142947/new/

https://reviews.llvm.org/D142947

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140757: [Hexagon][VE][WebAssembly] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros

2023-01-02 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz accepted this revision.
kparzysz added a comment.
This revision is now accepted and ready to land.

All of Hexagon's atomics are implemented using load-locked/store-conditional.  
If that meets the expectations of these macros, then this is fine with me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140757/new/

https://reviews.llvm.org/D140757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131172: [clang][llvm][doc] Add more information for the ABI change in FP16

2022-08-04 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz accepted this revision.
kparzysz added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131172/new/

https://reviews.llvm.org/D131172

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125177: Recognize scope of thread local variables in CFGBuilder

2022-05-09 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd9e6b5df74f5: [clang] Recognize scope of thread local 
variables in CFGBuilder (authored by kparzysz).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125177/new/

https://reviews.llvm.org/D125177

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/cfg.cpp


Index: clang/test/Analysis/cfg.cpp
===
--- clang/test/Analysis/cfg.cpp
+++ clang/test/Analysis/cfg.cpp
@@ -593,6 +593,63 @@
   A(), B();
 }
 
+// CHECK-LABEL: int crash_with_thread_local(char *p, int *q)
+// CHECK:   [B7 (ENTRY)]
+// CHECK-NEXT:Succs (1): B6
+// CHECK:   [B1]
+// CHECK-NEXT:   bail:
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: return [B1.1];
+// CHECK-NEXT:Preds (2): B2 B5
+// CHECK-NEXT:Succs (1): B0
+// CHECK:   [B2]
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: q
+// CHECK-NEXT:3: [B2.2] (ImplicitCastExpr, LValueToRValue, int *)
+// CHECK-NEXT:4: *[B2.3]
+// CHECK-NEXT:5: [B2.4] = [B2.1]
+// CHECK-NEXT:Preds (2): B3 B4
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B3]
+// WARNINGS-NEXT: 1:  (CXXConstructExpr, struct ClassWithDtor)
+// ANALYZER-NEXT: 1:  (CXXConstructExpr, [B3.2], struct ClassWithDtor)
+// CHECK-NEXT:2: thread_local ClassWithDtor a;
+// CHECK-NEXT:Preds (1): B4
+// CHECK-NEXT:Succs (1): B2
+// CHECK:   [B4]
+// CHECK-NEXT:T: static init a
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (2): B2 B3
+// CHECK:   [B5]
+// CHECK-NEXT:T: goto bail;
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B6]
+// CHECK-NEXT:1: p
+// CHECK-NEXT:2: [B6.1] (ImplicitCastExpr, LValueToRValue, char *)
+// CHECK-NEXT:3: 0
+// CHECK-NEXT:4: [B6.3] (ImplicitCastExpr, NullToPointer, char *)
+// CHECK-NEXT:5: [B6.2] != [B6.4]
+// CHECK-NEXT:T: if [B6.5]
+// CHECK-NEXT:Preds (1): B7
+// CHECK-NEXT:Succs (2): B5 B4
+// CHECK:   [B0 (EXIT)]
+// CHECK-NEXT:Preds (1): B1
+
+struct ClassWithDtor {
+  ~ClassWithDtor() {}
+};
+
+int crash_with_thread_local(char *p, int *q) {
+  if (p != 0) {
+goto bail;
+  }
+  thread_local ClassWithDtor a;
+  *q = 0;
+bail:
+  return 0;
+}
+
 // CHECK-LABEL: template<> int *PR18472()
 // CHECK: [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -2019,13 +2019,8 @@
 return Scope;
 
   // Check if variable is local.
-  switch (VD->getStorageClass()) {
-  case SC_None:
-  case SC_Auto:
-  case SC_Register:
-break;
-  default: return Scope;
-  }
+  if (!VD->hasLocalStorage())
+return Scope;
 
   if (BuildOpts.AddImplicitDtors) {
 if (!hasTrivialDestructor(VD) || BuildOpts.AddScopes) {


Index: clang/test/Analysis/cfg.cpp
===
--- clang/test/Analysis/cfg.cpp
+++ clang/test/Analysis/cfg.cpp
@@ -593,6 +593,63 @@
   A(), B();
 }
 
+// CHECK-LABEL: int crash_with_thread_local(char *p, int *q)
+// CHECK:   [B7 (ENTRY)]
+// CHECK-NEXT:Succs (1): B6
+// CHECK:   [B1]
+// CHECK-NEXT:   bail:
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: return [B1.1];
+// CHECK-NEXT:Preds (2): B2 B5
+// CHECK-NEXT:Succs (1): B0
+// CHECK:   [B2]
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: q
+// CHECK-NEXT:3: [B2.2] (ImplicitCastExpr, LValueToRValue, int *)
+// CHECK-NEXT:4: *[B2.3]
+// CHECK-NEXT:5: [B2.4] = [B2.1]
+// CHECK-NEXT:Preds (2): B3 B4
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B3]
+// WARNINGS-NEXT: 1:  (CXXConstructExpr, struct ClassWithDtor)
+// ANALYZER-NEXT: 1:  (CXXConstructExpr, [B3.2], struct ClassWithDtor)
+// CHECK-NEXT:2: thread_local ClassWithDtor a;
+// CHECK-NEXT:Preds (1): B4
+// CHECK-NEXT:Succs (1): B2
+// CHECK:   [B4]
+// CHECK-NEXT:T: static init a
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (2): B2 B3
+// CHECK:   [B5]
+// CHECK-NEXT:T: goto bail;
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B6]
+// CHECK-NEXT:1: p
+// CHECK-NEXT:2: [B6.1] (ImplicitCastExpr, LValueToRValue, char *)
+// CHECK-NEXT:3: 0
+// CHECK-NEXT:4: [B6.3] (ImplicitCastExpr, NullToPointer, char *)
+// CHECK-NEXT:5: [B6.2] != [B6.4]
+// CHECK-NEXT:T: if [B6.5]
+// CHECK-NEXT:Preds (1): B7
+// CHECK-NEXT:Succs (2): B5 B4
+// CHECK:   [B0 (EXIT)]
+// CHECK-NEXT:Preds (1): B1
+
+struct ClassWithDtor {
+  ~ClassWithDtor() {}
+};
+
+int crash_with_thread_local(char *p, int *q) {
+  if (p != 0) {
+goto bail;
+  }
+  thread_local ClassWithDtor a;
+  *q = 0;
+bail:
+  return 0;
+}
+
 // CHECK-LABEL: template<> int *PR18472()

[PATCH] D125177: Recognize scope of thread local variables in CFGBuilder

2022-05-08 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz updated this revision to Diff 427939.
kparzysz added a comment.

Use the proper diff file this time.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125177/new/

https://reviews.llvm.org/D125177

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/cfg.cpp


Index: clang/test/Analysis/cfg.cpp
===
--- clang/test/Analysis/cfg.cpp
+++ clang/test/Analysis/cfg.cpp
@@ -593,6 +593,63 @@
   A(), B();
 }
 
+// CHECK-LABEL: int crash_with_thread_local(char *p, int *q)
+// CHECK:   [B7 (ENTRY)]
+// CHECK-NEXT:Succs (1): B6
+// CHECK:   [B1]
+// CHECK-NEXT:   bail:
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: return [B1.1];
+// CHECK-NEXT:Preds (2): B2 B5
+// CHECK-NEXT:Succs (1): B0
+// CHECK:   [B2]
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: q
+// CHECK-NEXT:3: [B2.2] (ImplicitCastExpr, LValueToRValue, int *)
+// CHECK-NEXT:4: *[B2.3]
+// CHECK-NEXT:5: [B2.4] = [B2.1]
+// CHECK-NEXT:Preds (2): B3 B4
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B3]
+// WARNINGS-NEXT: 1:  (CXXConstructExpr, struct ClassWithDtor)
+// ANALYZER-NEXT: 1:  (CXXConstructExpr, [B3.2], struct ClassWithDtor)
+// CHECK-NEXT:2: thread_local ClassWithDtor a;
+// CHECK-NEXT:Preds (1): B4
+// CHECK-NEXT:Succs (1): B2
+// CHECK:   [B4]
+// CHECK-NEXT:T: static init a
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (2): B2 B3
+// CHECK:   [B5]
+// CHECK-NEXT:T: goto bail;
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B6]
+// CHECK-NEXT:1: p
+// CHECK-NEXT:2: [B6.1] (ImplicitCastExpr, LValueToRValue, char *)
+// CHECK-NEXT:3: 0
+// CHECK-NEXT:4: [B6.3] (ImplicitCastExpr, NullToPointer, char *)
+// CHECK-NEXT:5: [B6.2] != [B6.4]
+// CHECK-NEXT:T: if [B6.5]
+// CHECK-NEXT:Preds (1): B7
+// CHECK-NEXT:Succs (2): B5 B4
+// CHECK:   [B0 (EXIT)]
+// CHECK-NEXT:Preds (1): B1
+
+struct ClassWithDtor {
+  ~ClassWithDtor() {}
+};
+
+int crash_with_thread_local(char *p, int *q) {
+  if (p != 0) {
+goto bail;
+  }
+  thread_local ClassWithDtor a;
+  *q = 0;
+bail:
+  return 0;
+}
+
 // CHECK-LABEL: template<> int *PR18472()
 // CHECK: [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -2019,13 +2019,8 @@
 return Scope;
 
   // Check if variable is local.
-  switch (VD->getStorageClass()) {
-  case SC_None:
-  case SC_Auto:
-  case SC_Register:
-break;
-  default: return Scope;
-  }
+  if (!VD->hasLocalStorage())
+return Scope;
 
   if (BuildOpts.AddImplicitDtors) {
 if (!hasTrivialDestructor(VD) || BuildOpts.AddScopes) {


Index: clang/test/Analysis/cfg.cpp
===
--- clang/test/Analysis/cfg.cpp
+++ clang/test/Analysis/cfg.cpp
@@ -593,6 +593,63 @@
   A(), B();
 }
 
+// CHECK-LABEL: int crash_with_thread_local(char *p, int *q)
+// CHECK:   [B7 (ENTRY)]
+// CHECK-NEXT:Succs (1): B6
+// CHECK:   [B1]
+// CHECK-NEXT:   bail:
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: return [B1.1];
+// CHECK-NEXT:Preds (2): B2 B5
+// CHECK-NEXT:Succs (1): B0
+// CHECK:   [B2]
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: q
+// CHECK-NEXT:3: [B2.2] (ImplicitCastExpr, LValueToRValue, int *)
+// CHECK-NEXT:4: *[B2.3]
+// CHECK-NEXT:5: [B2.4] = [B2.1]
+// CHECK-NEXT:Preds (2): B3 B4
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B3]
+// WARNINGS-NEXT: 1:  (CXXConstructExpr, struct ClassWithDtor)
+// ANALYZER-NEXT: 1:  (CXXConstructExpr, [B3.2], struct ClassWithDtor)
+// CHECK-NEXT:2: thread_local ClassWithDtor a;
+// CHECK-NEXT:Preds (1): B4
+// CHECK-NEXT:Succs (1): B2
+// CHECK:   [B4]
+// CHECK-NEXT:T: static init a
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (2): B2 B3
+// CHECK:   [B5]
+// CHECK-NEXT:T: goto bail;
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B6]
+// CHECK-NEXT:1: p
+// CHECK-NEXT:2: [B6.1] (ImplicitCastExpr, LValueToRValue, char *)
+// CHECK-NEXT:3: 0
+// CHECK-NEXT:4: [B6.3] (ImplicitCastExpr, NullToPointer, char *)
+// CHECK-NEXT:5: [B6.2] != [B6.4]
+// CHECK-NEXT:T: if [B6.5]
+// CHECK-NEXT:Preds (1): B7
+// CHECK-NEXT:Succs (2): B5 B4
+// CHECK:   [B0 (EXIT)]
+// CHECK-NEXT:Preds (1): B1
+
+struct ClassWithDtor {
+  ~ClassWithDtor() {}
+};
+
+int crash_with_thread_local(char *p, int *q) {
+  if (p != 0) {
+goto bail;
+  }
+  thread_local ClassWithDtor a;
+  *q = 0;
+bail:
+  return 0;
+}
+
 // CHECK-LABEL: template<> int *PR18472()
 // CHECK: [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
Index: clang/lib/Analysis/CFG.cpp

[PATCH] D125177: Recognize scope of thread local variables in CFGBuilder

2022-05-08 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz updated this revision to Diff 427938.
kparzysz added a comment.

Replace the direct storage class examination with `hasLocalStorage`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125177/new/

https://reviews.llvm.org/D125177

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/cfg.cpp


Index: clang/test/Analysis/cfg.cpp
===
--- clang/test/Analysis/cfg.cpp
+++ clang/test/Analysis/cfg.cpp
@@ -593,6 +593,63 @@
   A(), B();
 }
 
+// CHECK-LABEL: int crash_with_thread_local(char *p, int *q)
+// CHECK:   [B7 (ENTRY)]
+// CHECK-NEXT:Succs (1): B6
+// CHECK:   [B1]
+// CHECK-NEXT:   bail:
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: return [B1.1];
+// CHECK-NEXT:Preds (2): B2 B5
+// CHECK-NEXT:Succs (1): B0
+// CHECK:   [B2]
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: q
+// CHECK-NEXT:3: [B2.2] (ImplicitCastExpr, LValueToRValue, int *)
+// CHECK-NEXT:4: *[B2.3]
+// CHECK-NEXT:5: [B2.4] = [B2.1]
+// CHECK-NEXT:Preds (2): B3 B4
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B3]
+// WARNINGS-NEXT: 1:  (CXXConstructExpr, struct ClassWithDtor)
+// ANALYZER-NEXT: 1:  (CXXConstructExpr, [B3.2], struct ClassWithDtor)
+// CHECK-NEXT:2: thread_local ClassWithDtor a;
+// CHECK-NEXT:Preds (1): B4
+// CHECK-NEXT:Succs (1): B2
+// CHECK:   [B4]
+// CHECK-NEXT:T: static init a
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (2): B2 B3
+// CHECK:   [B5]
+// CHECK-NEXT:T: goto bail;
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B6]
+// CHECK-NEXT:1: p
+// CHECK-NEXT:2: [B6.1] (ImplicitCastExpr, LValueToRValue, char *)
+// CHECK-NEXT:3: 0
+// CHECK-NEXT:4: [B6.3] (ImplicitCastExpr, NullToPointer, char *)
+// CHECK-NEXT:5: [B6.2] != [B6.4]
+// CHECK-NEXT:T: if [B6.5]
+// CHECK-NEXT:Preds (1): B7
+// CHECK-NEXT:Succs (2): B5 B4
+// CHECK:   [B0 (EXIT)]
+// CHECK-NEXT:Preds (1): B1
+
+struct ClassWithDtor {
+  ~ClassWithDtor() {}
+};
+
+int crash_with_thread_local(char *p, int *q) {
+  if (p != 0) {
+goto bail;
+  }
+  thread_local ClassWithDtor a;
+  *q = 0;
+bail:
+  return 0;
+}
+
 // CHECK-LABEL: template<> int *PR18472()
 // CHECK: [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -2021,6 +2021,11 @@
   // Check if variable is local.
   switch (VD->getStorageClass()) {
   case SC_None:
+if (VD->getTSCSpec() == ThreadStorageClassSpecifier::TSCS_thread_local) {
+  // TSCS_thread_local implies "static" for block scope variables.
+  return Scope;
+}
+break;
   case SC_Auto:
   case SC_Register:
 break;


Index: clang/test/Analysis/cfg.cpp
===
--- clang/test/Analysis/cfg.cpp
+++ clang/test/Analysis/cfg.cpp
@@ -593,6 +593,63 @@
   A(), B();
 }
 
+// CHECK-LABEL: int crash_with_thread_local(char *p, int *q)
+// CHECK:   [B7 (ENTRY)]
+// CHECK-NEXT:Succs (1): B6
+// CHECK:   [B1]
+// CHECK-NEXT:   bail:
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: return [B1.1];
+// CHECK-NEXT:Preds (2): B2 B5
+// CHECK-NEXT:Succs (1): B0
+// CHECK:   [B2]
+// CHECK-NEXT:1: 0
+// CHECK-NEXT:2: q
+// CHECK-NEXT:3: [B2.2] (ImplicitCastExpr, LValueToRValue, int *)
+// CHECK-NEXT:4: *[B2.3]
+// CHECK-NEXT:5: [B2.4] = [B2.1]
+// CHECK-NEXT:Preds (2): B3 B4
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B3]
+// WARNINGS-NEXT: 1:  (CXXConstructExpr, struct ClassWithDtor)
+// ANALYZER-NEXT: 1:  (CXXConstructExpr, [B3.2], struct ClassWithDtor)
+// CHECK-NEXT:2: thread_local ClassWithDtor a;
+// CHECK-NEXT:Preds (1): B4
+// CHECK-NEXT:Succs (1): B2
+// CHECK:   [B4]
+// CHECK-NEXT:T: static init a
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (2): B2 B3
+// CHECK:   [B5]
+// CHECK-NEXT:T: goto bail;
+// CHECK-NEXT:Preds (1): B6
+// CHECK-NEXT:Succs (1): B1
+// CHECK:   [B6]
+// CHECK-NEXT:1: p
+// CHECK-NEXT:2: [B6.1] (ImplicitCastExpr, LValueToRValue, char *)
+// CHECK-NEXT:3: 0
+// CHECK-NEXT:4: [B6.3] (ImplicitCastExpr, NullToPointer, char *)
+// CHECK-NEXT:5: [B6.2] != [B6.4]
+// CHECK-NEXT:T: if [B6.5]
+// CHECK-NEXT:Preds (1): B7
+// CHECK-NEXT:Succs (2): B5 B4
+// CHECK:   [B0 (EXIT)]
+// CHECK-NEXT:Preds (1): B1
+
+struct ClassWithDtor {
+  ~ClassWithDtor() {}
+};
+
+int crash_with_thread_local(char *p, int *q) {
+  if (p != 0) {
+goto bail;
+  }
+  thread_local ClassWithDtor a;
+  *q = 0;
+bail:
+  return 0;
+}
+
 // CHECK-LABEL: template<> int *PR18472()
 // CHECK: [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
Index: clang/lib/Analysis/CFG.cpp

[PATCH] D125177: Recognize scope of thread local variables in CFGBuilder

2022-05-07 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz created this revision.
kparzysz added a reviewer: rsmith.
Herald added subscribers: pengfei, krytarowski, arichardson, emaste.
Herald added a project: All.
kparzysz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Compiling the following testcase causes a crash:

  struct A {
~A() {}
  };
  
  int fred(char *p, int *q) {
if (p != 0) {
  goto bail;
}
thread_local A a;
*q = 0;
  bail:
return 0;
  }

The crash is caused by CFGBuilder thinking that the variable `a` is local (in 
terms of storage scope), and trying to perform some sort of a lifetime analysis 
on it.  The problem is that the program would not have been legal if `a` was 
actually local, and the problem would have been diagnosed earlier, preventing 
CFGBuilder from running in the first place.

This fix recognizes locally declared C++11 `thread_local` variables as `static`.

  Assertion failed: (F != const_iterator() && "L iterator is not reachable from 
F iterator."), function distance, file 
/w/src/llvm.org/clang/lib/Analysis/CFG.cpp, line 334.
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.  Program arguments: /w/c/org/bin/clang++ -c dd.cc
  1.   parser at end of file
  2.  dd.cc:5:27: parsing function body 'fred'
   #0 0x0561c8aa llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/w/c/org/bin/clang+++0x561c8aa)
   #1 0x0561a788 llvm::sys::RunSignalHandlers() 
(/w/c/org/bin/clang+++0x561a788)
   #2 0x0557edd4 (anonymous 
namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) 
CrashRecoveryContext.cpp:0:0
   #3 0x0557efa0 CrashRecoverySignalHandler(int) 
CrashRecoveryContext.cpp:0:0
   #4 0x0008091f35b0 handle_signal /usr/src/lib/libthr/thread/thr_sig.c:0:3
   #5 0x0008091f2b6f thr_sighandler 
/usr/src/lib/libthr/thread/thr_sig.c:247:1
   #6 0x72d3 ([vdso]+0x2d3)
   #7 0x00080950f14a thr_kill 
/usr/obj/usr/src/amd64.amd64/lib/libc/thr_kill.S:4:0
   #8 0x000809487c34 _raise /usr/src/lib/libc/gen/raise.c:0:10
   #9 0x000809538e99 abort /usr/src/lib/libc/stdlib/abort.c:73:17
  #10 0x00080946a9d1 (/lib/libc.so.7+0x929d1)
  #11 0x07f2fa66 (anonymous 
namespace)::CFGBuilder::addAutomaticObjHandling((anonymous 
namespace)::LocalScope::const_iterator, (anonymous 
namespace)::LocalScope::const_iterator, clang::Stmt*) CFG.cpp:0:0
  #12 0x07f2adc7 (anonymous 
namespace)::CFGBuilder::VisitGotoStmt(clang::GotoStmt*) CFG.cpp:0:0
  #13 0x07f2866f (anonymous 
namespace)::CFGBuilder::VisitCompoundStmt(clang::CompoundStmt*, bool) 
CFG.cpp:0:0
  #14 0x07f2b612 (anonymous 
namespace)::CFGBuilder::VisitIfStmt(clang::IfStmt*) CFG.cpp:0:0
  #15 0x07f2866f (anonymous 
namespace)::CFGBuilder::VisitCompoundStmt(clang::CompoundStmt*, bool) 
CFG.cpp:0:0
  #16 0x07f211e4 clang::CFG::buildCFG(clang::Decl const*, clang::Stmt*, 
clang::ASTContext*, clang::CFG::BuildOptions const&) 
(/w/c/org/bin/clang+++0x7f211e4)
  #17 0x07ef12ab clang::AnalysisDeclContext::getCFG() 
(/w/c/org/bin/clang+++0x7ef12ab)
  #18 0x076bb654 
clang::sema::AnalysisBasedWarnings::IssueWarnings(clang::sema::AnalysisBasedWarnings::Policy,
 clang::sema::FunctionScopeInfo*, clang::Decl const*, clang::QualType) 
(/w/c/org/bin/clang+++0x76bb654)
  #19 0x076b05f7 
clang::Sema::PopFunctionScopeInfo(clang::sema::AnalysisBasedWarnings::Policy 
const*, clang::Decl const*, clang::QualType) (/w/c/org/bin/clang+++0x76b05f7)
  #20 0x07817aa2 clang::Sema::ActOnFinishFunctionBody(clang::Decl*, 
clang::Stmt*, bool) (/w/c/org/bin/clang+++0x7817aa2)
  #21 0x075bb3f3 
clang::Parser::ParseFunctionStatementBody(clang::Decl*, 
clang::Parser::ParseScope&) (/w/c/org/bin/clang+++0x75bb3f3)
  #22 0x07590e34 
clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, 
clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) 
(/w/c/org/bin/clang+++0x7590e34)
  #23 0x07615d7d clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, 
clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) 
(/w/c/org/bin/clang+++0x7615d7d)
  #24 0x0758f681 
clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, 
clang::ParsingDeclSpec&, clang::AccessSpecifier) 
(/w/c/org/bin/clang+++0x758f681)
  #25 0x0758f0a2 
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, 
clang::ParsingDeclSpec*, clang::AccessSpecifier) 
(/w/c/org/bin/clang+++0x758f0a2)
  #26 0x0758de8b 
clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, 
clang::ParsingDeclSpec*) (/w/c/org/bin/clang+++0x758de8b)
  #27 0x0758bdcd 
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, 
clang::Sema::ModuleImportState&) 

[PATCH] D113638: [xray] Add support for hexagon architecture

2021-12-08 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz accepted this revision.
kparzysz added a comment.
This revision is now accepted and ready to land.

LGTM.  Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113638/new/

https://reviews.llvm.org/D113638

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111529: Specify Clang vector builtins.

2021-10-13 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:553
+Each builtin returns a scalar equivalent to applying the specified
+operation(x, y) as horizontal recursive pairwise reduction to all vector
+elements. In each reduction step, ``operation(x, y)`` is applied to adjacent

It's really not clear what "horizontal recursive pairwise" means unless one has 
read the mailing list discussions.  Maybe you could spell it out, e.g. 
"recursive even-odd pairwise reduction" or something like that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111529/new/

https://reviews.llvm.org/D111529

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75638: [Hexagon] Support for Linux/Musl ABI.

2020-03-25 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

I'm not sure if it's worth defining these macros especially if this is the only 
place where they are used.  We'd need a more coordinated effort to replace all 
32's with named constants where it refers to a register size, and I'm not even 
sure if we could classify whether a given 32 is tied to a register size or not.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75638/new/

https://reviews.llvm.org/D75638



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70919: [Hexagon] Avoid passing unsupported options to lld when -fuse-ld=lld is used

2019-12-16 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added inline comments.



Comment at: clang/test/Driver/hexagon-toolchain-elf.c:560
+// CHECK082-NOT:  "-march=hexagon"
+// CHECK082-NOT:  "-mcpu=hexagon"

kparzysz wrote:
> I don't think there will ever be `"-mcpu=hexagon"` (including the quotation 
> marks). Maybe this should just check for any `-march` and `-mcpu`.
This is still wrong.  Assume that we are passing `-mcpu=hexagonv60` to lld. The 
options will show up with quotation marks, and so it will be 
`"-mcpu=hexagonv60"`.  The testcase is checking for `"-mcpu"` which will not 
match `"-mcpu=hexagonv60"`, and the testcase will pass even though it shouldn't.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70919/new/

https://reviews.llvm.org/D70919



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70919: [Hexagon] Avoid passing unsupported options to lld when -fuse-ld=lld is used

2019-12-02 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added inline comments.



Comment at: clang/test/Driver/hexagon-toolchain-elf.c:560
+// CHECK082-NOT:  "-march=hexagon"
+// CHECK082-NOT:  "-mcpu=hexagon"

I don't think there will ever be `"-mcpu=hexagon"` (including the quotation 
marks). Maybe this should just check for any `-march` and `-mcpu`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70919/new/

https://reviews.llvm.org/D70919



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62127: [Hexagon] driver uses out-of-date option name and binary name

2019-06-28 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364648: [Hexagon] driver uses out-of-date option name and 
binary name (authored by kparzysz, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62127?vs=200221=207067#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62127/new/

https://reviews.llvm.org/D62127

Files:
  cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp


Index: cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
@@ -130,11 +130,11 @@
   const Driver  = HTC.getDriver();
   ArgStringList CmdArgs;
 
-  CmdArgs.push_back("-march=hexagon");
+  CmdArgs.push_back("--arch=hexagon");
 
   RenderExtraToolArgs(JA, CmdArgs);
 
-  const char *AsName = "hexagon-llvm-mc";
+  const char *AsName = "llvm-mc";
   CmdArgs.push_back("-filetype=obj");
   CmdArgs.push_back(Args.MakeArgString(
   "-mcpu=hexagon" +


Index: cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
@@ -130,11 +130,11 @@
   const Driver  = HTC.getDriver();
   ArgStringList CmdArgs;
 
-  CmdArgs.push_back("-march=hexagon");
+  CmdArgs.push_back("--arch=hexagon");
 
   RenderExtraToolArgs(JA, CmdArgs);
 
-  const char *AsName = "hexagon-llvm-mc";
+  const char *AsName = "llvm-mc";
   CmdArgs.push_back("-filetype=obj");
   CmdArgs.push_back(Args.MakeArgString(
   "-mcpu=hexagon" +
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59168: [runtimes] Move libunwind, libc++abi and libc++ to lib/$target/c++ and include/c++

2019-05-29 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

This commit stopped clang++ from finding libc++:

main.cc:

  #include 
  
  int main() {
std::vector x;
return x.size();
  }



  $ clang++ main.cc -stdlib=libc++ -v
  clang version 9.0.0 (/w/src/llvm.org/tools/clang 
754813c4737a444eeb4ea5b4070073dd251504cc) (/w/src/llvm.org 
e145e44a7c34acf851da0d6a2c66b274b6ebc82d)
  Target: x86_64-unknown-linux-gnu
  Thread model: posix
  InstalledDir: /w/c/org/bin
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.4
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.3
  Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
  Candidate multilib: .;@m64
  Candidate multilib: 32;@m32
  Candidate multilib: x32;@mx32
  Selected multilib: .;@m64
   "/w/c/org/bin/clang-9" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj 
-mrelax-all -disable-free -main-file-name main.cc -mrelocation-model static 
-mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose 
-mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 
-dwarf-column-info -debugger-tuning=gdb -v -resource-dir 
/w/c/org/lib/clang/9.0.0 -internal-isystem /usr/local/include -internal-isystem 
/w/c/org/lib/clang/9.0.0/include -internal-externc-isystem 
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include 
-internal-externc-isystem /usr/include -fdeprecated-macro 
-fdebug-compilation-dir /w/test -ferror-limit 19 -fmessage-length 0 
-fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option 
-fcolor-diagnostics -faddrsig -o /tmp/main-32e7f3.o -x c++ main.cc
  clang -cc1 version 9.0.0 based upon LLVM 9.0.0svn default target 
x86_64-unknown-linux-gnu
  ignoring nonexistent directory "/include"
  #include "..." search starts here:
  #include <...> search starts here:
   /usr/local/include
   /w/c/org/lib/clang/9.0.0/include
   /usr/include/x86_64-linux-gnu
   /usr/include
  End of search list.
  main.cc:1:10: fatal error: 'vector' file not found
  #include 
   ^~~~
  1 error generated.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59168/new/

https://reviews.llvm.org/D59168



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52840: Include Python binding tests in CMake rules

2018-10-16 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

Hexagon clang builder has been failing since around the time of this commit as 
well:
http://lab.llvm.org:8011/builders/clang-hexagon-elf/builds/20617/steps/ninja%20check%201/logs/stdio


Repository:
  rC Clang

https://reviews.llvm.org/D52840



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48571: improve diagnostics for missing 'template' keyword

2018-06-26 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

Please take over, I commandeered to restore the patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D48571



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48571: improve diagnostics for missing 'template' keyword

2018-06-26 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz updated this revision to Diff 152946.
kparzysz added a comment.

Restored the original patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D48571

Files:
  include/clang/Basic/BitmaskEnum.h
  include/clang/Parse/Parser.h
  include/clang/Parse/RAIIObjectsForParser.h
  include/clang/Sema/Sema.h
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/Parse/ParseCXXInlineMethods.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseStmt.cpp
  lib/Sema/SemaTemplate.cpp
  test/SemaTemplate/dependent-template-recover.cpp

Index: test/SemaTemplate/dependent-template-recover.cpp
===
--- test/SemaTemplate/dependent-template-recover.cpp
+++ test/SemaTemplate/dependent-template-recover.cpp
@@ -5,18 +5,59 @@
 t->f0(); // expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}}
 t->f0(); // expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}}
 
-t->operator+(); // expected-error{{use 'template' keyword to treat 'operator +' as a dependent template name}}
-t->f1(); // expected-error{{use 'template' keyword to treat 'f1' as a dependent template name}}
+t->operator+(1); // expected-error{{use 'template' keyword to treat 'operator +' as a dependent template name}}
+t->f1(1); // expected-error{{use 'template' keyword to treat 'f1' as a dependent template name}}
+t->f1<3, int const>(1); // expected-error{{missing 'template' keyword prior to dependent template name 'f1'}}
 
 T::getAs(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
 t->T::getAs(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
 
-// FIXME: We can't recover from these yet
-(*t).f2(); // expected-error{{expected expression}}
-(*t).f2<0>(); // expected-error{{expected expression}}
+(*t).f2(); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
+(*t).f2<0>(); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
+T::f2<0>(); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
+T::f2<0, int>(0); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
+
+T::foo= 4>(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
+
+// If there are multiple potential template names, pick the one where there
+// is no whitespace between the name and the '<'.
+T::foo(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
+T::foo < T::bar<1>(); // expected-error{{missing 'template' keyword prior to dependent template name 'bar'}}
+
+// Prefer to diagonse a missing 'template' keyword rather than finding a non-template name.
+xyz < T::foo < 1 > (); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
+T::foo < xyz < 1 > (); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
+
+// ... even if the whitespace suggests the other name is the template name.
+// FIXME: Is this the right heuristic?
+xyz(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
+T::foo < xyz<1>(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
   }
+
+  int xyz;
 };
 
+template  void not_missing_template(T t) {
+  (T::n < 0) > (
+ ) // expected-error {{expected expression}}
+;
+
+  int a = T::x < 3;
+  int b = T::y > (); // expected-error {{expected expression}}
+
+  void c(int = T::x < 3);
+  void d(int = T::y > ()); // expected-error {{expected expression}}
+
+  for (int x = t < 3 ? 1 : 2; t > (); ++t) { // expected-error {{expected expression}}
+  }
+
+  // FIXME: We shouldn't treat 'T::t' as a potential template-name here,
+  // because that would leave a '?' with no matching ':'.
+  // We should probably generally treat '?' ... ':' as a bracket-like
+  // construct.
+  bool k = T::t < 3 ? 1 > () : false; // expected-error {{missing 'template' keyword}} expected-error +{{}} expected-note +{{}}
+}
+
 struct MrsBadcrumble {
   friend MrsBadcrumble operator<(void (*)(int), MrsBadcrumble);
   friend void operator>(MrsBadcrumble, int);
@@ -30,6 +71,9 @@
   // Note: no diagnostic here, this is actually valid as a comparison between
   // the decayed pointer to Y::g<> and mb!
   T::g(0);
+
+  // ... but this one must be a template-id.
+  T::g(0); // expected-error {{missing 'template' keyword prior to dependent template name 'g'}}
 }
 
 struct Y {
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -508,20 +508,41 @@
 
   DeclContext *LookupCtx = nullptr;
   NamedDecl *Found = nullptr;
+  bool 

[PATCH] D48571: improve diagnostics for missing 'template' keyword

2018-06-26 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz reopened this revision.
kparzysz added a comment.

This needs to be restored to the original form.  A mistake in a commit message 
closed this review by accident.


Repository:
  rL LLVM

https://reviews.llvm.org/D48571



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38548: Hexagon] Move getHexagonTargetFeatures to Hexagon.cpp (NFC)

2017-10-04 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz accepted this revision.
kparzysz added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D38548



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36712: Emit section information for extern variables

2017-08-16 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

The problem is that the mismatch between sections does not have to lead to any 
undesirable behavior.  Whether it does or not depends on a particular case.  I 
think we should be consistent though---if we decide that a mismatch between the 
section for a declaration and the section for a definition leads to an 
undefined behavior, then it should be so regardless of whether the sections 
were given explicitly or inferred.


https://reviews.llvm.org/D36712



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36712: Emit section information for extern variables

2017-08-16 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

In https://reviews.llvm.org/D36712#843387, @eandrews wrote:

> Does this result in unexpected behavior though? Won't this just result in the 
> global being defined in the specified section?


If there is no section given explicitly, there is function 
SelectSectionForGlobal that will determine the section based on the properties 
of the global.  If there is code that only sees the declaration, but needs to 
know the section, it will get it from that function.  If the definition of that 
global doesn't have section either, that same function will be used, hopefully 
with the same result.  On the other hand, if the definition of the global has 
an explicit section, it may differ from the one calculated for the declarations 
of that global.  This could lead to a problem.


https://reviews.llvm.org/D36712



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36712: Emit section information for extern variables

2017-08-15 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

In https://reviews.llvm.org/D36712#842433, @efriedma wrote:

> I can't see how "undefined behavior" could possibly be the right answer in 
> that case.  Every definition has to end up in some section eventually, and in 
> many cases we don't know what section that will be when a global is declared. 
>  (For example, we put constants into different sections depending on the 
> contents of the initializer.)


These constants don't have explicit section information in the IR.  The typical 
scenario is that neither the declarations of a global, nor its definition have 
that.  In the cases when the section is explicitly given on a definition, it 
was likely imposed by something like the "section" attribute in the source.  I 
don't think it's unreasonable to expect that the declarations (in the original 
source as well as in the generated IR) should carry that information as well.  
However, since clang has apparently been ignoring that attribute on 
declarations, it's been generating IR where declarations may not have sections, 
but the corresponding definitions do.


https://reviews.llvm.org/D36712



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36712: Emit section information for extern variables

2017-08-15 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added inline comments.



Comment at: docs/LangRef.rst:629
+corresponding to the LLVM module, section information specified in the 
+declaration is retained in LLVM IR to enable OpenCL processes.
+

sdardis wrote:
> efriedma wrote:
> > This doesn't really explain the part that matters. For LangRef, it doesn't 
> > matter how the frontend decides to generate declarations (and it might be 
> > different for frontends other than clang).  And OpenCL might motivate this, 
> > but it has nothing to do with the semantics.
> > 
> > The key question here is what it actually means.  Is it a promise the that 
> > a definition will exist for the given symbol in the given section?  If so, 
> > what happens if the symbol is actually in a different section?  ("Undefined 
> > behavior" is probably an acceptable answer, but it needs to be stated 
> > explicitly.)
> > to enable OpenCL processes.
> 
> for targets which make use of this section information. 
> 
> I would also work in a sentence that says that attaching section information 
> to a external declaration is an assertion or promise that the definition is 
> located in that section. If the definition is actually located in a different 
> section the behaviour is undefined.
> 
> I'm favouring "undefined behaviour" in the error case as behaviour is so 
> target and environment specific.
The other side of the problem is, what if the declarations don't have any 
section information, but the definition does? Is that also an undefined 
behavior? I'm in favor of considering it UB as well, but I'm not sure what 
impact it would have on currently valid IR.


https://reviews.llvm.org/D36712



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35577: Add -flookup-tables and -fno-lookup-tables flags

2017-07-24 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

In https://reviews.llvm.org/D35577#817944, @echristo wrote:

> "Should this just be part of the tuning for the hexagon backend and not 
> options at all"


The ultimate decision as to what kind of code to generate out of a switch 
statement belongs to the customer.  The reasons to choose one way over another 
may involve factors that the compiler has no knowledge of (such as details of 
the target hardware).  I don't think we need separate options to control jump 
tables and lookup tables: one option to enable/disable the use of memory tables 
would be sufficient.


https://reviews.llvm.org/D35577



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35578: Add -fswitch-tables and -fno-switch-tables flags

2017-07-19 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

In https://reviews.llvm.org/D35578#814919, @mcrosier wrote:

> It sounds like to me you have some cases when you do want lookup tables and 
> other cases that you don't.  What exactly is the determining factor here?


The determining factor is whether the customers want it or not.  Each case has 
its own specifics, which we do not want to hardcode into the compiler.  At one 
point, the customers have reported to us that memory loads coming from switch 
expansion is an undesirable outcome.  We want to provide them with an option to 
prevent that from happening.


https://reviews.llvm.org/D35578



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33499: [PPC] PPC32/Darwin ABI info

2017-06-22 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

Great! Thanks.


Repository:
  rL LLVM

https://reviews.llvm.org/D33499



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33499: [PPC] PPC32/Darwin ABI info

2017-06-09 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

Ping.  The bug reporter has verified that this patch fixes the problem.


Repository:
  rL LLVM

https://reviews.llvm.org/D33499



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33499: [PPC] PPC32/Darwin ABI info

2017-05-30 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz updated this revision to Diff 100720.
kparzysz retitled this revision from "[PPC] First approximation of PPC32/Darwin 
ABI info" to "[PPC] PPC32/Darwin ABI info".
kparzysz edited the summary of this revision.
kparzysz added a comment.

This patch corrects the ABI alignment issues for arguments of size greater than 
4: all types except vector and aggregates will be aligned at 4-byte boundary in 
the parameter area. Vectors and aggregates will follow their natural alignment.


Repository:
  rL LLVM

https://reviews.llvm.org/D33499

Files:
  lib/CodeGen/TargetInfo.cpp

Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -4181,6 +4181,87 @@
   return false;
 }
 
+namespace {
+/// PPC32_Darwin_ABIInfo - The 32-bit PowerPC Darwin ABI information.
+class PPC32_Darwin_ABIInfo : public DefaultABIInfo {
+public:
+  PPC32_Darwin_ABIInfo(CodeGen::CodeGenTypes ) : DefaultABIInfo(CGT) {}
+
+  Address EmitVAArg(CodeGenFunction , Address VAListAddr,
+QualType Ty) const override;
+};
+
+class PPC32DarwinTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  PPC32DarwinTargetCodeGenInfo(CodeGenTypes )
+  : TargetCodeGenInfo(new PPC32_Darwin_ABIInfo(CGT)) {}
+
+  int getDwarfEHStackPointer(CodeGen::CodeGenModule ) const override {
+// This is recovered from gcc output.
+return 1; // r1 is the dedicated stack pointer
+  }
+
+  bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction ,
+   llvm::Value *Address) const override;
+};
+}
+
+Address PPC32_Darwin_ABIInfo::EmitVAArg(CodeGenFunction ,
+Address VAListAddr,
+QualType Ty) const {
+  // Cap the alignment of function arguments to the natural stack alignment
+  // for all types, except vectors and aggregates.
+  std::pair Info = getContext().getTypeInfoInChars(Ty);
+  CharUnits Slot = CharUnits::fromQuantity(4);
+  if (!Ty->isVectorType() && !isAggregateTypeForABI(Ty))
+Info.second = std::min(Info.second, Slot);
+
+  return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*Indirect=*/ false,
+  Info, Slot, /*AllowHigherAlign=*/ true);
+}
+
+// Copied from PP32TargetCodeGenInfo.
+bool
+PPC32DarwinTargetCodeGenInfo::initDwarfEHRegSizeTable(
+  CodeGen::CodeGenFunction , llvm::Value *Address) const {
+  // This is calculated from the LLVM and GCC tables and verified
+  // against gcc output.  AFAIK all ABIs use the same encoding.
+
+  CodeGen::CGBuilderTy  = CGF.Builder;
+
+  llvm::IntegerType *i8 = CGF.Int8Ty;
+  llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4);
+  llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8);
+  llvm::Value *Sixteen8 = llvm::ConstantInt::get(i8, 16);
+
+  // 0-31: r0-31, the 4-byte general-purpose registers
+  AssignToArrayRange(Builder, Address, Four8, 0, 31);
+
+  // 32-63: fp0-31, the 8-byte floating-point registers
+  AssignToArrayRange(Builder, Address, Eight8, 32, 63);
+
+  // 64-76 are various 4-byte special-purpose registers:
+  // 64: mq
+  // 65: lr
+  // 66: ctr
+  // 67: ap
+  // 68-75 cr0-7
+  // 76: xer
+  AssignToArrayRange(Builder, Address, Four8, 64, 76);
+
+  // 77-108: v0-31, the 16-byte vector registers
+  AssignToArrayRange(Builder, Address, Sixteen8, 77, 108);
+
+  // 109: vrsave
+  // 110: vscr
+  // 111: spe_acc
+  // 112: spefscr
+  // 113: sfp
+  AssignToArrayRange(Builder, Address, Four8, 109, 113);
+
+  return false;
+}
+
 // PowerPC-64
 
 namespace {
@@ -8488,6 +8569,8 @@
   }
 
   case llvm::Triple::ppc:
+if (Triple.isOSDarwin())
+  return SetCGInfo(new PPC32DarwinTargetCodeGenInfo(Types));
 return SetCGInfo(
 new PPC32TargetCodeGenInfo(Types, CodeGenOpts.FloatABI == "soft"));
   case llvm::Triple::ppc64:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33328: [CodeGen] Pessimize aliasing for union members (and may-alias) objects

2017-05-25 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303851: [CodeGen] Pessimize aliasing for member unions (and 
may-alias) objects (authored by kparzysz).

Changed prior to commit:
  https://reviews.llvm.org/D33328?vs=100142=100232#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33328

Files:
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/test/CodeGen/union-tbaa1.c
  cfe/trunk/test/CodeGenCXX/union-tbaa2.cpp

Index: cfe/trunk/test/CodeGenCXX/union-tbaa2.cpp
===
--- cfe/trunk/test/CodeGenCXX/union-tbaa2.cpp
+++ cfe/trunk/test/CodeGenCXX/union-tbaa2.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -O2 -std=c++11 -triple x86_64-unknown-linux-gnu -target-cpu x86-64 -target-feature +sse4.2 -target-feature +avx -emit-llvm -o - | FileCheck %s
+
+// Testcase from llvm.org/PR32056
+
+extern "C" int printf (const char *__restrict __format, ...);
+
+typedef double __m256d __attribute__((__vector_size__(32)));
+
+static __inline __m256d __attribute__((__always_inline__, __nodebug__,
+   __target__("avx")))
+_mm256_setr_pd(double __a, double __b, double __c, double __d) {
+  return (__m256d){ __a, __b, __c, __d };
+}
+
+struct A {
+  A () {
+// Check that the TBAA information generated for the stores to the
+// union members is based on the omnipotent char.
+// CHECK: store <4 x double>
+// CHECK: tbaa ![[OCPATH:[0-9]+]]
+// CHECK: store <4 x double>
+// CHECK: tbaa ![[OCPATH]]
+// CHECK: call
+a = _mm256_setr_pd(0.0, 1.0, 2.0, 3.0);
+b = _mm256_setr_pd(4.0, 5.0, 6.0, 7.0);
+  }
+
+  const double *begin() { return c; }
+  const double *end() { return c+8; }
+
+  union {
+struct { __m256d a, b; };
+double c[8];
+  };
+};
+
+int main(int argc, char *argv[]) {
+  A a;
+  for (double value : a)
+printf("%f ", value);
+  return 0;
+}
+
+// CHECK-DAG: ![[CHAR:[0-9]+]] = !{!"omnipotent char"
+// CHECK-DAG: ![[OCPATH]] = !{![[CHAR]], ![[CHAR]], i64 0}
Index: cfe/trunk/test/CodeGen/union-tbaa1.c
===
--- cfe/trunk/test/CodeGen/union-tbaa1.c
+++ cfe/trunk/test/CodeGen/union-tbaa1.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 %s -triple hexagon-unknown-elf -O2 -emit-llvm -o - | FileCheck %s
+
+typedef union __attribute__((aligned(4))) {
+  unsigned short uh[2];
+  unsigned uw;
+} vect32;
+
+void bar(vect32 p[][2]);
+
+// CHECK-LABEL: define void @fred
+void fred(unsigned Num, int Vec[2], int *Index, int Arr[4][2]) {
+  vect32 Tmp[4][2];
+// Generate tbaa for the load of Index:
+// CHECK: load i32, i32* %Index{{.*}}tbaa
+// But no tbaa for the two stores:
+// CHECK: %uw[[UW1:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW1]]
+// CHECK: tbaa ![[OCPATH:[0-9]+]]
+// There will be a load after the store, and it will use tbaa. Make sure
+// the check-not above doesn't find it:
+// CHECK: load
+  Tmp[*Index][0].uw = Arr[*Index][0] * Num;
+// CHECK: %uw[[UW2:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW2]]
+// CHECK: tbaa ![[OCPATH]]
+  Tmp[*Index][1].uw = Arr[*Index][1] * Num;
+// Same here, don't generate tbaa for the loads:
+// CHECK: %uh[[UH1:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX1:[0-9]*]] = getelementptr{{.*}}%uh[[UH1]]
+// CHECK: load i16, i16* %arrayidx[[AX1]]
+// CHECK: tbaa ![[OCPATH]]
+// CHECK: store
+  Vec[0] = Tmp[*Index][0].uh[1];
+// CHECK: %uh[[UH2:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX2:[0-9]*]] = getelementptr{{.*}}%uh[[UH2]]
+// CHECK: load i16, i16* %arrayidx[[AX2]]
+// CHECK: tbaa ![[OCPATH]]
+// CHECK: store
+  Vec[1] = Tmp[*Index][1].uh[1];
+  bar(Tmp);
+}
+
+// CHECK-DAG: ![[CHAR:[0-9]+]] = !{!"omnipotent char"
+// CHECK-DAG: ![[OCPATH]] = !{![[CHAR]], ![[CHAR]], i64 0}
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -1432,11 +1432,12 @@
 Load->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
   if (TBAAInfo) {
-llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
-  TBAAOffset);
-if (TBAAPath)
-  CGM.DecorateInstructionWithTBAA(Load, TBAAPath,
-  false /*ConvertTypeToTag*/);
+bool MayAlias = BaseInfo.getMayAlias();
+llvm::MDNode *TBAA = MayAlias
+? CGM.getTBAAInfo(getContext().CharTy)
+: CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo, TBAAOffset);
+if (TBAA)
+  CGM.DecorateInstructionWithTBAA(Load, TBAA, MayAlias);
   }
 
   if (EmitScalarRangeCheck(Load, Ty, Loc)) {
@@ -1522,11 +1523,12 @@
 Store->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
   if (TBAAInfo) {
-llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
-  TBAAOffset);
-   

[PATCH] D33328: [CodeGen] Pessimize aliasing for union members (and may-alias) objects

2017-05-24 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz updated this revision to Diff 100142.
kparzysz added a comment.

Pass char TBAA directly to DecorateInstructionWithTBAA and pass true for 
ConvertTypeToTag in such cases.


Repository:
  rL LLVM

https://reviews.llvm.org/D33328

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGen/union-tbaa1.c
  test/CodeGenCXX/union-tbaa2.cpp

Index: test/CodeGenCXX/union-tbaa2.cpp
===
--- /dev/null
+++ test/CodeGenCXX/union-tbaa2.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -O2 -std=c++11 -triple x86_64-unknown-linux-gnu -target-cpu x86-64 -target-feature +sse4.2 -target-feature +avx -emit-llvm -o - | FileCheck %s
+
+// Testcase from llvm.org/PR32056
+
+extern "C" int printf (const char *__restrict __format, ...);
+
+typedef double __m256d __attribute__((__vector_size__(32)));
+
+static __inline __m256d __attribute__((__always_inline__, __nodebug__,
+   __target__("avx")))
+_mm256_setr_pd(double __a, double __b, double __c, double __d) {
+  return (__m256d){ __a, __b, __c, __d };
+}
+
+struct A {
+  A () {
+// Check that the TBAA information generated for the stores to the
+// union members is based on the omnipotent char.
+// CHECK: store <4 x double>
+// CHECK: tbaa ![[OCPATH:[0-9]+]]
+// CHECK: store <4 x double>
+// CHECK: tbaa ![[OCPATH]]
+// CHECK: call
+a = _mm256_setr_pd(0.0, 1.0, 2.0, 3.0);
+b = _mm256_setr_pd(4.0, 5.0, 6.0, 7.0);
+  }
+
+  const double *begin() { return c; }
+  const double *end() { return c+8; }
+
+  union {
+struct { __m256d a, b; };
+double c[8];
+  };
+};
+
+int main(int argc, char *argv[]) {
+  A a;
+  for (double value : a)
+printf("%f ", value);
+  return 0;
+}
+
+// CHECK-DAG: ![[CHAR:[0-9]+]] = !{!"omnipotent char"
+// CHECK-DAG: ![[OCPATH]] = !{![[CHAR]], ![[CHAR]], i64 0}
Index: test/CodeGen/union-tbaa1.c
===
--- /dev/null
+++ test/CodeGen/union-tbaa1.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 %s -triple hexagon-unknown-elf -O2 -emit-llvm -o - | FileCheck %s
+
+typedef union __attribute__((aligned(4))) {
+  unsigned short uh[2];
+  unsigned uw;
+} vect32;
+
+void bar(vect32 p[][2]);
+
+// CHECK-LABEL: define void @fred
+void fred(unsigned Num, int Vec[2], int *Index, int Arr[4][2]) {
+  vect32 Tmp[4][2];
+// Generate tbaa for the load of Index:
+// CHECK: load i32, i32* %Index{{.*}}tbaa
+// But no tbaa for the two stores:
+// CHECK: %uw[[UW1:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW1]]
+// CHECK: tbaa ![[OCPATH:[0-9]+]]
+// There will be a load after the store, and it will use tbaa. Make sure
+// the check-not above doesn't find it:
+// CHECK: load
+  Tmp[*Index][0].uw = Arr[*Index][0] * Num;
+// CHECK: %uw[[UW2:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW2]]
+// CHECK: tbaa ![[OCPATH]]
+  Tmp[*Index][1].uw = Arr[*Index][1] * Num;
+// Same here, don't generate tbaa for the loads:
+// CHECK: %uh[[UH1:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX1:[0-9]*]] = getelementptr{{.*}}%uh[[UH1]]
+// CHECK: load i16, i16* %arrayidx[[AX1]]
+// CHECK: tbaa ![[OCPATH]]
+// CHECK: store
+  Vec[0] = Tmp[*Index][0].uh[1];
+// CHECK: %uh[[UH2:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX2:[0-9]*]] = getelementptr{{.*}}%uh[[UH2]]
+// CHECK: load i16, i16* %arrayidx[[AX2]]
+// CHECK: tbaa ![[OCPATH]]
+// CHECK: store
+  Vec[1] = Tmp[*Index][1].uh[1];
+  bar(Tmp);
+}
+
+// CHECK-DAG: ![[CHAR:[0-9]+]] = !{!"omnipotent char"
+// CHECK-DAG: ![[OCPATH]] = !{![[CHAR]], ![[CHAR]], i64 0}
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1432,11 +1432,12 @@
 Load->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
   if (TBAAInfo) {
-llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
-  TBAAOffset);
-if (TBAAPath)
-  CGM.DecorateInstructionWithTBAA(Load, TBAAPath,
-  false /*ConvertTypeToTag*/);
+bool MayAlias = BaseInfo.getMayAlias();
+llvm::MDNode *TBAA = MayAlias
+? CGM.getTBAAInfo(getContext().CharTy)
+: CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo, TBAAOffset);
+if (TBAA)
+  CGM.DecorateInstructionWithTBAA(Load, TBAA, MayAlias);
   }
 
   if (EmitScalarRangeCheck(Load, Ty, Loc)) {
@@ -1522,11 +1523,12 @@
 Store->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
   if (TBAAInfo) {
-llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
-  TBAAOffset);
-if (TBAAPath)
-  CGM.DecorateInstructionWithTBAA(Store, TBAAPath,
-  false /*ConvertTypeToTag*/);
+bool MayAlias = BaseInfo.getMayAlias();
+llvm::MDNode *TBAA = MayAlias
+? 

[PATCH] D33284: [CodeGen] Propagate LValueBaseInfo instead of AlignmentSource

2017-05-19 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz marked an inline comment as done.
kparzysz added inline comments.



Comment at: cfe/trunk/lib/CodeGen/CodeGenFunction.h:3756
   ///
   /// \param Source - If non-null, this will be initialized with
   ///   information about the source of the alignment.  Note that this

chapuni wrote:
> Could you update this? See also r303414. [-Wdocumentation]
Done in r303419.


Repository:
  rL LLVM

https://reviews.llvm.org/D33284



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33328: [CodeGen] Pessimize aliasing for union members (and may-alias) objects

2017-05-18 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz updated this revision to Diff 99467.
kparzysz edited subscribers, added: cfe-commits; removed: llvm-commits.
kparzysz added a comment.

The diff is the same as before, the change is in the subscribers: from 
llvm-commits to cfe-commits.


Repository:
  rL LLVM

https://reviews.llvm.org/D33328

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGen/union-tbaa1.c


Index: test/CodeGen/union-tbaa1.c
===
--- /dev/null
+++ test/CodeGen/union-tbaa1.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 %s -triple hexagon-unknown-elf -O2 -emit-llvm -o - | 
FileCheck %s
+
+typedef union __attribute__((aligned(4))) {
+  unsigned short uh[2];
+  unsigned uw;
+} vect32;
+
+void bar(vect32 p[][2]);
+
+// CHECK-LABEL: define void @fred
+void fred(unsigned Num, int Vec[2], int *Index, int Arr[4][2]) {
+  vect32 Tmp[4][2];
+// Generate tbaa for the load of Index:
+// CHECK: load i32, i32* %Index{{.*}}tbaa
+// But no tbaa for the two stores:
+// CHECK: %uw[[UW1:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW1]]
+// CHECK: tbaa ![[OCPATH:[0-9]+]]
+// There will be a load after the store, and it will use tbaa. Make sure
+// the check-not above doesn't find it:
+// CHECK: load
+  Tmp[*Index][0].uw = Arr[*Index][0] * Num;
+// CHECK: %uw[[UW2:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW2]]
+// CHECK: tbaa ![[OCPATH]]
+  Tmp[*Index][1].uw = Arr[*Index][1] * Num;
+// Same here, don't generate tbaa for the loads:
+// CHECK: %uh[[UH1:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX1:[0-9]*]] = getelementptr{{.*}}%uh[[UH1]]
+// CHECK: load i16, i16* %arrayidx[[AX1]]
+// CHECK: tbaa ![[OCPATH]]
+// CHECK: store
+  Vec[0] = Tmp[*Index][0].uh[1];
+// CHECK: %uh[[UH2:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX2:[0-9]*]] = getelementptr{{.*}}%uh[[UH2]]
+// CHECK: load i16, i16* %arrayidx[[AX2]]
+// CHECK: tbaa ![[OCPATH]]
+// CHECK: store
+  Vec[1] = Tmp[*Index][1].uh[1];
+  bar(Tmp);
+}
+
+// CHECK: ![[CHAR:[0-9]+]] = !{!"omnipotent char"
+// CHECK: ![[OCPATH]] = !{![[CHAR]]
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1432,6 +1432,8 @@
 Load->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
   if (TBAAInfo) {
+if (BaseInfo.getMayAlias())
+  TBAAInfo = CGM.getTBAAInfo(getContext().CharTy);
 llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
   TBAAOffset);
 if (TBAAPath)
@@ -1522,6 +1524,8 @@
 Store->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
   }
   if (TBAAInfo) {
+if (BaseInfo.getMayAlias())
+  TBAAInfo = CGM.getTBAAInfo(getContext().CharTy);
 llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
   TBAAOffset);
 if (TBAAPath)
@@ -3535,6 +3539,11 @@
 getFieldAlignmentSource(BaseInfo.getAlignmentSource());
   LValueBaseInfo FieldBaseInfo(fieldAlignSource, BaseInfo.getMayAlias());
 
+  const RecordDecl *rec = field->getParent();
+  bool mayAlias = rec->isUnion() || rec->hasAttr();
+  if (mayAlias)
+FieldBaseInfo.setMayAlias(true);
+
   if (field->isBitField()) {
 const CGRecordLayout  =
   CGM.getTypes().getCGRecordLayout(field->getParent());
@@ -3556,11 +3565,7 @@
 return LValue::MakeBitfield(Addr, Info, fieldType, FieldBaseInfo);
   }
 
-  const RecordDecl *rec = field->getParent();
   QualType type = field->getType();
-
-  bool mayAlias = rec->hasAttr();
-
   Address addr = base.getAddress();
   unsigned cvr = base.getVRQualifiers();
   bool TBAAPath = CGM.getCodeGenOpts().StructPathTBAA;


Index: test/CodeGen/union-tbaa1.c
===
--- /dev/null
+++ test/CodeGen/union-tbaa1.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 %s -triple hexagon-unknown-elf -O2 -emit-llvm -o - | FileCheck %s
+
+typedef union __attribute__((aligned(4))) {
+  unsigned short uh[2];
+  unsigned uw;
+} vect32;
+
+void bar(vect32 p[][2]);
+
+// CHECK-LABEL: define void @fred
+void fred(unsigned Num, int Vec[2], int *Index, int Arr[4][2]) {
+  vect32 Tmp[4][2];
+// Generate tbaa for the load of Index:
+// CHECK: load i32, i32* %Index{{.*}}tbaa
+// But no tbaa for the two stores:
+// CHECK: %uw[[UW1:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW1]]
+// CHECK: tbaa ![[OCPATH:[0-9]+]]
+// There will be a load after the store, and it will use tbaa. Make sure
+// the check-not above doesn't find it:
+// CHECK: load
+  Tmp[*Index][0].uw = Arr[*Index][0] * Num;
+// CHECK: %uw[[UW2:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW2]]
+// CHECK: tbaa ![[OCPATH]]
+  Tmp[*Index][1].uw = Arr[*Index][1] * Num;
+// Same here, don't generate tbaa for the loads:
+// CHECK: %uh[[UH1:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX1:[0-9]*]] = 

[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-05-18 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz abandoned this revision.
kparzysz added a comment.

This review is replaced by https://reviews.llvm.org/D33328.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33284: [CodeGen] Propagate LValueBaseInfo instead of AlignmentSource

2017-05-18 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303358: [CodeGen] Propagate LValueBaseInfo instead of 
AlignmentSource (authored by kparzysz).

Changed prior to commit:
  https://reviews.llvm.org/D33284?vs=99353=99457#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33284

Files:
  cfe/trunk/lib/CodeGen/CGAtomic.cpp
  cfe/trunk/lib/CodeGen/CGBlocks.cpp
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/CodeGen/CGClass.cpp
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGExprCXX.cpp
  cfe/trunk/lib/CodeGen/CGObjC.cpp
  cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
  cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
  cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
  cfe/trunk/lib/CodeGen/CGValue.h
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h

Index: cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
===
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
@@ -138,7 +138,8 @@
   Addr = CGF.Builder.CreateElementBitCast(Addr,
llvm::Type::getIntNTy(CGF.getLLVMContext(),
  Info->StorageSize));
-  return LValue::MakeBitfield(Addr, *Info, IvarTy, AlignmentSource::Decl);
+  return LValue::MakeBitfield(Addr, *Info, IvarTy,
+  LValueBaseInfo(AlignmentSource::Decl, false));
 }
 
 namespace {
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -374,12 +374,14 @@
   // dynamic initialization or a cleanup and we can just return the address
   // of the temporary.
   if (Var->hasInitializer())
-return MakeAddrLValue(Object, M->getType(), AlignmentSource::Decl);
+return MakeAddrLValue(Object, M->getType(),
+  LValueBaseInfo(AlignmentSource::Decl, false));
 
   Var->setInitializer(CGM.EmitNullConstant(E->getType()));
 }
 LValue RefTempDst = MakeAddrLValue(Object, M->getType(),
-   AlignmentSource::Decl);
+   LValueBaseInfo(AlignmentSource::Decl,
+  false));
 
 switch (getEvaluationKind(E->getType())) {
 default: llvm_unreachable("expected scalar or aggregate expression");
@@ -465,7 +467,7 @@
 
 case SubobjectAdjustment::FieldAdjustment: {
   LValue LV = MakeAddrLValue(Object, E->getType(),
- AlignmentSource::Decl);
+ LValueBaseInfo(AlignmentSource::Decl, false));
   LV = EmitLValueForField(LV, Adjustment.Field);
   assert(LV.isSimple() &&
  "materialized temporary field is not a simple lvalue");
@@ -482,7 +484,8 @@
 }
   }
 
-  return MakeAddrLValue(Object, M->getType(), AlignmentSource::Decl);
+  return MakeAddrLValue(Object, M->getType(),
+LValueBaseInfo(AlignmentSource::Decl, false));
 }
 
 RValue
@@ -847,7 +850,7 @@
 /// EmitPointerWithAlignment - Given an expression of pointer type, try to
 /// derive a more accurate bound on the alignment of the pointer.
 Address CodeGenFunction::EmitPointerWithAlignment(const Expr *E,
-  AlignmentSource  *Source) {
+  LValueBaseInfo *BaseInfo) {
   // We allow this with ObjC object pointers because of fragile ABIs.
   assert(E->getType()->isPointerType() ||
  E->getType()->isObjCObjectPointerType());
@@ -866,16 +869,20 @@
 if (PtrTy->getPointeeType()->isVoidType())
   break;
 
-AlignmentSource InnerSource;
-Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), );
-if (Source) *Source = InnerSource;
+LValueBaseInfo InnerInfo;
+Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), );
+if (BaseInfo) *BaseInfo = InnerInfo;
 
 // If this is an explicit bitcast, and the source l-value is
 // opaque, honor the alignment of the casted-to type.
 if (isa(CE) &&
-InnerSource != AlignmentSource::Decl) {
-  Addr = Address(Addr.getPointer(),
- getNaturalPointeeTypeAlignment(E->getType(), Source));
+InnerInfo.getAlignmentSource() != AlignmentSource::Decl) {
+  LValueBaseInfo ExpInfo;
+  CharUnits Align = getNaturalPointeeTypeAlignment(E->getType(),
+   );
+  if (BaseInfo)
+BaseInfo->mergeForCast(ExpInfo);
+  Addr = Address(Addr.getPointer(), Align);
 }
 
 if (SanOpts.has(SanitizerKind::CFIUnrelatedCast) &&
@@ -893,12 +900,12 @@
 
 // Array-to-pointer decay.
 case CK_ArrayToPointerDecay:
-  

[PATCH] D33284: [CodeGen] Propagate LValueBaseInfo instead of AlignmentSource

2017-05-18 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

If you have no further comments, could you accept this review?


Repository:
  rL LLVM

https://reviews.llvm.org/D33284



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33284: [CodeGen] Propagate LValueBaseInfo instead of AlignmentSource

2017-05-17 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz updated this revision to Diff 99353.
kparzysz marked 2 inline comments as done.
kparzysz added a comment.

Changed the getNatural.*TypeAlignment to produce the entire LValueBaseInfo, 
assuming MayAlias to be false.

Added merging of LValueBaseInfos.  The merging assumes that the alignment 
source in the parameter overrides the existing source.  That works for the 
existing cases (cast), but I'm not sure if that's correct in general.  Is there 
is an implicit ordering of alignment sources?


Repository:
  rL LLVM

https://reviews.llvm.org/D33284

Files:
  lib/CodeGen/CGAtomic.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CGObjCRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CGValue.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h

Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1886,31 +1886,33 @@
   //======//
 
   LValue MakeAddrLValue(Address Addr, QualType T,
-AlignmentSource AlignSource = AlignmentSource::Type) {
-return LValue::MakeAddr(Addr, T, getContext(), AlignSource,
+LValueBaseInfo BaseInfo =
+LValueBaseInfo(AlignmentSource::Type)) {
+return LValue::MakeAddr(Addr, T, getContext(), BaseInfo,
 CGM.getTBAAInfo(T));
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
-AlignmentSource AlignSource = AlignmentSource::Type) {
+LValueBaseInfo BaseInfo =
+LValueBaseInfo(AlignmentSource::Type)) {
 return LValue::MakeAddr(Address(V, Alignment), T, getContext(),
-AlignSource, CGM.getTBAAInfo(T));
+BaseInfo, CGM.getTBAAInfo(T));
   }
 
   LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T);
   LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T);
   CharUnits getNaturalTypeAlignment(QualType T,
-AlignmentSource *Source = nullptr,
+LValueBaseInfo *BaseInfo = nullptr,
 bool forPointeeType = false);
   CharUnits getNaturalPointeeTypeAlignment(QualType T,
-   AlignmentSource *Source = nullptr);
+   LValueBaseInfo *BaseInfo = nullptr);
 
   Address EmitLoadOfReference(Address Ref, const ReferenceType *RefTy,
-  AlignmentSource *Source = nullptr);
+  LValueBaseInfo *BaseInfo = nullptr);
   LValue EmitLoadOfReferenceLValue(Address Ref, const ReferenceType *RefTy);
 
   Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy,
-AlignmentSource *Source = nullptr);
+LValueBaseInfo *BaseInfo = nullptr);
   LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy);
 
   /// CreateTempAlloca - This creates a alloca and inserts it into the entry
@@ -2992,8 +2994,8 @@
   /// the LLVM value representation.
   llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
 SourceLocation Loc,
-AlignmentSource AlignSource =
-  AlignmentSource::Type,
+LValueBaseInfo BaseInfo =
+LValueBaseInfo(AlignmentSource::Type),
 llvm::MDNode *TBAAInfo = nullptr,
 QualType TBAABaseTy = QualType(),
 uint64_t TBAAOffset = 0,
@@ -3010,7 +3012,8 @@
   /// the LLVM value representation.
   void EmitStoreOfScalar(llvm::Value *Value, Address Addr,
  bool Volatile, QualType Ty,
- AlignmentSource AlignSource = AlignmentSource::Type,
+ LValueBaseInfo BaseInfo =
+ LValueBaseInfo(AlignmentSource::Type),
  llvm::MDNode *TBAAInfo = nullptr, bool isInit = false,
  QualType TBAABaseTy = QualType(),
  uint64_t TBAAOffset = 0, bool isNontemporal = false);
@@ -3083,7 +3086,7 @@
   RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc);
 
   Address EmitArrayToPointerDecay(const Expr *Array,
-  AlignmentSource *AlignSource = nullptr);
+  LValueBaseInfo *BaseInfo = nullptr);
 
   class ConstantEmission {
 

[PATCH] D33284: [CodeGen] Propagate LValueBaseInfo instead of AlignmentSource

2017-05-17 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added inline comments.



Comment at: lib/CodeGen/CGExpr.cpp:2256
 Address(CapLVal.getPointer(), getContext().getDeclAlign(VD)),
-CapLVal.getType(), AlignmentSource::Decl);
+CapLVal.getType(), LValueBaseInfo(AlignmentSource::Decl, 
MayAlias));
   }

rjmccall wrote:
> Hmm.  I think your side of this is right, but I'm not sure that the original 
> code is correct to override with AlignmentSource::Decl, because the captured 
> field might be a reference.  In fact, I'm not sure why this is overwriting 
> the alignment, either; it should be able to just return the result of 
> EmitCapturedFieldLValue, and that should be more correct for the same reason. 
>  Do any tests break if you do that?
There is one failure in check-clang: test/OpenMP/task_codegen.cpp.


```
; Function Attrs: noinline nounwind
define internal i32 @.omp_task_entry..14(i32, 
%struct.kmp_task_t_with_privates.13* noalias) #1 {
entry:
  %.global_tid..addr.i = alloca i32, align 4
  %.part_id..addr.i = alloca i32*, align 8
  %.privates..addr.i = alloca i8*, align 8
  %.copy_fn..addr.i = alloca void (i8*, ...)*, align 8
  %.task_t..addr.i = alloca i8*, align 8
  %__context.addr.i = alloca %struct.anon.12*, align 8
  %.addr = alloca i32, align 4
  %.addr1 = alloca %struct.kmp_task_t_with_privates.13*, align 8
  store i32 %0, i32* %.addr, align 4
  store %struct.kmp_task_t_with_privates.13* %1, 
%struct.kmp_task_t_with_privates.13** %.addr1, align 8
  %2 = load i32, i32* %.addr, align 4
  %3 = load %struct.kmp_task_t_with_privates.13*, 
%struct.kmp_task_t_with_privates.13** %.addr1, align 8
  %4 = getelementptr inbounds %struct.kmp_task_t_with_privates.13, 
%struct.kmp_task_t_with_privates.13* %3, i32 0, i32 0
  %5 = getelementptr inbounds %struct.kmp_task_t, %struct.kmp_task_t* %4, i32 
0, i32 2
  %6 = getelementptr inbounds %struct.kmp_task_t, %struct.kmp_task_t* %4, i32 
0, i32 0
  %7 = load i8*, i8** %6, align 8
  %8 = bitcast i8* %7 to %struct.anon.12*
  %9 = bitcast %struct.kmp_task_t_with_privates.13* %3 to i8*
  store i32 %2, i32* %.global_tid..addr.i, align 4
  store i32* %5, i32** %.part_id..addr.i, align 8
  store i8* null, i8** %.privates..addr.i, align 8
  store void (i8*, ...)* null, void (i8*, ...)** %.copy_fn..addr.i, align 8
  store i8* %9, i8** %.task_t..addr.i, align 8
  store %struct.anon.12* %8, %struct.anon.12** %__context.addr.i, align 8
  %10 = load %struct.anon.12*, %struct.anon.12** %__context.addr.i, align 8
  store i32 4, i32* @a, align 4
  %11 = getelementptr inbounds %struct.anon.12, %struct.anon.12* %10, i32 0, 
i32 0
  %ref.i = load i32*, i32** %11, align 8
  store i32 5, i32* %ref.i, align 128  // XXX This alignment is 4 with that 
change.
  ret i32 0
}
```



Repository:
  rL LLVM

https://reviews.llvm.org/D33284



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-05-17 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

I posted https://reviews.llvm.org/D33284 for the change from AlignmentSource to 
LValueBaseInfo.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33284: [CodeGen] Propagate LValueBaseInfo instead of AlignmentSource

2017-05-17 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz created this revision.

The functions creating LValues propagated information about alignment source. 
Extend the propagated data to also include information about possible 
unrestricted aliasing. A new class LValueBaseInfo will contain both 
AlignmentSource and MayAlias info.

  

This patch should not introduce any functional changes.


Repository:
  rL LLVM

https://reviews.llvm.org/D33284

Files:
  lib/CodeGen/CGAtomic.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CGObjCRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CGValue.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h

Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1886,15 +1886,15 @@
   //======//
 
   LValue MakeAddrLValue(Address Addr, QualType T,
-AlignmentSource AlignSource = AlignmentSource::Type) {
-return LValue::MakeAddr(Addr, T, getContext(), AlignSource,
+LValueBaseInfo BaseInfo = LValueBaseInfo()) {
+return LValue::MakeAddr(Addr, T, getContext(), BaseInfo,
 CGM.getTBAAInfo(T));
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
-AlignmentSource AlignSource = AlignmentSource::Type) {
+LValueBaseInfo BaseInfo = LValueBaseInfo()) {
 return LValue::MakeAddr(Address(V, Alignment), T, getContext(),
-AlignSource, CGM.getTBAAInfo(T));
+BaseInfo, CGM.getTBAAInfo(T));
   }
 
   LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T);
@@ -1906,11 +1906,11 @@
AlignmentSource *Source = nullptr);
 
   Address EmitLoadOfReference(Address Ref, const ReferenceType *RefTy,
-  AlignmentSource *Source = nullptr);
+  LValueBaseInfo *BaseInfo = nullptr);
   LValue EmitLoadOfReferenceLValue(Address Ref, const ReferenceType *RefTy);
 
   Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy,
-AlignmentSource *Source = nullptr);
+LValueBaseInfo *BaseInfo = nullptr);
   LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy);
 
   /// CreateTempAlloca - This creates a alloca and inserts it into the entry
@@ -2992,8 +2992,7 @@
   /// the LLVM value representation.
   llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
 SourceLocation Loc,
-AlignmentSource AlignSource =
-  AlignmentSource::Type,
+LValueBaseInfo BaseInfo = LValueBaseInfo(),
 llvm::MDNode *TBAAInfo = nullptr,
 QualType TBAABaseTy = QualType(),
 uint64_t TBAAOffset = 0,
@@ -3010,7 +3009,7 @@
   /// the LLVM value representation.
   void EmitStoreOfScalar(llvm::Value *Value, Address Addr,
  bool Volatile, QualType Ty,
- AlignmentSource AlignSource = AlignmentSource::Type,
+ LValueBaseInfo BaseInfo = LValueBaseInfo(),
  llvm::MDNode *TBAAInfo = nullptr, bool isInit = false,
  QualType TBAABaseTy = QualType(),
  uint64_t TBAAOffset = 0, bool isNontemporal = false);
@@ -3083,7 +3082,7 @@
   RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc);
 
   Address EmitArrayToPointerDecay(const Expr *Array,
-  AlignmentSource *AlignSource = nullptr);
+  LValueBaseInfo *BaseInfo = nullptr);
 
   class ConstantEmission {
 llvm::PointerIntPair ValueAndIsReference;
@@ -3224,7 +3223,7 @@
   Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base,
   llvm::Value *memberPtr,
   const MemberPointerType *memberPtrType,
-  AlignmentSource *AlignSource = nullptr);
+  LValueBaseInfo *BaseInfo = nullptr);
   RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E,
   ReturnValueSlot ReturnValue);
 
@@ -3765,7 +3764,7 @@
   ///   just ignore the returned alignment when it isn't from an
   ///   explicit source.
   Address EmitPointerWithAlignment(const Expr *Addr,
-   AlignmentSource *Source = nullptr);
+  

[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-05-15 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

In https://reviews.llvm.org/D31885#751164, @rjmccall wrote:

> The right fix is probably just to make sure that EmitLValueForField doesn't 
> add TBAA information when the base LValue doesn't have it.  That will also 
> fix problems with recursive member access where the base is may_alias.


That won't work for arrays that are member of unions.  We'd need to change 
EmitArraySubscriptExpr, which at some point calls MakeAddrLValue for the type 
being loaded/stored. MakeAddrLValue adds TBAAInfo for that type (unsigned short 
in case of the C testcase) and it does so regardless of any struct paths. This 
TBAA info must be removed for the testcase to be fixed.  At that point we would 
have to examine the base expression to see if it refers to a union member, 
which is not different from the approach in this review.  The LValue 
construction is done in a piecewise manner where some elements of the 
previously (recursively) created LValues may or may not be preserved.  This 
makes me concerned that any more detailed attempt at fixing this may 
accidentally omit some case.
The patch in this review is not intended as a permanent solution, only 
something that is easily revertible and will fix the problem until a better 
solution is developed (which is already worked on).


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-05-10 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

I'm not intimately familiar with clang, so if you know about a better place for 
doing this, please let me know.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-05-10 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

In https://reviews.llvm.org/D31885#748889, @rjmccall wrote:

> Sounds to me like we should just not apply struct-path TBAA data that runs 
> through a union field because either LLVM's representation can't handle it or 
> Clang isn't generating the representation right.  That should be simple to do 
> in a targeted place in Clang rather than awkwardly doing it retroactively 
> like in the current patch.


The TBAA information seems to be assembled from several smaller pieces during 
code generation.  There is already a check for unions in EmitLValueForField, 
which turns off path TBAA information for union fields, but that is not 
sufficient to avoid problems.  Both testcases will still fail with this code in 
place (the C++ testcase needs to be updated: it's missing "-O2 -std=c++11").


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-05-08 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

Ping.

What's the next step here?


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-19 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz updated this revision to Diff 95780.
kparzysz added a comment.

Memoize known results of checking for union access.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/union-tbaa1.c
  test/CodeGenCXX/union-tbaa2.cpp

Index: test/CodeGenCXX/union-tbaa2.cpp
===
--- /dev/null
+++ test/CodeGenCXX/union-tbaa2.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -target-cpu x86-64 -target-feature +sse4.2 -target-feature +avx -emit-llvm -o - | FileCheck %s
+
+// Testcase from llvm.org/PR32056
+
+extern "C" int printf (const char *__restrict __format, ...);
+
+typedef double __m256d __attribute__((__vector_size__(32)));
+
+static __inline __m256d __attribute__((__always_inline__, __nodebug__,
+   __target__("avx")))
+_mm256_setr_pd(double __a, double __b, double __c, double __d) {
+  return (__m256d){ __a, __b, __c, __d };
+}
+
+struct A {
+  A () {
+// Check that there is no TBAA information generated for the stores to the
+// union members:
+// CHECK: store <4 x double>
+// CHECK-NOT: tbaa
+// CHECK: store <4 x double>
+// CHECK-NOT: tbaa
+a = _mm256_setr_pd(0.0, 1.0, 2.0, 3.0);
+b = _mm256_setr_pd(4.0, 5.0, 6.0, 7.0);
+  }
+
+  const double *begin() { return c; }
+  const double *end() { return c+8; }
+
+  union {
+struct { __m256d a, b; };
+double c[8];
+  };
+};
+
+int main(int argc, char *argv[]) {
+  A a;
+  for (double value : a)
+printf("%f ", value);
+  return 0;
+}
Index: test/CodeGen/union-tbaa1.c
===
--- /dev/null
+++ test/CodeGen/union-tbaa1.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -triple hexagon-unknown-elf -O2 -emit-llvm -o - | FileCheck %s
+
+typedef union __attribute__((aligned(4))) {
+  unsigned short uh[2];
+  unsigned uw;
+} vect32;
+
+void bar(vect32 p[][2]);
+
+// CHECK-LABEL: define void @fred
+void fred(unsigned Num, int Vec[2], int *Index, int Arr[4][2]) {
+  vect32 Tmp[4][2];
+// Generate tbaa for the load of Index:
+// CHECK: load i32, i32* %Index{{.*}}tbaa
+// But no tbaa for the two stores:
+// CHECK: %uw[[UW1:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW1]]
+// CHECK-NOT: tbaa
+// There will be a load after the store, and it will use tbaa. Make sure
+// the check-not above doesn't find it:
+// CHECK: load
+  Tmp[*Index][0].uw = Arr[*Index][0] * Num;
+// CHECK: %uw[[UW2:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW2]]
+// CHECK-NOT: tbaa
+  Tmp[*Index][1].uw = Arr[*Index][1] * Num;
+// Same here, don't generate tbaa for the loads:
+// CHECK: %uh[[UH1:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX1:[0-9]*]] = getelementptr{{.*}}%uh[[UH1]]
+// CHECK: load i16, i16* %arrayidx[[AX1]]
+// CHECK-NOT: tbaa
+// CHECK: store
+  Vec[0] = Tmp[*Index][0].uh[1];
+// CHECK: %uh[[UH2:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX2:[0-9]*]] = getelementptr{{.*}}%uh[[UH2]]
+// CHECK: load i16, i16* %arrayidx[[AX2]]
+// CHECK-NOT: tbaa
+// CHECK: store
+  Vec[1] = Tmp[*Index][1].uh[1];
+  bar(Tmp);
+}
+
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -2885,6 +2885,21 @@
   /// that the address will be used to access the object.
   LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK);
 
+private:
+  /// The actual implementations of LValue emission. As a workaround for
+  /// a problem in representing union member accesses in TBAA, the public
+  /// functions will remove the TBAA information from any LValue generated
+  /// for such an access.
+  /// When the TBAA issue is fixed, the public wrappers (declared above)
+  /// should be replaced with these functions.
+  LValue EmitLValueImpl(const Expr *E);
+  LValue EmitCheckedLValueImpl(const Expr *E, TypeCheckKind TCK);
+
+  /// Cached results of previous checks for union access. This is reset
+  /// at the beginning of GenerateCode.
+  llvm::DenseMap UnionAccesses;
+
+public:
   RValue convertTempToRValue(Address addr, QualType type,
  SourceLocation Loc);
 
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1103,6 +1103,9 @@
 
 void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
const CGFunctionInfo ) {
+  // Clear the cache of known union accesses.
+  UnionAccesses.clear();
+
   const FunctionDecl *FD = cast(GD.getDecl());
   CurGD = GD;
 
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -995,7 +995,49 @@
   return true;
 }
 
+/// 

[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-19 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

In https://reviews.llvm.org/D31885#730038, @hfinkel wrote:

> I'm somewhat concerned that this patch is quadratic in the AST.


I'd be happy to address this, but I'm not sure how.  Memoizing results could be 
one way, but don't know if that's acceptable.

This location in codegen seems to be the last place where the original C/C++ 
types are available, in particular the information as to whether a type is a 
union or not.  Maybe it would be possible to propagate some bit somewhere, but 
then this patch would become much less localized.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

I'm not really concerned about the approach here---I can abandon this patch if 
you have something better.  You have two testcases.  One is based on an issue 
that our customer encountered.  As long as TBAA doesn't produce false 
negatives, it's all good.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-14 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

This is not meant as a fine-grained solution to the TBAA problem, but a 
temporary fix for generating wrong information.  Just yesterday I helped 
diagnose yet another problem related to this, so this issue is causing trouble 
out there.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-13 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz updated this revision to Diff 95217.
kparzysz edited the summary of this revision.
kparzysz added a reviewer: hfinkel.
kparzysz added a comment.

Fixed the testcases (forgot to use FileCheck).


Repository:
  rL LLVM

https://reviews.llvm.org/D31885

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/union-tbaa1.c
  test/CodeGenCXX/union-tbaa2.cpp

Index: test/CodeGenCXX/union-tbaa2.cpp
===
--- /dev/null
+++ test/CodeGenCXX/union-tbaa2.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -target-cpu x86-64 -target-feature +sse4.2 -target-feature +avx -emit-llvm -o - | FileCheck %s
+
+// Testcase from llvm.org/PR32056
+
+extern "C" int printf (const char *__restrict __format, ...);
+
+typedef double __m256d __attribute__((__vector_size__(32)));
+
+static __inline __m256d __attribute__((__always_inline__, __nodebug__,
+   __target__("avx")))
+_mm256_setr_pd(double __a, double __b, double __c, double __d) {
+  return (__m256d){ __a, __b, __c, __d };
+}
+
+struct A {
+  A () {
+// Check that there is no TBAA information generated for the stores to the
+// union members:
+// CHECK: store <4 x double>
+// CHECK-NOT: tbaa
+// CHECK: store <4 x double>
+// CHECK-NOT: tbaa
+a = _mm256_setr_pd(0.0, 1.0, 2.0, 3.0);
+b = _mm256_setr_pd(4.0, 5.0, 6.0, 7.0);
+  }
+
+  const double *begin() { return c; }
+  const double *end() { return c+8; }
+
+  union {
+struct { __m256d a, b; };
+double c[8];
+  };
+};
+
+int main(int argc, char *argv[]) {
+  A a;
+  for (double value : a)
+printf("%f ", value);
+  return 0;
+}
Index: test/CodeGen/union-tbaa1.c
===
--- /dev/null
+++ test/CodeGen/union-tbaa1.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -triple hexagon-unknown-elf -O2 -emit-llvm -o - | FileCheck %s
+
+typedef union __attribute__((aligned(4))) {
+  unsigned short uh[2];
+  unsigned uw;
+} vect32;
+
+void bar(vect32 p[][2]);
+
+// CHECK-LABEL: define void @fred
+void fred(unsigned Num, int Vec[2], int *Index, int Arr[4][2]) {
+  vect32 Tmp[4][2];
+// Generate tbaa for the load of Index:
+// CHECK: load i32, i32* %Index{{.*}}tbaa
+// But no tbaa for the two stores:
+// CHECK: %uw[[UW1:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW1]]
+// CHECK-NOT: tbaa
+// There will be a load after the store, and it will use tbaa. Make sure
+// the check-not above doesn't find it:
+// CHECK: load
+  Tmp[*Index][0].uw = Arr[*Index][0] * Num;
+// CHECK: %uw[[UW2:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW2]]
+// CHECK-NOT: tbaa
+  Tmp[*Index][1].uw = Arr[*Index][1] * Num;
+// Same here, don't generate tbaa for the loads:
+// CHECK: %uh[[UH1:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX1:[0-9]*]] = getelementptr{{.*}}%uh[[UH1]]
+// CHECK: load i16, i16* %arrayidx[[AX1]]
+// CHECK-NOT: tbaa
+// CHECK: store
+  Vec[0] = Tmp[*Index][0].uh[1];
+// CHECK: %uh[[UH2:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX2:[0-9]*]] = getelementptr{{.*}}%uh[[UH2]]
+// CHECK: load i16, i16* %arrayidx[[AX2]]
+// CHECK-NOT: tbaa
+// CHECK: store
+  Vec[1] = Tmp[*Index][1].uh[1];
+  bar(Tmp);
+}
+
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -2886,6 +2886,17 @@
   /// that the address will be used to access the object.
   LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK);
 
+private:
+  /// The actual implementations of LValue emission. As a workaround for
+  /// a problem in representing union member accesses in TBAA, the public
+  /// functions will remove the TBAA information from any LValue generated
+  /// for such an access.
+  /// When the TBAA issue is fixed, the public wrappers (declared above)
+  /// should be replaced with these functions.
+  LValue EmitLValueImpl(const Expr *E);
+  LValue EmitCheckedLValueImpl(const Expr *E, TypeCheckKind TCK);
+
+public:
   RValue convertTempToRValue(Address addr, QualType type,
  SourceLocation Loc);
 
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -980,7 +980,37 @@
   return true;
 }
 
+/// Hacks to remove TBAA information from LValues that represent union members.
+/// The TBAA in the current form does not work for union members: the aliasing
+/// information emitted in such cases may be incorrect (leading to incorrect
+/// optimizations).
+static bool isUnionAccess(const Expr *E) {
+  switch (E->getStmtClass()) {
+case Stmt::MemberExprClass: {
+  const Expr *BE = cast(E)->getBase();
+  if (BE->getType()->isUnionType())
+return true;
+  return isUnionAccess(BE);
+}
+case Stmt::ImplicitCastExprClass:
+  return 

[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-10 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz updated this revision to Diff 94721.
kparzysz added a comment.

Cleaned the code up, added testcases.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/union-tbaa1.c
  test/CodeGenCXX/union-tbaa2.cpp

Index: test/CodeGenCXX/union-tbaa2.cpp
===
--- /dev/null
+++ test/CodeGenCXX/union-tbaa2.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -target-cpu x86-64 -target-feature +sse4.2 -target-feature +avx -emit-llvm -o -
+
+// Testcase from llvm.org/PR32056
+
+extern "C" int printf (const char *__restrict __format, ...);
+
+typedef double __m256d __attribute__((__vector_size__(32)));
+
+static __inline __m256d __attribute__((__always_inline__, __nodebug__,
+   __target__("avx")))
+_mm256_setr_pd(double __a, double __b, double __c, double __d) {
+  return (__m256d){ __a, __b, __c, __d };
+}
+
+struct A {
+  A () {
+// Check that there is no TBAA information generated for the stores to the
+// union members:
+// CHECK: store <4 x double>
+// CHECK-NOT: tbaa
+// CHECK: store <4 x double>
+// CHECK-NOT: tbaa
+a = _mm256_setr_pd(0.0, 1.0, 2.0, 3.0);
+b = _mm256_setr_pd(4.0, 5.0, 6.0, 7.0);
+  }
+
+  const double *begin() { return c; }
+  const double *end() { return c+8; }
+
+  union {
+struct { __m256d a, b; };
+double c[8];
+  };
+};
+
+int main(int argc, char *argv[]) {
+  A a;
+  for (double value : a)
+printf("%f ", value);
+  return 0;
+}
Index: test/CodeGen/union-tbaa1.c
===
--- /dev/null
+++ test/CodeGen/union-tbaa1.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 %s -triple hexagon-unknown-elf -O2 -emit-llvm -o -
+
+typedef union __attribute__((aligned(4))) {
+  unsigned short uh[2];
+  unsigned uw;
+} vect32;
+
+void bar(vect32 p[][2]);
+
+// CHECK-LABEL: define void @fred
+void fred(unsigned Num, int Vec[2], int *Index, int Arr[4][2]) {
+  vect32 Tmp[4][2];
+// Generate tbaa for the load of Index:
+// CHECK: load i32, i32* %Index{{.*}}tbaa
+// But no tbaa for the two stores:
+// CHECK: %uw[UW1:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW1]]
+// CHECK-NOT: tbaa
+  Tmp[*Index][0].uw = Arr[*Index][0] * Num;
+// CHECK: %uw[UW2:[0-9]*]] = getelementptr
+// CHECK: store{{.*}}%uw[[UW1]]
+// CHECK-NOT: tbaa
+  Tmp[*Index][1].uw = Arr[*Index][1] * Num;
+// Same here, don't generate tbaa for the loads:
+// CHECK: %uh[[UH1:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX1:[0-9]*]] = getelementptr{{.*}}%uh[[UH1]
+// CHECK: load i16, i16* %arrayidx[[AX1]]
+// CHECK-NOT: tbaa
+  Vec[0] = Tmp[*Index][0].uh[1];
+// CHECK: %uh[[UH2:[0-9]*]] = bitcast %union.vect32
+// CHECK: %arrayidx[[AX2:[0-9]*]] = getelementptr{{.*}}%uh[[UH2]
+// CHECK: load i16, i16* %arrayidx[[AX2]]
+// CHECK-NOT: tbaa
+  Vec[1] = Tmp[*Index][1].uh[1];
+  bar(Tmp);
+}
+
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -2886,6 +2886,17 @@
   /// that the address will be used to access the object.
   LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK);
 
+private:
+  /// The actual implementations of LValue emission. As a workaround for
+  /// a problem in representing union member accesses in TBAA, the public
+  /// functions will remove the TBAA information from any LValue generated
+  /// for such an access.
+  /// When the TBAA issue is fixed, the public wrappers (declared above)
+  /// should be replaced with these functions.
+  LValue EmitLValueImpl(const Expr *E);
+  LValue EmitCheckedLValueImpl(const Expr *E, TypeCheckKind TCK);
+
+public:
   RValue convertTempToRValue(Address addr, QualType type,
  SourceLocation Loc);
 
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -979,7 +979,37 @@
   return true;
 }
 
+/// Hacks to remove TBAA information from LValues that represent union members.
+/// The TBAA in the current form does not work for union members: the aliasing
+/// information emitted in such cases may be incorrect (leading to incorrect
+/// optimizations).
+static bool isUnionAccess(const Expr *E) {
+  switch (E->getStmtClass()) {
+case Stmt::MemberExprClass: {
+  const Expr *BE = cast(E)->getBase();
+  if (BE->getType()->isUnionType())
+return true;
+  return isUnionAccess(BE);
+}
+case Stmt::ImplicitCastExprClass:
+  return isUnionAccess(cast(E)->getSubExpr());
+case Stmt::ArraySubscriptExprClass:
+  return isUnionAccess(cast(E)->getBase());
+default:
+  break;
+  }
+  return false;
+}
+
 LValue CodeGenFunction::EmitCheckedLValue(const Expr *E, TypeCheckKind TCK) {
+  LValue LV = EmitCheckedLValueImpl(E, TCK);

[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-10 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz created this revision.

The TBAA information for union members may be wrong, and in the current form 
TBAA cannot represent them correctly.

This is a follow-up to this thread from llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2017-April/111859.html


Repository:
  rL LLVM

https://reviews.llvm.org/D31885

Files:
  lib/CodeGen/CGExpr.cpp

Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1011,66 +1011,97 @@
 /// type of the same size of the lvalue's type.  If the lvalue has a variable
 /// length type, this is not possible.
 ///
+
+/// Hacks to remove TBAA information from LValues that represent union members.
+/// The TBAA in the current form does not work for union members: the aliasing
+/// information emitted in such cases may be incorrect (leading to incorrect
+/// optimizations).
+static bool isUnionAccess(const Expr *E) {
+  switch (E->getStmtClass()) {
+case Stmt::MemberExprClass:
+  return cast(E)->getBase()->getType()->isUnionType();
+case Stmt::ImplicitCastExprClass:
+  return isUnionAccess(cast(E)->getSubExpr());
+case Stmt::ArraySubscriptExprClass:
+  return isUnionAccess(cast(E)->getBase());
+default:
+  break;
+  }
+  return false;
+}
+
+static LValue ClearTBAA(LValue &, bool Reset) {
+  if (Reset)
+LV.setTBAAInfo(nullptr);
+  return LV;
+}
+
 LValue CodeGenFunction::EmitLValue(const Expr *E) {
+  bool R = CGM.shouldUseTBAA() && isUnionAccess(E);
   ApplyDebugLocation DL(*this, E);
   switch (E->getStmtClass()) {
-  default: return EmitUnsupportedLValue(E, "l-value expression");
+  default: return ClearTBAA(EmitUnsupportedLValue(E, "l-value expression"), R);
 
   case Expr::ObjCPropertyRefExprClass:
 llvm_unreachable("cannot emit a property reference directly");
 
   case Expr::ObjCSelectorExprClass:
-return EmitObjCSelectorLValue(cast(E));
+return ClearTBAA(EmitObjCSelectorLValue(cast(E)), R);
   case Expr::ObjCIsaExprClass:
-return EmitObjCIsaExpr(cast(E));
+return ClearTBAA(EmitObjCIsaExpr(cast(E)), R);
   case Expr::BinaryOperatorClass:
-return EmitBinaryOperatorLValue(cast(E));
+return ClearTBAA(EmitBinaryOperatorLValue(cast(E)), R);
   case Expr::CompoundAssignOperatorClass: {
 QualType Ty = E->getType();
 if (const AtomicType *AT = Ty->getAs())
   Ty = AT->getValueType();
+const auto *CA = cast(E);
 if (!Ty->isAnyComplexType())
-  return EmitCompoundAssignmentLValue(cast(E));
-return EmitComplexCompoundAssignmentLValue(cast(E));
+  return ClearTBAA(EmitCompoundAssignmentLValue(CA), R);
+return ClearTBAA(EmitComplexCompoundAssignmentLValue(CA), R);
   }
   case Expr::CallExprClass:
   case Expr::CXXMemberCallExprClass:
   case Expr::CXXOperatorCallExprClass:
   case Expr::UserDefinedLiteralClass:
-return EmitCallExprLValue(cast(E));
+return ClearTBAA(EmitCallExprLValue(cast(E)), R);
   case Expr::VAArgExprClass:
-return EmitVAArgExprLValue(cast(E));
+return ClearTBAA(EmitVAArgExprLValue(cast(E)), R);
   case Expr::DeclRefExprClass:
-return EmitDeclRefLValue(cast(E));
+return ClearTBAA(EmitDeclRefLValue(cast(E)), R);
   case Expr::ParenExprClass:
-return EmitLValue(cast(E)->getSubExpr());
-  case Expr::GenericSelectionExprClass:
-return EmitLValue(cast(E)->getResultExpr());
+return ClearTBAA(EmitLValue(cast(E)->getSubExpr()), R);
+  case Expr::GenericSelectionExprClass: {
+const auto *GS = cast(E);
+return ClearTBAA(EmitLValue(GS->getResultExpr()), R);
+  }
   case Expr::PredefinedExprClass:
-return EmitPredefinedLValue(cast(E));
+return ClearTBAA(EmitPredefinedLValue(cast(E)), R);
   case Expr::StringLiteralClass:
-return EmitStringLiteralLValue(cast(E));
+return ClearTBAA(EmitStringLiteralLValue(cast(E)), R);
   case Expr::ObjCEncodeExprClass:
-return EmitObjCEncodeExprLValue(cast(E));
+return ClearTBAA(EmitObjCEncodeExprLValue(cast(E)), R);
   case Expr::PseudoObjectExprClass:
-return EmitPseudoObjectLValue(cast(E));
+return ClearTBAA(EmitPseudoObjectLValue(cast(E)), R);
   case Expr::InitListExprClass:
-return EmitInitListLValue(cast(E));
+return ClearTBAA(EmitInitListLValue(cast(E)), R);
   case Expr::CXXTemporaryObjectExprClass:
   case Expr::CXXConstructExprClass:
-return EmitCXXConstructLValue(cast(E));
-  case Expr::CXXBindTemporaryExprClass:
-return EmitCXXBindTemporaryLValue(cast(E));
+return ClearTBAA(EmitCXXConstructLValue(cast(E)), R);
+  case Expr::CXXBindTemporaryExprClass: {
+const auto *BT = cast(E);
+return ClearTBAA(EmitCXXBindTemporaryLValue(BT), R);
+  }
   case Expr::CXXUuidofExprClass:
-return EmitCXXUuidofLValue(cast(E));
+return ClearTBAA(EmitCXXUuidofLValue(cast(E)), R);
   case Expr::LambdaExprClass:
-return EmitLambdaLValue(cast(E));
+return ClearTBAA(EmitLambdaLValue(cast(E)), R);
 
   case Expr::ExprWithCleanupsClass: {
  

[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-10 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added inline comments.



Comment at: lib/CodeGen/CGExpr.cpp:1019
+/// optimizations).
+static bool isUnionAccess(const Expr *E) {
+  switch (E->getStmtClass()) {

I'm not sure if this is a complete list of different ways to get a union member.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-04-10 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz updated this revision to Diff 94699.
kparzysz added a comment.

Do not stop the check for unions at the first MemberExpr (unless it's a union).


Repository:
  rL LLVM

https://reviews.llvm.org/D31885

Files:
  lib/CodeGen/CGExpr.cpp

Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1011,66 +1011,101 @@
 /// type of the same size of the lvalue's type.  If the lvalue has a variable
 /// length type, this is not possible.
 ///
+
+/// Hacks to remove TBAA information from LValues that represent union members.
+/// The TBAA in the current form does not work for union members: the aliasing
+/// information emitted in such cases may be incorrect (leading to incorrect
+/// optimizations).
+static bool isUnionAccess(const Expr *E) {
+  switch (E->getStmtClass()) {
+case Stmt::MemberExprClass: {
+  const Expr *BE = cast(E)->getBase();
+  if (BE->getType()->isUnionType())
+return true;
+  return isUnionAccess(BE);
+}
+case Stmt::ImplicitCastExprClass:
+  return isUnionAccess(cast(E)->getSubExpr());
+case Stmt::ArraySubscriptExprClass:
+  return isUnionAccess(cast(E)->getBase());
+default:
+  break;
+  }
+  return false;
+}
+
+static LValue ClearTBAA(LValue &, bool Reset) {
+  if (Reset)
+LV.setTBAAInfo(nullptr);
+  return LV;
+}
+
 LValue CodeGenFunction::EmitLValue(const Expr *E) {
+  bool R = CGM.shouldUseTBAA() && isUnionAccess(E);
   ApplyDebugLocation DL(*this, E);
   switch (E->getStmtClass()) {
-  default: return EmitUnsupportedLValue(E, "l-value expression");
+  default: return ClearTBAA(EmitUnsupportedLValue(E, "l-value expression"), R);
 
   case Expr::ObjCPropertyRefExprClass:
 llvm_unreachable("cannot emit a property reference directly");
 
   case Expr::ObjCSelectorExprClass:
-return EmitObjCSelectorLValue(cast(E));
+return ClearTBAA(EmitObjCSelectorLValue(cast(E)), R);
   case Expr::ObjCIsaExprClass:
-return EmitObjCIsaExpr(cast(E));
+return ClearTBAA(EmitObjCIsaExpr(cast(E)), R);
   case Expr::BinaryOperatorClass:
-return EmitBinaryOperatorLValue(cast(E));
+return ClearTBAA(EmitBinaryOperatorLValue(cast(E)), R);
   case Expr::CompoundAssignOperatorClass: {
 QualType Ty = E->getType();
 if (const AtomicType *AT = Ty->getAs())
   Ty = AT->getValueType();
+const auto *CA = cast(E);
 if (!Ty->isAnyComplexType())
-  return EmitCompoundAssignmentLValue(cast(E));
-return EmitComplexCompoundAssignmentLValue(cast(E));
+  return ClearTBAA(EmitCompoundAssignmentLValue(CA), R);
+return ClearTBAA(EmitComplexCompoundAssignmentLValue(CA), R);
   }
   case Expr::CallExprClass:
   case Expr::CXXMemberCallExprClass:
   case Expr::CXXOperatorCallExprClass:
   case Expr::UserDefinedLiteralClass:
-return EmitCallExprLValue(cast(E));
+return ClearTBAA(EmitCallExprLValue(cast(E)), R);
   case Expr::VAArgExprClass:
-return EmitVAArgExprLValue(cast(E));
+return ClearTBAA(EmitVAArgExprLValue(cast(E)), R);
   case Expr::DeclRefExprClass:
-return EmitDeclRefLValue(cast(E));
+return ClearTBAA(EmitDeclRefLValue(cast(E)), R);
   case Expr::ParenExprClass:
-return EmitLValue(cast(E)->getSubExpr());
-  case Expr::GenericSelectionExprClass:
-return EmitLValue(cast(E)->getResultExpr());
+return ClearTBAA(EmitLValue(cast(E)->getSubExpr()), R);
+  case Expr::GenericSelectionExprClass: {
+const auto *GS = cast(E);
+return ClearTBAA(EmitLValue(GS->getResultExpr()), R);
+  }
   case Expr::PredefinedExprClass:
-return EmitPredefinedLValue(cast(E));
+return ClearTBAA(EmitPredefinedLValue(cast(E)), R);
   case Expr::StringLiteralClass:
-return EmitStringLiteralLValue(cast(E));
+return ClearTBAA(EmitStringLiteralLValue(cast(E)), R);
   case Expr::ObjCEncodeExprClass:
-return EmitObjCEncodeExprLValue(cast(E));
+return ClearTBAA(EmitObjCEncodeExprLValue(cast(E)), R);
   case Expr::PseudoObjectExprClass:
-return EmitPseudoObjectLValue(cast(E));
+return ClearTBAA(EmitPseudoObjectLValue(cast(E)), R);
   case Expr::InitListExprClass:
-return EmitInitListLValue(cast(E));
+return ClearTBAA(EmitInitListLValue(cast(E)), R);
   case Expr::CXXTemporaryObjectExprClass:
   case Expr::CXXConstructExprClass:
-return EmitCXXConstructLValue(cast(E));
-  case Expr::CXXBindTemporaryExprClass:
-return EmitCXXBindTemporaryLValue(cast(E));
+return ClearTBAA(EmitCXXConstructLValue(cast(E)), R);
+  case Expr::CXXBindTemporaryExprClass: {
+const auto *BT = cast(E);
+return ClearTBAA(EmitCXXBindTemporaryLValue(BT), R);
+  }
   case Expr::CXXUuidofExprClass:
-return EmitCXXUuidofLValue(cast(E));
+return ClearTBAA(EmitCXXUuidofLValue(cast(E)), R);
   case Expr::LambdaExprClass:
-return EmitLambdaLValue(cast(E));
+return ClearTBAA(EmitLambdaLValue(cast(E)), R);
 
   case Expr::ExprWithCleanupsClass: {
 const auto 

[PATCH] D25811: [libcxx] Fix toupper/tolower tests for UTF-8 locale

2017-01-03 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz abandoned this revision.
kparzysz added a comment.

In https://reviews.llvm.org/D25811#632670, @EricWF wrote:

> While I was attempting to review this patch I ended up coming up with fixed 
> tests myself. I committed them in r290746. I'm very sorry to step on your 
> toes.


No problem at all.  Thanks for the fixes!


Repository:
  rL LLVM

https://reviews.llvm.org/D25811



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits