r374035 - [Diagnostics] Silence -Wsizeof-array-div for character buffers

2019-10-08 Thread James Clarke via cfe-commits
Author: jrtc27
Date: Tue Oct  8 04:34:02 2019
New Revision: 374035

URL: http://llvm.org/viewvc/llvm-project?rev=374035&view=rev
Log:
[Diagnostics] Silence -Wsizeof-array-div for character buffers

Summary:
Character buffers are sometimes used to represent a pool of memory that
contains non-character objects, due to them being synonymous with a stream of
bytes on almost all modern architectures. Often, when interacting with hardware
devices, byte buffers are therefore used as an intermediary and so we can end
Character buffers are sometimes used to represent a pool of memory that
contains non-character objects, due to them being synonymous with a stream of
bytes on almost all modern architectures. Often, when interacting with hardware
devices, byte buffers are therefore used as an intermediary and so we can end
up generating lots of false-positives.

Moreover, due to the ability of character pointers to alias non-character
pointers, the strict aliasing violations that would generally be implied by the
calculations caught by the warning (if the calculation itself is in fact
correct) do not apply here, and so although the length calculation may be
wrong, that is the only possible issue.

Reviewers: rsmith, xbolva00, thakis

Reviewed By: xbolva00, thakis

Subscribers: thakis, lebedev.ri, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68526

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/div-sizeof-array.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=374035&r1=374034&r2=374035&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Oct  8 04:34:02 2019
@@ -9197,6 +9197,7 @@ static void DiagnoseDivisionSizeofPointe
 QualType ArrayElemTy = ArrayTy->getElementType();
 if (ArrayElemTy != S.Context.getBaseElementType(ArrayTy) ||
 ArrayElemTy->isDependentType() || RHSTy->isDependentType() ||
+ArrayElemTy->isCharType() ||
 S.Context.getTypeSize(ArrayElemTy) == S.Context.getTypeSize(RHSTy))
   return;
 S.Diag(Loc, diag::warn_division_sizeof_array)

Modified: cfe/trunk/test/Sema/div-sizeof-array.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-array.cpp?rev=374035&r1=374034&r2=374035&view=diff
==
--- cfe/trunk/test/Sema/div-sizeof-array.cpp (original)
+++ cfe/trunk/test/Sema/div-sizeof-array.cpp Tue Oct  8 04:34:02 2019
@@ -25,6 +25,8 @@ void test(void) {
   int a10 = sizeof(arr3) / sizeof(char);
   int a11 = sizeof(arr2) / (sizeof(unsigned));
   int a12 = sizeof(arr) / (sizeof(short));
+  int a13 = sizeof(arr3) / sizeof(p);
+  int a14 = sizeof(arr3) / sizeof(int);
 
   int arr4[10][12];
   int b1 = sizeof(arr4) / sizeof(arr2[12]);


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


r374013 - [ItaniumMangle] Fix mangling of GNU __null in an expression to match GCC

2019-10-08 Thread James Clarke via cfe-commits
Author: jrtc27
Date: Mon Oct  7 19:28:57 2019
New Revision: 374013

URL: http://llvm.org/viewvc/llvm-project?rev=374013&view=rev
Log:
[ItaniumMangle] Fix mangling of GNU __null in an expression to match GCC

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: erik.pilkington, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68368

Modified:
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=374013&r1=374012&r2=374013&view=diff
==
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Mon Oct  7 19:28:57 2019
@@ -4273,8 +4273,11 @@ recurse:
   }
 
   case Expr::GNUNullExprClass:
-// FIXME: should this really be mangled the same as nullptr?
-// fallthrough
+// Mangle as if an integer literal 0.
+Out << 'L';
+mangleType(E->getType());
+Out << "0E";
+break;
 
   case Expr::CXXNullPtrLiteralExprClass: {
 Out << "LDnE";

Modified: cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp?rev=374013&r1=374012&r2=374013&view=diff
==
--- cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp Mon Oct  7 19:28:57 2019
@@ -373,3 +373,19 @@ namespace designated_init {
   template void f(decltype(T{.a.b[3][1 ... 4] = 9}) x) {}
   void use_f(A a) { f(a); }
 }
+
+namespace null {
+  template 
+  void cpp_nullptr(typename enable_if::type* = 0) {
+  }
+
+  template 
+  void gnu_null(typename enable_if::type* = 0) {
+  }
+
+  // CHECK-LABEL: define {{.*}} 
@_ZN4null11cpp_nullptrILDn0EEEvPN9enable_ifIXeqT_LDnEEvE4typeE
+  template void cpp_nullptr(void *);
+
+  // CHECK-LABEL: define {{.*}} 
@_ZN4null8gnu_nullILPv0EEEvPN9enable_ifIXeqT_Ll0EEvE4typeE
+  template void gnu_null(void *);
+}


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


[clang] 3d6c492 - [RISCV] Fix ILP32D lowering for double+double/double+int return types

2020-01-14 Thread James Clarke via cfe-commits

Author: James Clarke
Date: 2020-01-14T11:17:19Z
New Revision: 3d6c492d7a9830a1a39b85dfa215743581d52715

URL: 
https://github.com/llvm/llvm-project/commit/3d6c492d7a9830a1a39b85dfa215743581d52715
DIFF: 
https://github.com/llvm/llvm-project/commit/3d6c492d7a9830a1a39b85dfa215743581d52715.diff

LOG: [RISCV] Fix ILP32D lowering for double+double/double+int return types

Summary:
Previously, since these aggregates are > 2*XLen, Clang would think they
were being returned indirectly and thus would decrease the number of
available GPRs available by 1. For long argument lists this could lead
to a struct argument incorrectly being passed indirectly.

Reviewers: asb, lenary

Reviewed By: asb, lenary

Subscribers: luismarques, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, 
kito-cheng, shiva0217, zzheng, edward-jones, rogfer01, MartinMosbeck, 
brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, Jim, lenary, 
s.egerton, pzheng, sameer.abuasal, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69590

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGen/riscv32-ilp32d-abi.c

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 7068fa0fcc69..dd6597f154bb 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -9377,11 +9377,21 @@ void RISCVABIInfo::computeInfo(CGFunctionInfo &FI) 
const {
 FI.getReturnInfo() = classifyReturnType(RetTy);
 
   // IsRetIndirect is true if classifyArgumentType indicated the value should
-  // be passed indirect or if the type size is greater than 2*xlen. e.g. fp128
-  // is passed direct in LLVM IR, relying on the backend lowering code to
-  // rewrite the argument list and pass indirectly on RV32.
-  bool IsRetIndirect = FI.getReturnInfo().getKind() == ABIArgInfo::Indirect ||
-   getContext().getTypeSize(RetTy) > (2 * XLen);
+  // be passed indirect, or if the type size is a scalar greater than 2*XLen
+  // and not a complex type with elements <= FLen. e.g. fp128 is passed direct
+  // in LLVM IR, relying on the backend lowering code to rewrite the argument
+  // list and pass indirectly on RV32.
+  bool IsRetIndirect = FI.getReturnInfo().getKind() == ABIArgInfo::Indirect;
+  if (!IsRetIndirect && RetTy->isScalarType() &&
+  getContext().getTypeSize(RetTy) > (2 * XLen)) {
+if (RetTy->isComplexType() && FLen) {
+  QualType EltTy = RetTy->getAs()->getElementType();
+  IsRetIndirect = getContext().getTypeSize(EltTy) > FLen;
+} else {
+  // This is a normal scalar > 2*XLen, such as fp128 on RV32.
+  IsRetIndirect = true;
+}
+  }
 
   // We must track the number of GPRs used in order to conform to the RISC-V
   // ABI, as integer scalars passed in registers should have signext/zeroext

diff  --git a/clang/test/CodeGen/riscv32-ilp32d-abi.c 
b/clang/test/CodeGen/riscv32-ilp32d-abi.c
index 078fcb6b5ab1..b5b451cee151 100644
--- a/clang/test/CodeGen/riscv32-ilp32d-abi.c
+++ b/clang/test/CodeGen/riscv32-ilp32d-abi.c
@@ -280,3 +280,27 @@ void f_double_u_arg(union double_u a) {}
 union double_u f_ret_double_u() {
   return (union double_u){1.0};
 }
+
+// Test that we don't incorrectly think double+int/double+double structs will
+// be returned indirectly and thus have an off-by-one error for the number of
+// GPRs available (this is an edge case when structs > 2*XLEN are still
+// returned in registers). This includes complex doubles, which are treated as
+// double+double structs by the ABI.
+
+// CHECK: define { double, i32 } 
@f_ret_double_int32_s_double_int32_s_just_sufficient_gprs(i32 %a, i32 %b, i32 
%c, i32 %d, i32 %e, i32 %f, i32 %g, double %0, i32 %1)
+struct double_int32_s f_ret_double_int32_s_double_int32_s_just_sufficient_gprs(
+int a, int b, int c, int d, int e, int f, int g, struct double_int32_s h) {
+  return (struct double_int32_s){1.0, 2};
+}
+
+// CHECK: define { double, double } 
@f_ret_double_double_s_double_int32_s_just_sufficient_gprs(i32 %a, i32 %b, i32 
%c, i32 %d, i32 %e, i32 %f, i32 %g, double %0, i32 %1)
+struct double_double_s 
f_ret_double_double_s_double_int32_s_just_sufficient_gprs(
+int a, int b, int c, int d, int e, int f, int g, struct double_int32_s h) {
+  return (struct double_double_s){1.0, 2.0};
+}
+
+// CHECK: define { double, double } 
@f_ret_doublecomplex_double_int32_s_just_sufficient_gprs(i32 %a, i32 %b, i32 
%c, i32 %d, i32 %e, i32 %f, i32 %g, double %0, i32 %1)
+double __complex__ f_ret_doublecomplex_double_int32_s_just_sufficient_gprs(
+int a, int b, int c, int d, int e, int f, int g, struct double_int32_s h) {
+  return 1.0;
+}



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