[PATCH] D64083: [OpenCL][Sema] Improve address space support for blocks

2019-07-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: cfe/trunk/lib/Sema/SemaExprCXX.cpp:4229
+LangAS AddrSpaceR =
+RHSType->getAs()->getPointeeType().getAddressSpace();
+CastKind Kind =

All of this can be much simpler:

```
LangAS AddrSpaceL = 
ToType->castAs()->getPointeeType().getAddressSpace();
LangAS AddrSpaceR = 
FromType->castAs()->getPointeeType().getAddressSpace();
```

Is there something actually checking the validity of this address-space cast 
somewhere?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D64083



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


[PATCH] D64464: [CodeGen] Emit destructor calls for non-trivial C structs

2019-07-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGExpr.cpp:4100
+  if (E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct)
+pushDestroy(QualType::DK_nontrivial_c_struct, DeclPtr, E->getType());
+

Unfortunately, the lifetime of compound literals in C is not this simple; 
they're like blocks in that they're destroyed at the end of the enclosing scope 
rather than at the end of the current statement. (The cleanup here will be 
popped at the end of the full-expression if we've entered an 
`ExprWithCleanups`.) And the l-value case is exactly the case where this 
matters.

I think you need to do something like what we do with blocks, where we record 
all the blocks in the full-expression on the `ExprWithCleanups` so that we can 
push an inactive cleanup for them and then activate it when we emit the block.



Comment at: lib/CodeGen/CGExprAgg.cpp:248
   bool RequiresDestruction =
-  Dest.isIgnored() &&
+  !Dest.isExternallyDestructed() &&
   RetTy.isDestructedType() == QualType::DK_nontrivial_c_struct;

ahatanak wrote:
> This change wasn't needed to fix the bugs, but I think 
> `isExternallyDestructed` instead of `isIgnored` should be called to determine 
> whether the returned value requires destruction.
Agreed.



Comment at: lib/CodeGen/CGExprAgg.cpp:668
+Dest.setExternallyDestructed();
+  }
   CGF.EmitAggExpr(E->getInitializer(), Slot);

The cleanup shouldn't be pushed until after you've finished evaluating the 
initializer.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64464



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


[PATCH] D63753: [Sema] Instead of rejecting C unions with non-trivial fields, detect attempts to destruct/initialize/copy them.

2019-07-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thanks, that looks great.  A few more requests and then this will be ready to 
go, I think.




Comment at: include/clang/AST/DeclBase.h:1454
   /// Number of non-inherited bits in RecordDeclBitfields.
   enum { NumRecordDeclBits = 11 };
 

This needs to be updated.



Comment at: include/clang/AST/Type.h:1133
+  /// Check if this is or contains a non-trivial C struct/union type.
+  bool hasNonTrivialPrimitiveCStruct() const;
 

rjmccall wrote:
> ahatanak wrote:
> > rjmccall wrote:
> > > You only want these checks to trigger on unions with non-trivial members 
> > > (or structs containing them), right?  How about something like 
> > > `hasNonTrivialPrimitiveCUnionMember()`?  Or maybe make it more 
> > > descriptive for the use sites, like `isPrimitiveCRestrictedType()`?
> > > 
> > > Also, it would be nice if the fast path of this could be inlined so that 
> > > clients usually didn't had to make a call at all.  You can write the 
> > > `getBaseElementTypeUnsafe()->getAs()` part in an `inline` 
> > > implementation at the bottom this file.
> > Since we don't keep track of whether a struct or union is or contains 
> > unions with non-trivial members, we'll have to use the visitors to detect 
> > such structs or unions or, to do it faster, add a bit to `RecordDeclBits` 
> > that indicates the presence of non-trivial unions. I guess it's okay to add 
> > another bit to `RecordDeclBits`?
> It looks like there's plenty of space in `RecordDeclBits`, yeah.
This comment seems like the right place to explain what makes a union 
non-trivial in C (that it contains a member which is non-trivial for *any* of 
the reasons that a type might be non-trivial).



Comment at: include/clang/AST/Type.h:1238
+  /// Check if \param RD is or contains a non-trivial C union.
+  bool hasNonTrivialPrimitiveCUnionMember(const RecordDecl *RD) const;
 };

This should be `static`, right?



Comment at: lib/Sema/SemaDecl.cpp:11648
+if (VDecl->getType().hasNonTrivialPrimitiveCUnionMember() &&
+VDecl->hasLocalStorage()) {
+  if (auto *ILE = dyn_cast(Init))

Please add a comment explaining why this is specific to local variables.



Comment at: lib/Sema/SemaDecl.cpp:12053
+NTCUC_UninitAutoVar);
 }
+

Please add a comment explaining why this is specific to local variables.



Comment at: lib/Sema/SemaExpr.cpp:6097
+  // non-trivial to copy or default-initialize.
+  checkNonTrivialCUnionInInitList(ILE);
+  }

Can we extract a common function that checks the initializer expression of a 
non-trivial C union?  I think there are at least three separate places that do 
that in this patch, and it's not too hard to imagine that we might want to add 
more cases to the common analysis.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63753



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


[PATCH] D64294: [Driver] Consolidate shouldUseFramePointer() and shouldUseLeafFramePointer()

2019-07-09 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:579
 
-static bool shouldUseFramePointer(const ArgList ,
-  const llvm::Triple ) {
-  if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer,
-   options::OPT_fomit_frame_pointer))
-return A->getOption().matches(options::OPT_fno_omit_frame_pointer) ||
-   mustUseNonLeafFramePointerForTarget(Triple);
-
-  if (Args.hasArg(options::OPT_pg))
-return true;
-
-  return useFramePointerForTargetByDefault(Args, Triple);
-}
-
-static bool shouldUseLeafFramePointer(const ArgList ,
-  const llvm::Triple ) {
-  if (Arg *A = Args.getLastArg(options::OPT_mno_omit_leaf_frame_pointer,
-   options::OPT_momit_leaf_frame_pointer))
-return A->getOption().matches(options::OPT_mno_omit_leaf_frame_pointer);
-
-  if (Args.hasArg(options::OPT_pg))
-return true;
-
-  if (Triple.isPS4CPU())
-return false;
-
-  return useFramePointerForTargetByDefault(Args, Triple);
+static FramePointerKind getFramePointerKind(const ArgList ,
+const llvm::Triple ) {

`getFramePointerKind` -> `decideFramePointerKind` / `determineFramePointerKind` 
? 



Comment at: lib/Driver/ToolChains/Clang.cpp:585
+  (A && A->getOption().matches(options::OPT_fno_omit_frame_pointer)) ||
+  (!(A && A->getOption().matches(options::OPT_fomit_frame_pointer)) &&
+   (Args.hasArg(options::OPT_pg) ||

It looks better if  `frame_pointer` is represented using tri-state. Something 
like this?

It would be great to have comments for conditions that are not obvious such as 
the overriding rules.

```
  // There are three states for frame_pointer.
  enum class FpFlag {true, false, none};
  FpFlag FPF = FpFlag::none;
  if (Arg *A = Args.getLastArg(options::OPT_fomit_frame_pointer,
   options::OPT_fno_omit_frame_pointer))
FPF = A->getOption().matches(options::OPT_fno_omit_frame_pointer)) ?
 FpFlag::true : FpFlag::false;

  if (!mustUseNonLeaf && FPF == FpFlag::false)
return FramePointerKind::None;

  if (mustUseNonLeaf || FPF == FpFlag::true || Args.hasArg(options::OPT_pg) ||
  useFramePointerForTargetByDefault(Args, Triple)) {
if (Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
 options::OPT_mno_omit_leaf_frame_pointer,
 Triple.isPS4CPU()))
  return FramePointerKind::NonLeaf;
return FramePointerKind::All;
  }
  return FramePointerKind::None;
```


Repository:
  rC Clang

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

https://reviews.llvm.org/D64294



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


[PATCH] D64283: [PowerPC] Support -mabi=ieeelongdouble and -mabi=ibmlongdouble

2019-07-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 208875.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Add another test: -mabi=elfv2 -mabi=elfv1 -mabi=ibmlongdouble 
-mabi=ieeelongdouble

Try fixing the markdown in the description


Repository:
  rC Clang

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

https://reviews.llvm.org/D64283

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/PPC.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/ppc64-long-double.cpp
  test/Driver/ppc-abi.c

Index: test/Driver/ppc-abi.c
===
--- test/Driver/ppc-abi.c
+++ test/Driver/ppc-abi.c
@@ -66,4 +66,22 @@
 // CHECK-ELFv2-PIC: "-mrelocation-model" "pic" "-pic-level" "2"
 // CHECK-ELFv2-PIC: "-target-abi" "elfv2"
 
+// Check -mabi=ieeelongdouble is passed through but it does not change -target-abi.
+// RUN: %clang -target powerpc64le-linux-gnu %s -mabi=ieeelongdouble -mabi=elfv1 -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ELFv1-IEEE %s
+// RUN: %clang -target powerpc64le-linux-gnu %s -mabi=elfv1 -mabi=ieeelongdouble -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ELFv1-IEEE %s
+// RUN: %clang -target powerpc64le-linux-gnu %s -mabi=elfv2 -mabi=elfv1 -mabi=ibmlongdouble -mabi=ieeelongdouble -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ELFv1-IEEE %s
 
+// CHECK-ELFv1-IEEE: "-mabi=ieeelongdouble"
+// CHECK-ELFv1-IEEE: "-target-abi" "elfv1"
+
+// Check -mabi=ibmlongdouble is the default.
+// RUN: %clang -target powerpc64le-linux-gnu %s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s
+// RUN: %clang -target powerpc64le-linux-gnu %s -mabi=ibmlongdouble -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s
+
+// CHECK-ELFv2-IBM128-NOT: "-mabi=ieeelongdouble"
+// CHECK-ELFv2-IBM128: "-target-abi" "elfv2"
Index: test/CodeGen/ppc64-long-double.cpp
===
--- test/CodeGen/ppc64-long-double.cpp
+++ test/CodeGen/ppc64-long-double.cpp
@@ -3,6 +3,14 @@
 // RUN: %clang_cc1 -triple powerpc64-linux-gnu -emit-llvm -o - %s -mlong-double-64 | \
 // RUN:   FileCheck --check-prefix=FP64 %s
 
+// musl defaults to -mlong-double-64, so -mlong-double-128 is needed to make
+// -mabi=ieeelongdouble effective.
+// RUN: %clang_cc1 -triple powerpc64-linux-musl -emit-llvm -o - %s -mlong-double-128 \
+// RUN:   -mabi=ieeelongdouble | FileCheck --check-prefix=FP128 %s
+// RUN: %clang_cc1 -triple powerpc64-linux-gnu -emit-llvm -o - %s \
+// RUN:   -mabi=ieeelongdouble | FileCheck --check-prefix=FP128 %s
+
+// IBM extended double is the default.
 // RUN: %clang_cc1 -triple powerpc64-linux-gnu -emit-llvm -o - %s | \
 // RUN:   FileCheck --check-prefix=IBM128 %s
 // RUN: %clang_cc1 -triple powerpc64-linux-musl -emit-llvm -o - -mlong-double-128 %s | \
@@ -13,10 +21,13 @@
 
 // FP64: @x = global double {{.*}}, align 8
 // FP64: @size = global i32 8
+// FP128: @x = global fp128 {{.*}}, align 16
+// FP128: @size = global i32 16
 // IBM128: @x = global ppc_fp128 {{.*}}, align 16
 // IBM128: @size = global i32 16
 
 long double foo(long double d) { return d; }
 
 // FP64: double @_Z3fooe(double %d)
+// FP128: fp128 @_Z3foou9__ieee128(fp128 %d)
 // IBM128: ppc_fp128 @_Z3foog(ppc_fp128 %d)
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2745,6 +2745,7 @@
   Opts.LongDoubleSize = Args.hasArg(OPT_mlong_double_128)
 ? 128
 : Args.hasArg(OPT_mlong_double_64) ? 64 : 0;
+  Opts.PPCIEEELongDouble = Args.hasArg(OPT_mabi_EQ_ieeelongdouble);
   Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
   Opts.ROPI = Args.hasArg(OPT_fropi);
   Opts.RWPI = Args.hasArg(OPT_frwpi);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -1808,12 +1808,27 @@
   break;
 }
 
-  if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
-// The ppc64 linux abis are all "altivec" abis by default. Accept and ignore
-// the option if given as we don't have backend support for any targets
-// that don't use the altivec abi.
-if (StringRef(A->getValue()) != "altivec")
-  ABIName = A->getValue();
+  bool IEEELongDouble = false, SeenLongDouble = false, SeenOther = false;
+  for (Arg *A : Args.filtered_reverse(options::OPT_mabi_EQ,
+  options::OPT_mabi_EQ_ieeelongdouble)) {
+if (A->getOption().matches(options::OPT_mabi_EQ_ieeelongdouble)) {
+  A->claim();
+  if (!SeenLongDouble)
+IEEELongDouble = true;
+  SeenLongDouble = true;
+} else if (StringRef(A->getValue()) == 

[PATCH] D64283: [PowerPC] Support -mabi=ieeelongdouble and -mabi=ibmlongdouble

2019-07-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:1825
+  // that don't use the altivec abi.
+  if (!SeenOther)
+ABIName = A->getValue();

hfinkel wrote:
> This seems like an unintentional behavior change on top of the existing 
> behavior (which may have also been not quite right). As best I can tell, 
> we're trying to set ABIName equal to the last ABI type specified, unless that 
> type is "altivec", in which case the ABI name should be its default value 
> (either a nullptr or something like "elfv2"). With this change, we'll now 
> take the first ABI name seen, not the last (as we'll get SeenOther to true 
> after the first name).
> 
> Maybe we should loop over the list multiple times, once to get the 
> long-double format, once to get the basic ABI name (where we save the 
> default, and then if the last name found is "altivec", then reset to the 
> default)?
> 
My understanding (could be wrong) is that "ibmlongdouble", "ieeelongdouble", 
and "altivec" cannot be ABIName, so I write it this way (filtered_reverse + 
SeenLongDouble + SeenOther).

e.g. with -mabi=elfv2 -mabi=ieeelongdouble, ABIName should be "elfv2". With 
-mabi=elfv1 -mabi=ieeelongdouble, ABIName should be "elfv1" (no local entry). 
This matches the behavior I observed from powerpc64le-linux-gnu-gcc.

Before the change, ABIName is "ieeelongdouble". I think that is not desired.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64283



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


[PATCH] D64464: [CodeGen] Emit destructor calls for non-trivial C structs

2019-07-09 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added inline comments.



Comment at: lib/CodeGen/CGExprAgg.cpp:248
   bool RequiresDestruction =
-  Dest.isIgnored() &&
+  !Dest.isExternallyDestructed() &&
   RetTy.isDestructedType() == QualType::DK_nontrivial_c_struct;

This change wasn't needed to fix the bugs, but I think `isExternallyDestructed` 
instead of `isIgnored` should be called to determine whether the returned value 
requires destruction.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64464



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


[PATCH] D64464: [CodeGen] Emit destructor calls for non-trivial C structs

2019-07-09 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added a reviewer: rjmccall.
ahatanak added a project: clang.
Herald added subscribers: dexonsmith, jkorous.

This patch fixes a bug in IRGen where it wasn't calling the destructors for 
non-trivial C structs in the following cases:

- member access of structs that are returned from a function.
- compound literal.
- load from volatile types.

rdar://problem/51867864


Repository:
  rC Clang

https://reviews.llvm.org/D64464

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  test/CodeGenObjC/strong-in-c-struct.m

Index: test/CodeGenObjC/strong-in-c-struct.m
===
--- test/CodeGenObjC/strong-in-c-struct.m
+++ test/CodeGenObjC/strong-in-c-struct.m
@@ -521,7 +521,9 @@
 
 // CHECK: define void @test_copy_constructor_StrongVolatile0(
 // CHECK: call void @__copy_constructor_8_8_t0w4_sv8(
+// CHECK-NOT: call
 // CHECK: call void @__destructor_8_sv8(
+// CHECK-NOT: call
 
 // CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w4_sv8(
 // CHECK: %[[V8:.*]] = load volatile i8*, i8** %{{.*}}, align 8
@@ -718,4 +720,42 @@
   VolatileArray t = *a;
 }
 
+// CHECK: define void @test_member_access(
+// CHECK: %[[TMP:.*]] = alloca %[[STRUCT_STRONGSMALL]],
+// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8**
+// CHECK: call void @__destructor_8_s8(i8** %[[V3]])
+
+void test_member_access(void) {
+  id t = getStrongSmall().f1;
+}
+
+// CHECK: define void @test_compound_literal(
+// CHECK: %[[_COMPOUNDLITERAL:.*]] = alloca %[[STRUCT_STRONGSMALL]],
+// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]] to i8**
+// CHECK: call void @__destructor_8_s8(i8** %[[V0]])
+
+void test_compound_literal(void) {
+  StrongSmall *p = &(StrongSmall){ 1, 0 };
+}
+
+// CHECK: define void @test_compound_literal2(
+// CHECK: %[[AGG_TMP_ENSURED:.*]] = alloca %[[STRUCT_STRONGSMALL]],
+// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[AGG_TMP_ENSURED]] to i8**
+// CHECK: call void @__destructor_8_s8(i8** %[[V0]])
+
+void test_compound_literal2(void) {
+  (void)(StrongSmall){ 1, 0 };
+}
+
+// CHECK: define void @test_volatile_variable_reference(
+// CHECK: %[[AGG_TMP_ENSURED:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
+// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[AGG_TMP_ENSURED]] to i8**
+// CHECK: call void @__copy_constructor_8_8_tv0w32_sv8(i8** %[[V1]], i8** %{{.*}})
+// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[AGG_TMP_ENSURED]] to i8**
+// CHECK: call void @__destructor_8_s8(i8** %[[V3]])
+
+void test_volatile_variable_reference(volatile StrongSmall *a) {
+  (void)*a;
+}
+
 #endif /* USESTRUCT */
Index: lib/CodeGen/CGExprAgg.cpp
===
--- lib/CodeGen/CGExprAgg.cpp
+++ lib/CodeGen/CGExprAgg.cpp
@@ -245,7 +245,7 @@
 const Expr *E, llvm::function_ref EmitCall) {
   QualType RetTy = E->getType();
   bool RequiresDestruction =
-  Dest.isIgnored() &&
+  !Dest.isExternallyDestructed() &&
   RetTy.isDestructedType() == QualType::DK_nontrivial_c_struct;
 
   // If it makes no observable difference, save a memcpy + temporary.
@@ -656,6 +656,16 @@
   }
 
   AggValueSlot Slot = EnsureSlot(E->getType());
+
+  // Push a destructor cleanup if this is a non-trivial C struct. A compound
+  // literal object that doesn't have a file scope has automatic
+  // storage duration.
+  if (!Dest.isExternallyDestructed() &&
+  E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct) {
+CGF.pushDestroy(QualType::DK_nontrivial_c_struct, Slot.getAddress(),
+E->getType());
+Dest.setExternallyDestructed();
+  }
   CGF.EmitAggExpr(E->getInitializer(), Slot);
 }
 
@@ -792,6 +802,12 @@
 // into existence.
 if (E->getSubExpr()->getType().isVolatileQualified()) {
   EnsureDest(E->getType());
+  if (!Dest.isExternallyDestructed() &&
+  E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct) {
+CGF.pushDestroy(QualType::DK_nontrivial_c_struct, Dest.getAddress(),
+E->getType());
+Dest.setExternallyDestructed();
+  }
   return Visit(E->getSubExpr());
 }
 
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -4093,6 +4093,12 @@
   EmitAnyExprToMem(InitExpr, DeclPtr, E->getType().getQualifiers(),
/*Init*/ true);
 
+  // Push a destructor cleanup if this is a non-trivial C struct. A compound
+  // literal object that doesn't have a file scope has automatic
+  // storage duration.
+  if (E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct)
+pushDestroy(QualType::DK_nontrivial_c_struct, DeclPtr, E->getType());
+
   return Result;
 }
 
@@ -4574,6 +4580,10 @@
 LValue CodeGenFunction::EmitCallExprLValue(const CallExpr *E) {
   RValue 

[PATCH] D63753: [Sema] Instead of rejecting C unions with non-trivial fields, detect attempts to destruct/initialize/copy them.

2019-07-09 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 208861.
ahatanak marked 2 inline comments as done.
ahatanak added a comment.

Add a bit to `RecordDeclBitfields` that indicates whether the record has a 
non-trivial C union member.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63753

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclBase.h
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/Type.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenObjC/Inputs/strong_in_union.h
  test/CodeGenObjC/strong-in-c-struct.m
  test/PCH/non-trivial-c-union.m
  test/SemaObjC/arc-decls.m
  test/SemaObjC/non-trivial-c-union.m

Index: test/SemaObjC/non-trivial-c-union.m
===
--- /dev/null
+++ test/SemaObjC/non-trivial-c-union.m
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -fobjc-runtime-has-weak -verify %s
+
+typedef union { // expected-note 8 {{'U0' has subobjects that are non-trivial to default-initialize}} expected-note 36 {{'U0' has subobjects that are non-trivial to destruct}} expected-note 26 {{'U0' has subobjects that are non-trivial to copy}}
+  id f0; // expected-note 8 {{f0 has type '__strong id' that is non-trivial to default-initialize}} expected-note 36 {{f0 has type '__strong id' that is non-trivial to destruct}} expected-note 26 {{f0 has type '__strong id' that is non-trivial to copy}}
+  __weak id f1; // expected-note 8 {{f1 has type '__weak id' that is non-trivial to default-initialize}} expected-note 36 {{f1 has type '__weak id' that is non-trivial to destruct}} expected-note 26 {{f1 has type '__weak id' that is non-trivial to copy}}
+} U0;
+
+typedef struct {
+  U0 f0;
+  id f1;
+} S0;
+
+id g0;
+U0 ug0;
+U0 ug1 = { .f0 = 0 };
+S0 sg0;
+S0 sg1 = { .f0 = {0}, .f1 = 0 };
+
+U0 foo0(U0); // expected-error {{cannot use type 'U0' for a function/method parameter since it is a union that is non-trivial to destruct}} expected-error {{cannot use type 'U0' for a function/method parameter since it is a union that is non-trivial to copy}} expected-error {{cannot use type 'U0' for function/method return since it is a union that is non-trivial to destruct}} expected-error {{cannot use type 'U0' for function/method return since it is a union that is non-trivial to copy}}
+S0 foo1(S0); // expected-error {{cannot use type 'S0' for a function/method parameter since it contains a union that is non-trivial to destruct}} expected-error {{cannot use type 'S0' for a function/method parameter since it contains a union that is non-trivial to copy}} expected-error {{cannot use type 'S0' for function/method return since it contains a union that is non-trivial to destruct}} expected-error {{cannot use type 'S0' for function/method return since it contains a union that is non-trivial to copy}}
+
+@interface C
+-(U0)m0:(U0)arg; // expected-error {{cannot use type 'U0' for a function/method parameter since it is a union that is non-trivial to destruct}} expected-error {{cannot use type 'U0' for a function/method parameter since it is a union that is non-trivial to copy}} expected-error {{cannot use type 'U0' for function/method return since it is a union that is non-trivial to destruct}} expected-error {{cannot use type 'U0' for function/method return since it is a union that is non-trivial to copy}}
+-(S0)m1:(S0)arg; // expected-error {{cannot use type 'S0' for a function/method parameter since it contains a union that is non-trivial to destruct}} expected-error {{cannot use type 'S0' for a function/method parameter since it contains a union that is non-trivial to copy}} expected-error {{cannot use type 'S0' for function/method return since it contains a union that is non-trivial to destruct}} expected-error {{cannot use type 'S0' for function/method return since it contains a union that is non-trivial to copy}}
+@end
+
+void testBlockFunction(void) {
+  (void)^(U0 a){ return ug0; }; // expected-error {{cannot use type 'U0' for a function/method parameter since it is a union that is non-trivial to destruct}} expected-error {{cannot use type 'U0' for a function/method parameter since it is a union that is non-trivial to copy}} expected-error {{cannot use type 'U0' for function/method return since it is a union that is non-trivial to destruct}} expected-error {{cannot use type 'U0' for function/method return since it is a union that is non-trivial to copy}}
+  (void)^(S0 a){ return sg0; }; // expected-error {{cannot use type 'S0' for a function/method parameter since it contains a union that is non-trivial to destruct}} expected-error {{cannot use type 'S0' for a function/method parameter since it contains a union that is non-trivial to copy}} expected-error {{cannot use type 'S0' for 

[PATCH] D64458: add -fthinlto-index= option to clang-cl

2019-07-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In D64458#1577435 , @pcc wrote:

> Do we really need to support clang-cl syntax here? Can't the user of 
> -fthinlto-index= use the regular clang driver?


I think it depends on how many compiler flags we have to pass to backend 
compilation actions. I don't have a good sense of how many of those actually 
matter. Some flags affect the object file and are not encoded in bitcode, like 
-ffunction-sections. It's potentially onerous for a build system to have to 
work out for itself that `cl -O2` implicitly enables `-Gy`, which is the MSVC 
spelling of `-ffunction-sections`, so therefore we need this other set of 
backend action flags. It seems nicer to for the build system to just take the 
first stage command line and re-run it with a new input and this new flag.

If we want to make the behavior consistent, I would say we should port this new 
-x ir behavior over to clang so it's the same as clang-cl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64458



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


r365590 - [analyzer] CastValueChecker: Remove a dump()

2019-07-09 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Tue Jul  9 17:50:01 2019
New Revision: 365590

URL: http://llvm.org/viewvc/llvm-project?rev=365590=rev
Log:
[analyzer] CastValueChecker: Remove a dump()

Summary: Fix a nit.

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=365590=365589=365590=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp Tue Jul  9 
17:50:01 2019
@@ -163,7 +163,6 @@ bool CastValueChecker::evalCall(const Ca
   if (!Check)
 return false;
 
-  Call.getOriginExpr()->dump();
   const auto *CE = cast(Call.getOriginExpr());
   if (!CE)
 return false;


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


[PATCH] D64380: Add 'require_designated_init' and 'required' attribute to clang

2019-07-09 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman marked 2 inline comments as done.
emmettneyman added inline comments.



Comment at: clang/test/SemaCXX/attr-designated-init-required.cpp:3
+
+#define ATTR [[clang::designated_init_required]]
+

compnerd wrote:
> Why the macro?
I modeled this file after 
`test/SemaCXX/attr-require-constant-initialization.cpp` where a macro is 
defined at the top. I assume just to keep things neat.



Comment at: clang/test/SemaCXX/attr-require-designated-init.cpp:3
+
+#define ATTR [[clang::require_designated_init]]
+

compnerd wrote:
> Why the macro?
See above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64380



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


[PATCH] D64458: add -fthinlto-index= option to clang-cl

2019-07-09 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

Do we really need to support clang-cl syntax here? Can't the user of 
-fthinlto-index= use the regular clang driver?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64458



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


[PATCH] D64380: Add 'require_designated_init' and 'required' attribute to clang

2019-07-09 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman added a comment.

In D64380#1577350 , @compnerd wrote:

> I don't see any cases where `[[clang::required]]` is tested, am I missing 
> something?


I renamed the attribute at your suggestion. It's now called 
`[[clang::designated_init_required]`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64380



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


[PATCH] D64458: add -fthinlto-index= option to clang-cl

2019-07-09 Thread Bob Haarman via Phabricator via cfe-commits
inglorion added a comment.

This is similar to r254927 for the clang driver, and reuses the tests from that 
commit for the backend part. On the frontend, it differs in that clang-cl does 
not support -x (per the comment in clang/lib/Driver/Driver.cpp line 2068: "// 
No driver mode exposes -x and /TC or /TP; we don't support mixing them.") 
Instead of requiring -x ir, the behavior added to clang-cl here is to expect 
that what would be detected as a native object file based on file extension is 
really a bitcode file. If it isn't, the backend will cause us to say "error: 
Invalid bitcode signature", which I think is adequate as a diagnostic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64458



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


[PATCH] D64317: [Driver] Add float-divide-by-zero back to supported sanitizers after D63793/rC365272

2019-07-09 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365587: [Driver] Add float-divide-by-zero back to supported 
sanitizers after… (authored by MaskRay, committed by ).

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64317

Files:
  cfe/trunk/include/clang/Basic/Sanitizers.h
  cfe/trunk/lib/Driver/SanitizerArgs.cpp
  cfe/trunk/lib/Driver/ToolChain.cpp
  cfe/trunk/test/Driver/fsanitize-blacklist.c
  cfe/trunk/test/Driver/fsanitize-coverage.c
  cfe/trunk/test/Driver/fsanitize.c
  cfe/trunk/test/Driver/sanitizer-ld.c
  cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp

Index: cfe/trunk/include/clang/Basic/Sanitizers.h
===
--- cfe/trunk/include/clang/Basic/Sanitizers.h
+++ cfe/trunk/include/clang/Basic/Sanitizers.h
@@ -185,7 +185,7 @@
 inline SanitizerMask getPPTransparentSanitizers() {
   return SanitizerKind::CFI | SanitizerKind::Integer |
  SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
- SanitizerKind::Undefined;
+ SanitizerKind::Undefined | SanitizerKind::FloatDivideByZero;
 }
 
 } // namespace clang
Index: cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp
===
--- cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp
+++ cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp
@@ -29,7 +29,7 @@
 // RUN: ls %t.2 | count 2
 //
 // Next, build with sanitization, and check that a new module isn't built.
-// RUN: %clang_cc1 -fsanitize=cfi-vcall,unsigned-integer-overflow,nullability-arg,null -fmodules \
+// RUN: %clang_cc1 -fsanitize=cfi-vcall,float-divide-by-zero,unsigned-integer-overflow,nullability-arg,null -fmodules \
 // RUN:   -fmodules-cache-path=%t.2 \
 // RUN:   -fmodule-map-file=%S/Inputs/check-for-sanitizer-feature/map \
 // RUN:   -I %S/Inputs/check-for-sanitizer-feature -verify %s
Index: cfe/trunk/test/Driver/fsanitize-coverage.c
===
--- cfe/trunk/test/Driver/fsanitize-coverage.c
+++ cfe/trunk/test/Driver/fsanitize-coverage.c
@@ -14,6 +14,7 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=bool -fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=dataflow -fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
+// RUN: %clang -target %itanium_abi_triple -fsanitize=float-divide-by-zero -fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
 // RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
 // CHECK-SANITIZE-COVERAGE-FUNC: fsanitize-coverage-type=1
 
Index: cfe/trunk/test/Driver/fsanitize-blacklist.c
===
--- cfe/trunk/test/Driver/fsanitize-blacklist.c
+++ cfe/trunk/test/Driver/fsanitize-blacklist.c
@@ -30,6 +30,7 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=nullability -resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT-UBSAN-BLACKLIST --implicit-check-not=fdepfile-entry --implicit-check-not=-fsanitize-blacklist=
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT-UBSAN-BLACKLIST --implicit-check-not=fdepfile-entry --implicit-check-not=-fsanitize-blacklist=
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=alignment -resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT-UBSAN-BLACKLIST --implicit-check-not=fdepfile-entry --implicit-check-not=-fsanitize-blacklist=
+// RUN: %clang -target %itanium_abi_triple -fsanitize=float-divide-by-zero -resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT-UBSAN-BLACKLIST --implicit-check-not=fdepfile-entry --implicit-check-not=-fsanitize-blacklist=
 // CHECK-DEFAULT-UBSAN-BLACKLIST: -fsanitize-blacklist={{.*}}ubsan_blacklist.txt
 
 // Check that combining ubsan and another sanitizer results in both blacklists being used.
Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -840,3 +840,17 @@
 // CHECK-POINTER-SUB-NEEDS-ADDRESS: error: invalid argument '-fsanitize=pointer-subtract' only allowed with '-fsanitize=address'
 // CHECK-NO-POINTER-SUB-NOT: {{.*}}asan-detect-invalid-pointer{{.*}}
 // 

r365587 - [Driver] Add float-divide-by-zero back to supported sanitizers after D63793/rC365272

2019-07-09 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Tue Jul  9 17:30:02 2019
New Revision: 365587

URL: http://llvm.org/viewvc/llvm-project?rev=365587=rev
Log:
[Driver] Add float-divide-by-zero back to supported sanitizers after 
D63793/rC365272

D63793 removed float-divide-by-zero from the "undefined" set but it
failed to add it to getSupportedSanitizers(), thus the sanitizer is
rejected by the driver:

clang-9: error: unsupported option '-fsanitize=float-divide-by-zero' for 
target 'x86_64-unknown-linux-gnu'

Also, add SanitizerMask::FloatDivideByZero to a few other masks to make 
-fsanitize-trap, -fsanitize-recover, -fsanitize-minimal-runtime and 
-fsanitize-coverage work.

Reviewed By: rsmith, vitalybuka

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

Modified:
cfe/trunk/include/clang/Basic/Sanitizers.h
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/test/Driver/fsanitize-blacklist.c
cfe/trunk/test/Driver/fsanitize-coverage.c
cfe/trunk/test/Driver/fsanitize.c
cfe/trunk/test/Driver/sanitizer-ld.c
cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp

Modified: cfe/trunk/include/clang/Basic/Sanitizers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.h?rev=365587=365586=365587=diff
==
--- cfe/trunk/include/clang/Basic/Sanitizers.h (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.h Tue Jul  9 17:30:02 2019
@@ -185,7 +185,7 @@ SanitizerMask expandSanitizerGroups(Sani
 inline SanitizerMask getPPTransparentSanitizers() {
   return SanitizerKind::CFI | SanitizerKind::Integer |
  SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
- SanitizerKind::Undefined;
+ SanitizerKind::Undefined | SanitizerKind::FloatDivideByZero;
 }
 
 } // namespace clang

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=365587=365586=365587=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue Jul  9 17:30:02 2019
@@ -27,7 +27,7 @@ using namespace llvm::opt;
 static const SanitizerMask NeedsUbsanRt =
 SanitizerKind::Undefined | SanitizerKind::Integer |
 SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
-SanitizerKind::CFI;
+SanitizerKind::CFI | SanitizerKind::FloatDivideByZero;
 static const SanitizerMask NeedsUbsanCxxRt =
 SanitizerKind::Vptr | SanitizerKind::CFI;
 static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr;
@@ -44,10 +44,11 @@ static const SanitizerMask SupportsCover
 SanitizerKind::Undefined | SanitizerKind::Integer |
 SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
 SanitizerKind::DataFlow | SanitizerKind::Fuzzer |
-SanitizerKind::FuzzerNoLink;
+SanitizerKind::FuzzerNoLink | SanitizerKind::FloatDivideByZero;
 static const SanitizerMask RecoverableByDefault =
 SanitizerKind::Undefined | SanitizerKind::Integer |
-SanitizerKind::ImplicitConversion | SanitizerKind::Nullability;
+SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
+SanitizerKind::FloatDivideByZero;
 static const SanitizerMask Unrecoverable =
 SanitizerKind::Unreachable | SanitizerKind::Return;
 static const SanitizerMask AlwaysRecoverable =
@@ -59,7 +60,7 @@ static const SanitizerMask TrappingSuppo
 (SanitizerKind::Undefined & ~SanitizerKind::Vptr) |
 SanitizerKind::UnsignedIntegerOverflow | SanitizerKind::ImplicitConversion 
|
 SanitizerKind::Nullability | SanitizerKind::LocalBounds |
-SanitizerKind::CFI;
+SanitizerKind::CFI | SanitizerKind::FloatDivideByZero;
 static const SanitizerMask TrappingDefault = SanitizerKind::CFI;
 static const SanitizerMask CFIClasses =
 SanitizerKind::CFIVCall | SanitizerKind::CFINVCall |
@@ -125,9 +126,10 @@ static void addDefaultBlacklists(const D
 {"tsan_blacklist.txt", SanitizerKind::Thread},
 {"dfsan_abilist.txt", SanitizerKind::DataFlow},
 {"cfi_blacklist.txt", SanitizerKind::CFI},
-{"ubsan_blacklist.txt", SanitizerKind::Undefined |
-SanitizerKind::Integer |
-SanitizerKind::Nullability}};
+{"ubsan_blacklist.txt",
+ SanitizerKind::Undefined | SanitizerKind::Integer |
+ SanitizerKind::Nullability |
+ SanitizerKind::FloatDivideByZero}};
 
   for (auto BL : Blacklists) {
 if (!(Kinds & BL.Mask))

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=365587=365586=365587=diff

[PATCH] D64458: add -fthinlto-index= option to clang-cl

2019-07-09 Thread Bob Haarman via Phabricator via cfe-commits
inglorion created this revision.
inglorion added reviewers: tejohnson, pcc, rnk.
Herald added subscribers: arphaman, dexonsmith, steven_wu, mehdi_amini.
Herald added a project: clang.

This adds a -fthinlto-index= option to clang-cl, which allows it to
be used to drive ThinLTO backend passes. This allows clang-cl to be
used for distributed ThinLTO.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64458

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/cl-thinlto-backend.c


Index: clang/test/Driver/cl-thinlto-backend.c
===
--- /dev/null
+++ clang/test/Driver/cl-thinlto-backend.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cl -c -flto=thin -Fo%t.obj %s
+// RUN: llvm-lto2 run -thinlto-distributed-indexes -o %t.exe %t.obj
+
+// -fthinlto_index should be passed to cc1
+// RUN: %clang_cl -### -c -fthinlto-index=%t.thinlto.bc -Fo%t1.obj \
+// RUN: %t.obj 2>&1 | FileCheck %s
+
+// CHECK: -fthinlto-index=
+// CHECK: "-x" "ir"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2119,6 +2119,13 @@
   Diag(clang::diag::warn_drv_treating_input_as_cxx)
   << getTypeName(OldTy) << getTypeName(Ty);
   }
+
+  // If the driver is invoked as clang-cl with -thinlto-index=,
+  // extensions that normally identify native object files actually
+  // identify LLVM bitcode files.
+  if (IsCLMode() && Ty == types::TY_Object &&
+  Args.hasArgNoClaim(options::OPT_fthinlto_index_EQ))
+Ty = types::TY_LLVM_BC;
 }
 
 // -ObjC and -ObjC++ override the default language, but only for 
"source
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1270,7 +1270,7 @@
"of 0 means the number of threads will be derived from "
"the number of CPUs detected)">;
 def fthinlto_index_EQ : Joined<["-"], "fthinlto-index=">,
-  Flags<[CC1Option]>, Group,
+  Flags<[CoreOption, CC1Option]>, Group,
   HelpText<"Perform ThinLTO importing using provided function summary index">;
 def fmacro_backtrace_limit_EQ : Joined<["-"], "fmacro-backtrace-limit=">,
 Group, Flags<[DriverOption, 
CoreOption]>;


Index: clang/test/Driver/cl-thinlto-backend.c
===
--- /dev/null
+++ clang/test/Driver/cl-thinlto-backend.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cl -c -flto=thin -Fo%t.obj %s
+// RUN: llvm-lto2 run -thinlto-distributed-indexes -o %t.exe %t.obj
+
+// -fthinlto_index should be passed to cc1
+// RUN: %clang_cl -### -c -fthinlto-index=%t.thinlto.bc -Fo%t1.obj \
+// RUN: %t.obj 2>&1 | FileCheck %s
+
+// CHECK: -fthinlto-index=
+// CHECK: "-x" "ir"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2119,6 +2119,13 @@
   Diag(clang::diag::warn_drv_treating_input_as_cxx)
   << getTypeName(OldTy) << getTypeName(Ty);
   }
+
+  // If the driver is invoked as clang-cl with -thinlto-index=,
+  // extensions that normally identify native object files actually
+  // identify LLVM bitcode files.
+  if (IsCLMode() && Ty == types::TY_Object &&
+  Args.hasArgNoClaim(options::OPT_fthinlto_index_EQ))
+Ty = types::TY_LLVM_BC;
 }
 
 // -ObjC and -ObjC++ override the default language, but only for "source
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1270,7 +1270,7 @@
"of 0 means the number of threads will be derived from "
"the number of CPUs detected)">;
 def fthinlto_index_EQ : Joined<["-"], "fthinlto-index=">,
-  Flags<[CC1Option]>, Group,
+  Flags<[CoreOption, CC1Option]>, Group,
   HelpText<"Perform ThinLTO importing using provided function summary index">;
 def fmacro_backtrace_limit_EQ : Joined<["-"], "fmacro-backtrace-limit=">,
 Group, Flags<[DriverOption, CoreOption]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r365585 - [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Tue Jul  9 17:20:03 2019
New Revision: 365585

URL: http://llvm.org/viewvc/llvm-project?rev=365585=rev
Log:
[analyzer] CastValueChecker: Model casts

Summary:
It models the LLVM casts:
- `cast<>`
- `dyn_cast<>`
- `cast_or_null<>`
- `dyn_cast_or_null<>`

It has a very basic support without checking the `classof()` function.

(It reapplies the reverted 'llvm-svn: 365582' patch with proper test file.)

Reviewed By: NoQ

Tags: #clang

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

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
cfe/trunk/test/Analysis/cast-value.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
cfe/trunk/test/Analysis/return-value-guaranteed.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=365585=365584=365585=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Tue Jul  9 
17:20:03 2019
@@ -100,6 +100,7 @@ def LLVMAlpha : Package<"llvm">, ParentP
 // intended for API modeling that is not controlled by the target triple.
 def APIModeling : Package<"apiModeling">, Hidden;
 def GoogleAPIModeling : Package<"google">, ParentPackage, Hidden;
+def LLVMAPIModeling : Package<"llvm">, ParentPackage, Hidden;
 
 def Debug : Package<"debug">, Hidden;
 
@@ -274,10 +275,6 @@ def NullableReturnedFromNonnullChecker :
 
 let ParentPackage = APIModeling in {
 
-def ReturnValueChecker : Checker<"ReturnValue">,
-  HelpText<"Model the guaranteed boolean return value of function calls">,
-  Documentation;
-
 def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
   HelpText<"Improve modeling of the C standard library functions">,
   Documentation;
@@ -1109,6 +1106,18 @@ def LLVMConventionsChecker : Checker<"Co
 
 } // end "llvm"
 
+let ParentPackage = LLVMAPIModeling in {
+
+def CastValueChecker : Checker<"CastValue">,
+  HelpText<"Model implementation of custom RTTIs">,
+  Documentation;
+
+def ReturnValueChecker : Checker<"ReturnValue">,
+  HelpText<"Model the guaranteed boolean return value of function calls">,
+  Documentation;
+
+} // end "apiModeling.llvm"
+
 
//===--===//
 // Checkers modeling Google APIs.
 
//===--===//

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h?rev=365585=365584=365585=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
Tue Jul  9 17:20:03 2019
@@ -247,6 +247,17 @@ public:
 IsPrunable);
   }
 
+  /// A shorthand version of getNoteTag that accepts a plain note.
+  ///
+  /// @param Note The note.
+  /// @param IsPrunable Whether the note is prunable. It allows BugReporter
+  ///to omit the note from the report if it would make the displayed
+  ///bug path significantly shorter.
+  const NoteTag *getNoteTag(StringRef Note, bool IsPrunable = false) {
+return getNoteTag(
+[Note](BugReporterContext &, BugReport &) { return Note; }, 
IsPrunable);
+  }
+
   /// Returns the word that should be used to refer to the declaration
   /// in the report.
   StringRef getDeclDescription(const Decl *D);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=365585=365584=365585=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Tue Jul  9 17:20:03 
2019
@@ -16,6 +16,7 @@ add_clang_library(clangStaticAnalyzerChe
   CallAndMessageChecker.cpp
   CastSizeChecker.cpp
   CastToStructChecker.cpp
+  CastValueChecker.cpp
   CheckObjCDealloc.cpp
   CheckObjCInstMethSignature.cpp
   CheckSecuritySyntaxOnly.cpp

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=365585=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (added)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp 

[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 208847.
Charusso added a comment.

- Add the llvm namespace to the test file.


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

https://reviews.llvm.org/D64374

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/test/Analysis/cast-value.cpp
  clang/test/Analysis/return-value-guaranteed.cpp

Index: clang/test/Analysis/return-value-guaranteed.cpp
===
--- clang/test/Analysis/return-value-guaranteed.cpp
+++ clang/test/Analysis/return-value-guaranteed.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 \
-// RUN:  -analyzer-checker=core,apiModeling.ReturnValue \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.ReturnValue \
 // RUN:  -analyzer-output=text -verify=class %s
 
 struct Foo { int Field; };
Index: clang/test/Analysis/cast-value.cpp
===
--- /dev/null
+++ clang/test/Analysis/cast-value.cpp
@@ -0,0 +1,137 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN:  -verify=logic %s
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue \
+// RUN:  -analyzer-output=text -verify %s
+
+void clang_analyzer_numTimesReached();
+void clang_analyzer_warnIfReached();
+void clang_analyzer_eval(bool);
+
+namespace llvm {
+template 
+const X *cast(Y Value);
+
+template 
+const X *dyn_cast(Y Value);
+
+template 
+const X *cast_or_null(Y Value);
+
+template 
+const X *dyn_cast_or_null(Y Value);
+} // namespace llvm
+
+using namespace llvm;
+
+class Shape {};
+class Triangle : public Shape {};
+class Circle : public Shape {};
+
+namespace test_cast {
+void evalLogic(const Shape *S) {
+  const Circle *C = cast(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{1}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // no-warning
+
+  if (!S)
+clang_analyzer_warnIfReached(); // no-warning
+}
+} // namespace test_cast
+
+namespace test_dyn_cast {
+void evalLogic(const Shape *S) {
+  const Circle *C = dyn_cast(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{2}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // logic-warning {{REACHABLE}}
+
+  if (!S)
+clang_analyzer_warnIfReached(); // no-warning
+}
+} // namespace test_dyn_cast
+
+namespace test_cast_or_null {
+void evalLogic(const Shape *S) {
+  const Circle *C = cast_or_null(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{2}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // no-warning
+
+  if (!S)
+clang_analyzer_eval(!C); // logic-warning {{TRUE}}
+}
+} // namespace test_cast_or_null
+
+namespace test_dyn_cast_or_null {
+void evalLogic(const Shape *S) {
+  const Circle *C = dyn_cast_or_null(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{3}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // logic-warning {{REACHABLE}}
+
+  if (!S)
+clang_analyzer_eval(!C); // logic-warning {{TRUE}}
+}
+
+void evalNonNullParamNonNullReturn(const Shape *S) {
+  const auto *C = dyn_cast_or_null(S);
+  // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' succeeds}}
+  // expected-note@-2 {{Assuming pointer value is null}}
+  // expected-note@-3 {{'C' initialized here}}
+
+  (void)(1 / !(bool)C);
+  // expected-note@-1 {{'C' is non-null}}
+  // expected-note@-2 {{Division by zero}}
+  // expected-warning@-3 {{Division by zero}}
+  // logic-warning@-4 {{Division by zero}}
+}
+
+void evalNonNullParamNullReturn(const Shape *S) {
+  const auto *C = dyn_cast_or_null(S);
+  // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' fails}}
+  // expected-note@-2 {{Assuming pointer value is null}}
+
+  if (const auto *T = dyn_cast_or_null(S)) {
+// expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Triangle' succeeds}}
+// expected-note@-2 {{'T' initialized here}}
+// expected-note@-3 {{'T' is non-null}}
+// expected-note@-4 {{Taking true branch}}
+
+(void)(1 / !T);
+// expected-note@-1 {{'T' is non-null}}
+// expected-note@-2 {{Division by zero}}
+// expected-warning@-3 {{Division by zero}}
+// logic-warning@-4 {{Division by zero}}
+  }
+}
+
+void evalNullParamNullReturn(const Shape *S) {
+  const auto *C = dyn_cast_or_null(S);
+  // expected-note@-1 {{Assuming null pointer is passed into cast}}
+  // expected-note@-2 {{'C' initialized to a null pointer value}}
+

[PATCH] D64380: Add 'require_designated_init' and 'required' attribute to clang

2019-07-09 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

I don't see any cases where `[[clang::required]]` is tested, am I missing 
something?




Comment at: clang/test/SemaCXX/attr-designated-init-required.cpp:3
+
+#define ATTR [[clang::designated_init_required]]
+

Why the macro?



Comment at: clang/test/SemaCXX/attr-require-designated-init.cpp:3
+
+#define ATTR [[clang::require_designated_init]]
+

Why the macro?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64380



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


[PATCH] D58418: [clang][DirectoryWatcher] Upstream DirectoryWatcher

2019-07-09 Thread Jan Korous via Phabricator via cfe-commits
jkorous added a comment.

Thanks for the revert.

There's actually one more problem - seems like ninja doesn't like the generated 
build.ninja file on Linux.

  ninja: error: build.ninja:52390: bad $-escape (literal $ must be written as 
$$)

http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/13617/steps/build-stage1-compiler/logs/stdio


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58418



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


[PATCH] D64257: [clangd] Added highlighting for class and enum types

2019-07-09 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

@jvikstrom out of curiosity, are you testing these patches against a 
client-side implementation of semantic highlighting? If so, which one?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64257



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


[PATCH] D64380: Add 'require_designated_init' and 'required' attribute to clang

2019-07-09 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 208842.
emmettneyman added a comment.

slight change to specification reference format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64380

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCXX/attr-designated-init-required.cpp
  clang/test/SemaCXX/attr-require-designated-init.cpp

Index: clang/test/SemaCXX/attr-require-designated-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/attr-require-designated-init.cpp
@@ -0,0 +1,104 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#define ATTR [[clang::require_designated_init]]
+
+// The require_designated_init attribute only applies to types. It will
+// generate a warning when attached to variables, functions, arrays, etc.
+int ATTR x;// expected-error{{'require_designated_init' attribute cannot be applied to types}}
+void ATTR fun(int x) { // expected-error{{'require_designated_init' attribute cannot be applied to types}}
+  return;
+}
+int ATTR arr[10]; // expected-error{{'require_designated_init' attribute cannot be applied to types}}
+
+// Struct with one field with require_designated_init attribute
+struct ATTR Foo { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int a;
+};
+
+// The following are invalid ways of initializing instances of this struct.
+Foo f1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Foo f2{1};// expected-error{{variable declaration does not use designated initializer syntax}}
+Foo f3 = {1}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this struct.
+Foo f4{};
+Foo f5 = {};
+Foo f6{.a = 1};
+Foo f7 = {.a = 1};
+
+// Struct with multiple fields wth require_designated_init attribute
+struct ATTR Bar { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int b;
+  int c;
+};
+
+// The following are invalid ways of initializing instances of this struct.
+Bar b1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b2{1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b3 = {1, 2};  // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b4{.b = 1, 2};// expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b5 = {.b = 1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this struct.
+Bar b6{};
+Bar b7 = {};
+Bar b8{.b = 1};
+Bar b9 = {.b = 1};
+Bar b10{.b = 1, .c = 2};
+Bar b11 = {.b = 1, .c = 2};
+Bar b12 = {.c = 2, .b = 1};
+
+// Struct without require_designated_init attribute
+struct Baz {
+  int d;
+  int e;
+};
+
+// The following are all valid ways of initializing instances of this struct.
+Baz z1;
+Baz z2{};
+Baz z3 = {};
+Baz z4{1, 2};
+Baz z5 = {1, 2};
+Baz z6{.d = 1, .e = 2};
+Baz z7 = {.d = 1, .e = 2};
+Baz z8{1};
+Baz z9 = {1};
+Baz z10{.d = 1, 2};
+Baz z11 = {.d = 1, 2};
+
+// The require_designated_init attribute can also be attached to unions.
+union ATTR Uni { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int x;
+  int y;
+};
+
+// The following are invalid ways of initializing instances of this union.
+Uni u1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Uni u2{1};// expected-error{{variable declaration does not use designated initializer syntax}}
+Uni u3 = {1}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this union.
+Uni u4{};
+Uni u5 = {};
+Uni u6{.x = 1};
+Uni u7 = {.x = 1};
+
+// The require_designated_init attribute can also be attached to classes.
+class ATTR Cla { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+public:
+  int x;
+  int y;
+};
+
+// The following are invalid ways of initializing instances of this class.
+Cla c1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c2{1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c3 = {1, 2};  // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c4{.x = 1, 2};// expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c5 = {.x = 1, 2}; // 

[PATCH] D64380: Add 'require_designated_init' and 'required' attribute to clang

2019-07-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

C++20 designated initializers don't permit mixing designated fields with 
non-designated ones, so some of the examples here are invalid. However, I think 
we should be looking for an attribute design that works well in both C and C++, 
and with the various Clang extensions that permit the full generality of C 
designated initializers in other language modes. I also think this patch is 
combining multiple features that would be useful to expose separately. To that 
end, I think something like this might make sense:

- An attribute that can be applied to either a field or to a struct that 
requires a designator to be used on any initializer for that field (and for a 
struct, is equivalent to specifying the attribute on all fields)
- An attribute that can be applied to either a field or to a struct that 
requires an explicit initializer to be used for that field, for both aggregate 
initialization and constructor mem-initializer lists (and for a struct, is 
equivalent to specifying the attribute on all fields with no default member 
initializers)

Maybe `requires_designator` and `requires_init` or similar?

And I think these attributes should be made available in both C++11 attribute 
syntax and GNU attribute syntax. Inventing a C++-only extension to improve 
support for designated initializers doesn't seem like the right choice to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64380



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


r365584 - Revert "[analyzer] CastValueChecker: Model casts"

2019-07-09 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Tue Jul  9 16:47:09 2019
New Revision: 365584

URL: http://llvm.org/viewvc/llvm-project?rev=365584=rev
Log:
Revert "[analyzer] CastValueChecker: Model casts"

This reverts commit 27cf6664437efd640bb6db5594bafcce68fa2854.

Removed:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
cfe/trunk/test/Analysis/cast-value.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
cfe/trunk/test/Analysis/return-value-guaranteed.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=365584=365583=365584=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Tue Jul  9 
16:47:09 2019
@@ -100,7 +100,6 @@ def LLVMAlpha : Package<"llvm">, ParentP
 // intended for API modeling that is not controlled by the target triple.
 def APIModeling : Package<"apiModeling">, Hidden;
 def GoogleAPIModeling : Package<"google">, ParentPackage, Hidden;
-def LLVMAPIModeling : Package<"llvm">, ParentPackage, Hidden;
 
 def Debug : Package<"debug">, Hidden;
 
@@ -275,6 +274,10 @@ def NullableReturnedFromNonnullChecker :
 
 let ParentPackage = APIModeling in {
 
+def ReturnValueChecker : Checker<"ReturnValue">,
+  HelpText<"Model the guaranteed boolean return value of function calls">,
+  Documentation;
+
 def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
   HelpText<"Improve modeling of the C standard library functions">,
   Documentation;
@@ -1106,18 +1109,6 @@ def LLVMConventionsChecker : Checker<"Co
 
 } // end "llvm"
 
-let ParentPackage = LLVMAPIModeling in {
-
-def CastValueChecker : Checker<"CastValue">,
-  HelpText<"Model implementation of custom RTTIs">,
-  Documentation;
-
-def ReturnValueChecker : Checker<"ReturnValue">,
-  HelpText<"Model the guaranteed boolean return value of function calls">,
-  Documentation;
-
-} // end "apiModeling.llvm"
-
 
//===--===//
 // Checkers modeling Google APIs.
 
//===--===//

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h?rev=365584=365583=365584=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
Tue Jul  9 16:47:09 2019
@@ -247,17 +247,6 @@ public:
 IsPrunable);
   }
 
-  /// A shorthand version of getNoteTag that accepts a plain note.
-  ///
-  /// @param Note The note.
-  /// @param IsPrunable Whether the note is prunable. It allows BugReporter
-  ///to omit the note from the report if it would make the displayed
-  ///bug path significantly shorter.
-  const NoteTag *getNoteTag(StringRef Note, bool IsPrunable = false) {
-return getNoteTag(
-[Note](BugReporterContext &, BugReport &) { return Note; }, 
IsPrunable);
-  }
-
   /// Returns the word that should be used to refer to the declaration
   /// in the report.
   StringRef getDeclDescription(const Decl *D);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=365584=365583=365584=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Tue Jul  9 16:47:09 
2019
@@ -16,7 +16,6 @@ add_clang_library(clangStaticAnalyzerChe
   CallAndMessageChecker.cpp
   CastSizeChecker.cpp
   CastToStructChecker.cpp
-  CastValueChecker.cpp
   CheckObjCDealloc.cpp
   CheckObjCInstMethSignature.cpp
   CheckSecuritySyntaxOnly.cpp

Removed: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=365583=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (removed)
@@ -1,190 +0,0 @@
-//===- CastValueChecker - Model implementation of custom RTTIs --*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.

[PATCH] D64380: Add 'require_designated_init' and 'required' attribute to clang

2019-07-09 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 208840.
emmettneyman marked an inline comment as done.
emmettneyman added a comment.

Remove cppreference link, add reference to C++ spec.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64380

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCXX/attr-designated-init-required.cpp
  clang/test/SemaCXX/attr-require-designated-init.cpp

Index: clang/test/SemaCXX/attr-require-designated-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/attr-require-designated-init.cpp
@@ -0,0 +1,104 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#define ATTR [[clang::require_designated_init]]
+
+// The require_designated_init attribute only applies to types. It will
+// generate a warning when attached to variables, functions, arrays, etc.
+int ATTR x;// expected-error{{'require_designated_init' attribute cannot be applied to types}}
+void ATTR fun(int x) { // expected-error{{'require_designated_init' attribute cannot be applied to types}}
+  return;
+}
+int ATTR arr[10]; // expected-error{{'require_designated_init' attribute cannot be applied to types}}
+
+// Struct with one field with require_designated_init attribute
+struct ATTR Foo { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int a;
+};
+
+// The following are invalid ways of initializing instances of this struct.
+Foo f1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Foo f2{1};// expected-error{{variable declaration does not use designated initializer syntax}}
+Foo f3 = {1}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this struct.
+Foo f4{};
+Foo f5 = {};
+Foo f6{.a = 1};
+Foo f7 = {.a = 1};
+
+// Struct with multiple fields wth require_designated_init attribute
+struct ATTR Bar { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int b;
+  int c;
+};
+
+// The following are invalid ways of initializing instances of this struct.
+Bar b1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b2{1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b3 = {1, 2};  // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b4{.b = 1, 2};// expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b5 = {.b = 1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this struct.
+Bar b6{};
+Bar b7 = {};
+Bar b8{.b = 1};
+Bar b9 = {.b = 1};
+Bar b10{.b = 1, .c = 2};
+Bar b11 = {.b = 1, .c = 2};
+Bar b12 = {.c = 2, .b = 1};
+
+// Struct without require_designated_init attribute
+struct Baz {
+  int d;
+  int e;
+};
+
+// The following are all valid ways of initializing instances of this struct.
+Baz z1;
+Baz z2{};
+Baz z3 = {};
+Baz z4{1, 2};
+Baz z5 = {1, 2};
+Baz z6{.d = 1, .e = 2};
+Baz z7 = {.d = 1, .e = 2};
+Baz z8{1};
+Baz z9 = {1};
+Baz z10{.d = 1, 2};
+Baz z11 = {.d = 1, 2};
+
+// The require_designated_init attribute can also be attached to unions.
+union ATTR Uni { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int x;
+  int y;
+};
+
+// The following are invalid ways of initializing instances of this union.
+Uni u1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Uni u2{1};// expected-error{{variable declaration does not use designated initializer syntax}}
+Uni u3 = {1}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this union.
+Uni u4{};
+Uni u5 = {};
+Uni u6{.x = 1};
+Uni u7 = {.x = 1};
+
+// The require_designated_init attribute can also be attached to classes.
+class ATTR Cla { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+public:
+  int x;
+  int y;
+};
+
+// The following are invalid ways of initializing instances of this class.
+Cla c1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c2{1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c3 = {1, 2};  // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c4{.x = 1, 2};// expected-error{{variable declaration does not use designated initializer 

[PATCH] D64454: [clang-tidy] Adding static analyzer check to list of clang-tidy checks

2019-07-09 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-apiModeling.StdCLibraryFunctions.rst:4
+clang-analyzer-apiModeling.StdCLibraryFunctions
+==
+

Please adjust length. Same in other files.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-apiModeling.StdCLibraryFunctions.rst:7
+The clang-analyzer-apiModeling.StdCLibraryFunctions check is an alias, please 
see
+`Clang Static Analyzer Available Checkers 
`_
+for more information.

Could documentation refer to specific checker? Same in other files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64454



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


[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365582: [analyzer] CastValueChecker: Model casts (authored 
by Charusso, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64374?vs=208831=208839#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64374

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  cfe/trunk/test/Analysis/cast-value.cpp
  cfe/trunk/test/Analysis/return-value-guaranteed.cpp

Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -247,6 +247,17 @@
 IsPrunable);
   }
 
+  /// A shorthand version of getNoteTag that accepts a plain note.
+  ///
+  /// @param Note The note.
+  /// @param IsPrunable Whether the note is prunable. It allows BugReporter
+  ///to omit the note from the report if it would make the displayed
+  ///bug path significantly shorter.
+  const NoteTag *getNoteTag(StringRef Note, bool IsPrunable = false) {
+return getNoteTag(
+[Note](BugReporterContext &, BugReport &) { return Note; }, IsPrunable);
+  }
+
   /// Returns the word that should be used to refer to the declaration
   /// in the report.
   StringRef getDeclDescription(const Decl *D);
Index: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -100,6 +100,7 @@
 // intended for API modeling that is not controlled by the target triple.
 def APIModeling : Package<"apiModeling">, Hidden;
 def GoogleAPIModeling : Package<"google">, ParentPackage, Hidden;
+def LLVMAPIModeling : Package<"llvm">, ParentPackage, Hidden;
 
 def Debug : Package<"debug">, Hidden;
 
@@ -274,10 +275,6 @@
 
 let ParentPackage = APIModeling in {
 
-def ReturnValueChecker : Checker<"ReturnValue">,
-  HelpText<"Model the guaranteed boolean return value of function calls">,
-  Documentation;
-
 def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
   HelpText<"Improve modeling of the C standard library functions">,
   Documentation;
@@ -1109,6 +1106,18 @@
 
 } // end "llvm"
 
+let ParentPackage = LLVMAPIModeling in {
+
+def CastValueChecker : Checker<"CastValue">,
+  HelpText<"Model implementation of custom RTTIs">,
+  Documentation;
+
+def ReturnValueChecker : Checker<"ReturnValue">,
+  HelpText<"Model the guaranteed boolean return value of function calls">,
+  Documentation;
+
+} // end "apiModeling.llvm"
+
 //===--===//
 // Checkers modeling Google APIs.
 //===--===//
Index: cfe/trunk/test/Analysis/return-value-guaranteed.cpp
===
--- cfe/trunk/test/Analysis/return-value-guaranteed.cpp
+++ cfe/trunk/test/Analysis/return-value-guaranteed.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 \
-// RUN:  -analyzer-checker=core,apiModeling.ReturnValue \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.ReturnValue \
 // RUN:  -analyzer-output=text -verify=class %s
 
 struct Foo { int Field; };
Index: cfe/trunk/test/Analysis/cast-value.cpp
===
--- cfe/trunk/test/Analysis/cast-value.cpp
+++ cfe/trunk/test/Analysis/cast-value.cpp
@@ -0,0 +1,133 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN:  -verify=logic %s
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue \
+// RUN:  -analyzer-output=text -verify %s
+
+void clang_analyzer_numTimesReached();
+void clang_analyzer_warnIfReached();
+void clang_analyzer_eval(bool);
+
+template 
+const X *cast(Y Value);
+
+template 
+const X *dyn_cast(Y Value);
+
+template 
+const X *cast_or_null(Y Value);
+
+template 
+const X *dyn_cast_or_null(Y Value);
+
+class Shape {};
+class Triangle : public Shape {};
+class Circle : public Shape {};
+
+namespace test_cast {
+void evalLogic(const Shape *S) {
+  const Circle *C = cast(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{1}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // no-warning
+
+  if (!S)
+ 

r365582 - [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Tue Jul  9 16:33:23 2019
New Revision: 365582

URL: http://llvm.org/viewvc/llvm-project?rev=365582=rev
Log:
[analyzer] CastValueChecker: Model casts

Summary:
It models the LLVM casts:
- `cast<>`
- `dyn_cast<>`
- `cast_or_null<>`
- `dyn_cast_or_null<>`

It has a very basic support without checking the `classof()` function.

Reviewed By: NoQ

Tags: #clang

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

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
cfe/trunk/test/Analysis/cast-value.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
cfe/trunk/test/Analysis/return-value-guaranteed.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=365582=365581=365582=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Tue Jul  9 
16:33:23 2019
@@ -100,6 +100,7 @@ def LLVMAlpha : Package<"llvm">, ParentP
 // intended for API modeling that is not controlled by the target triple.
 def APIModeling : Package<"apiModeling">, Hidden;
 def GoogleAPIModeling : Package<"google">, ParentPackage, Hidden;
+def LLVMAPIModeling : Package<"llvm">, ParentPackage, Hidden;
 
 def Debug : Package<"debug">, Hidden;
 
@@ -274,10 +275,6 @@ def NullableReturnedFromNonnullChecker :
 
 let ParentPackage = APIModeling in {
 
-def ReturnValueChecker : Checker<"ReturnValue">,
-  HelpText<"Model the guaranteed boolean return value of function calls">,
-  Documentation;
-
 def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
   HelpText<"Improve modeling of the C standard library functions">,
   Documentation;
@@ -1109,6 +1106,18 @@ def LLVMConventionsChecker : Checker<"Co
 
 } // end "llvm"
 
+let ParentPackage = LLVMAPIModeling in {
+
+def CastValueChecker : Checker<"CastValue">,
+  HelpText<"Model implementation of custom RTTIs">,
+  Documentation;
+
+def ReturnValueChecker : Checker<"ReturnValue">,
+  HelpText<"Model the guaranteed boolean return value of function calls">,
+  Documentation;
+
+} // end "apiModeling.llvm"
+
 
//===--===//
 // Checkers modeling Google APIs.
 
//===--===//

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h?rev=365582=365581=365582=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
Tue Jul  9 16:33:23 2019
@@ -247,6 +247,17 @@ public:
 IsPrunable);
   }
 
+  /// A shorthand version of getNoteTag that accepts a plain note.
+  ///
+  /// @param Note The note.
+  /// @param IsPrunable Whether the note is prunable. It allows BugReporter
+  ///to omit the note from the report if it would make the displayed
+  ///bug path significantly shorter.
+  const NoteTag *getNoteTag(StringRef Note, bool IsPrunable = false) {
+return getNoteTag(
+[Note](BugReporterContext &, BugReport &) { return Note; }, 
IsPrunable);
+  }
+
   /// Returns the word that should be used to refer to the declaration
   /// in the report.
   StringRef getDeclDescription(const Decl *D);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=365582=365581=365582=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Tue Jul  9 16:33:23 
2019
@@ -16,6 +16,7 @@ add_clang_library(clangStaticAnalyzerChe
   CallAndMessageChecker.cpp
   CastSizeChecker.cpp
   CastToStructChecker.cpp
+  CastValueChecker.cpp
   CheckObjCDealloc.cpp
   CheckObjCInstMethSignature.cpp
   CheckSecuritySyntaxOnly.cpp

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=365582=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (added)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp Tue Jul  9 
16:33:23 2019
@@ -0,0 +1,190 @@
+//===- CastValueChecker - Model 

[PATCH] D50763: [Parser] Refactor and fix bugs in late-parsing

2019-07-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.
Herald added a project: clang.



Comment at: lib/Parse/ParseCXXInlineMethods.cpp:266
+public:
+  UseCachedTokensRAII(Parser , CachedTokens , const void *Data)
+  : Self(Self), Data(Data) {

Can you pass ownership of the cached tokens into here instead of passing a 
mutable reference? It makes me uncomfortable for this object to be modifying a 
list of tokens that it doesn't own (by adding an EOF token) -- that's not 
something I'd ever expect a utility with this name to do!


Repository:
  rC Clang

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

https://reviews.llvm.org/D50763



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


[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

Thanks for the review!

In D64374#1577279 , @NoQ wrote:

> That doesn't sound like it's high on our list. That's not too many times. 
> Probably very few false positives come out of it. Also modeling smart 
> pointers is much harder than modeling regular pointers.


Hm, because it is smart, probably it is out of our scope. Thanks for pointing 
it out!


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

https://reviews.llvm.org/D64374



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


[PATCH] D58418: [clang][DirectoryWatcher] Upstream DirectoryWatcher

2019-07-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Reverted in rC365581 .


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58418



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


[PATCH] D58418: [clang][DirectoryWatcher] Upstream DirectoryWatcher

2019-07-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp:420
+std::error_code setTimeRes =
+llvm::sys::fs::setLastAccessAndModificationTime(FD, NewTimePt,
+NewTimePt);

This fails to compile on Windows because file_t is not int there:
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\unittests\DirectoryWatcher\DirectoryWatcherTest.cpp(415):
 error C2440: 'initializing': cannot convert from 'void *' to 'int'
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\unittests\DirectoryWatcher\DirectoryWatcherTest.cpp(415):
 note: There is no context in which this conversion is possible

I have been working on migrating some code over to native file handles to make 
this type of error less likely in the future, but it is not done yet.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58418



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


r365581 - Revert [clang] DirectoryWatcher

2019-07-09 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Jul  9 16:22:01 2019
New Revision: 365581

URL: http://llvm.org/viewvc/llvm-project?rev=365581=rev
Log:
Revert [clang] DirectoryWatcher

This reverts r365574 (git commit 31babea94a3ed38a140540f2252cf043dacec1f7)

Removed:
cfe/trunk/include/clang/DirectoryWatcher/
cfe/trunk/lib/DirectoryWatcher/
cfe/trunk/unittests/DirectoryWatcher/
Modified:
cfe/trunk/lib/CMakeLists.txt
cfe/trunk/unittests/CMakeLists.txt

Modified: cfe/trunk/lib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CMakeLists.txt?rev=365581=365580=365581=diff
==
--- cfe/trunk/lib/CMakeLists.txt (original)
+++ cfe/trunk/lib/CMakeLists.txt Tue Jul  9 16:22:01 2019
@@ -18,7 +18,6 @@ add_subdirectory(Serialization)
 add_subdirectory(Frontend)
 add_subdirectory(FrontendTool)
 add_subdirectory(Tooling)
-add_subdirectory(DirectoryWatcher)
 add_subdirectory(Index)
 if(CLANG_ENABLE_STATIC_ANALYZER)
   add_subdirectory(StaticAnalyzer)

Modified: cfe/trunk/unittests/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/CMakeLists.txt?rev=365581=365580=365581=diff
==
--- cfe/trunk/unittests/CMakeLists.txt (original)
+++ cfe/trunk/unittests/CMakeLists.txt Tue Jul  9 16:22:01 2019
@@ -30,7 +30,6 @@ add_subdirectory(CodeGen)
 if(NOT WIN32 AND CLANG_TOOL_LIBCLANG_BUILD) 
   add_subdirectory(libclang)
 endif()
-add_subdirectory(DirectoryWatcher)
 add_subdirectory(Rename)
 add_subdirectory(Index)
 add_subdirectory(Serialization)


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


[PATCH] D64454: [clang-tidy] Adding static analyzer check to list of clang-tidy checks

2019-07-09 Thread Nathan Huckleberry via Phabricator via cfe-commits
Nathan-Huckleberry added a comment.

The contents of each check page are identical other than the check name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64454



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


[PATCH] D64454: [clang-tidy] Adding static analyzer check to list of clang-tidy checks

2019-07-09 Thread Nathan Huckleberry via Phabricator via cfe-commits
Nathan-Huckleberry created this revision.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware, xazax.hun.
Herald added a project: clang.

Since clang-tidy supports use of the static analyzer there
should be documentation of how to invoke the static analyzer
checks.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64454

Files:
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-apiModeling.StdCLibraryFunctions.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-apiModeling.TrustNonnull.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-apiModeling.google.GTest.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.CallAndMessage.rst
  clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.DivideZero.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.DynamicTypePropagation.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.NonNullParamChecker.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.NonnilStringConstants.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.NullDereference.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.StackAddrEscapeBase.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.StackAddressEscape.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.UndefinedBinaryOperatorResult.rst
  clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.VLASize.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.builtin.BuiltinFunctions.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.builtin.NoReturnFunctions.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.uninitialized.ArraySubscript.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.uninitialized.Assign.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.uninitialized.Branch.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.uninitialized.CapturedBlockVariable.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-core.uninitialized.UndefReturn.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-cplusplus.InnerPointer.rst
  clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-cplusplus.Move.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-cplusplus.NewDelete.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-cplusplus.NewDeleteLeaks.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-cplusplus.SelfAssignment.rst
  clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-cplusplus.SmartPtr.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-deadcode.DeadStores.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-nullability.NullPassedToNonnull.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-nullability.NullReturnedFromNonnull.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-nullability.NullabilityBase.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-nullability.NullableDereferenced.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-nullability.NullablePassedToNonnull.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-nullability.NullableReturnedFromNonnull.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-optin.cplusplus.UninitializedObject.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-optin.cplusplus.VirtualCall.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-optin.mpi.MPI-Checker.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-optin.osx.OSObjectCStyleCast.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-optin.performance.GCDAntipattern.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-optin.performance.Padding.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-optin.portability.UnixAPI.rst
  clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-osx.API.rst
  clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-osx.MIG.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-osx.NSOrCFErrorDerefChecker.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-osx.NumberObjectConversion.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-osx.OSObjectRetainCount.rst
  clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-osx.ObjCProperty.rst
  clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-osx.SecKeychainAPI.rst
  clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-osx.cocoa.AtSync.rst
  
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer-osx.cocoa.AutoreleaseWrite.rst
  

r365579 - [MS] Treat ignored explicit calling conventions as an explicit __cdecl

2019-07-09 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Jul  9 16:17:43 2019
New Revision: 365579

URL: http://llvm.org/viewvc/llvm-project?rev=365579=rev
Log:
[MS] Treat ignored explicit calling conventions as an explicit __cdecl

The CCCR_Ignore action is only used for Microsoft calling conventions,
mainly because MSVC does not warn when a calling convention would be
ignored by the current target. This behavior is actually somewhat
important, since windows.h uses WINAPI (which expands to __stdcall)
widely. This distinction didn't matter much before the introduction of
__vectorcall to x64 and the ability to make that the default calling
convention with /Gv. Now, we can't just ignore __stdcall for x64, we
have to treat it as an explicit __cdecl annotation.

Fixes PR42531

Added:
cfe/trunk/test/CodeGen/calling-conv-ignored.c
Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=365579=365578=365579=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Jul  9 16:17:43 2019
@@ -4655,10 +4655,22 @@ bool Sema::CheckCallingConvAttr(const Pa
   } else {
 A = TI.checkCallingConvention(CC);
   }
-  if (A != TargetInfo::CCCR_OK) {
-if (A == TargetInfo::CCCR_Warning)
-  Diag(Attrs.getLoc(), diag::warn_cconv_ignored)
-  << Attrs << (int)CallingConventionIgnoredReason::ForThisTarget;
+
+  switch (A) {
+  case TargetInfo::CCCR_OK:
+break;
+
+  case TargetInfo::CCCR_Ignore:
+// Treat an ignored convention as if it was an explicit C calling 
convention
+// attribute. For example, __stdcall on Win x64 functions as __cdecl, so
+// that command line flags that change the default convention to
+// __vectorcall don't affect declarations marked __stdcall.
+CC = CC_C;
+break;
+
+  case TargetInfo::CCCR_Warning: {
+Diag(Attrs.getLoc(), diag::warn_cconv_ignored)
+<< Attrs << (int)CallingConventionIgnoredReason::ForThisTarget;
 
 // This convention is not valid for the target. Use the default function or
 // method calling convention.
@@ -4668,6 +4680,8 @@ bool Sema::CheckCallingConvAttr(const Pa
   IsVariadic = FD->isVariadic();
 }
 CC = Context.getDefaultCallingConvention(IsVariadic, IsCXXMethod);
+break;
+  }
   }
 
   Attrs.setProcessingCache((unsigned) CC);

Added: cfe/trunk/test/CodeGen/calling-conv-ignored.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/calling-conv-ignored.c?rev=365579=auto
==
--- cfe/trunk/test/CodeGen/calling-conv-ignored.c (added)
+++ cfe/trunk/test/CodeGen/calling-conv-ignored.c Tue Jul  9 16:17:43 2019
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -o - %s | FileCheck 
%s --check-prefix=X86
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -o - %s | FileCheck 
%s --check-prefix=X64
+// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -o - %s 
-fdefault-calling-conv=vectorcall | FileCheck %s --check-prefix=X86-VEC
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -o - %s 
-fdefault-calling-conv=vectorcall | FileCheck %s --check-prefix=X64-VEC
+
+void foo_default(const char *lpString1, const char *lpString2);
+void __stdcall foo_std(const char *lpString1, const char *lpString2);
+void __fastcall foo_fast(const char *lpString1, const char *lpString2);
+void __vectorcall foo_vector(const char *lpString1, const char *lpString2);
+
+void __cdecl bar() {
+  foo_default(0, 0);
+  foo_std(0, 0);
+  foo_fast(0, 0);
+  foo_vector(0, 0);
+}
+
+// X86-LABEL: define dso_local void @bar()
+// X86:   call void @foo_default(i8* null, i8* null)
+// X86:   call x86_stdcallcc void @"\01_foo_std@8"(i8* null, i8* null)
+// X86:   call x86_fastcallcc void @"\01@foo_fast@8"(i8* inreg null, i8* inreg 
null)
+// X86:   call x86_vectorcallcc void @"\01foo_vector@@8"(i8* inreg null, i8* 
inreg null)
+// X86:   ret void
+
+// X64-LABEL: define dso_local void @bar()
+// X64:   call void @foo_default(i8* null, i8* null)
+// X64:   call void @foo_std(i8* null, i8* null)
+// X64:   call void @foo_fast(i8* null, i8* null)
+// X64:   call x86_vectorcallcc void @"\01foo_vector@@16"(i8* null, i8* null)
+// X64:   ret void
+
+// X86-VEC-LABEL: define dso_local void @bar()
+// X86-VEC:   call x86_vectorcallcc void @"\01foo_default@@8"(i8* inreg null, 
i8* inreg null)
+// X86-VEC:   call x86_stdcallcc void @"\01_foo_std@8"(i8* null, i8* null)
+// X86-VEC:   call x86_fastcallcc void @"\01@foo_fast@8"(i8* inreg null, i8* 
inreg null)
+// X86-VEC:   call x86_vectorcallcc void @"\01foo_vector@@8"(i8* inreg null, 
i8* inreg null)
+// X86-VEC:   ret void
+
+// X64-VEC-LABEL: define dso_local void @bar()
+// X64-VEC:   call x86_vectorcallcc void @"\01foo_default@@16"(i8* null, i8* 
null)
+// X64-VEC:   

[clang-tools-extra] r365576 - [clangd] fix assert in test after r365531.

2019-07-09 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Jul  9 16:05:20 2019
New Revision: 365576

URL: http://llvm.org/viewvc/llvm-project?rev=365576=rev
Log:
[clangd] fix assert in test after r365531.

Unverified because CMake/ninja seems to be broken...

Modified:
clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp?rev=365576=365575=365576=diff
==
--- clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp Tue Jul  
9 16:05:20 2019
@@ -10,6 +10,7 @@
 #include "llvm/Support/Threading.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 #include 
 
 using ::testing::_;
@@ -581,27 +582,31 @@ protected:
 
   // Perform Action and determine whether it rebuilt the index or not.
   bool checkRebuild(std::function Action) {
-// Update reference count so we can tell if the index updates.
-++TestSymbol.References;
+// Update name so we can tell if the index updates.
+VersionStorage.push_back("Sym" + std::to_string(++VersionCounter));
+TestSymbol.Name = VersionStorage.back();
 SymbolSlab::Builder SB;
 SB.insert(TestSymbol);
 Source.update("", llvm::make_unique(std::move(SB).build()),
   nullptr, nullptr, false);
 // Now maybe update the index.
 Action();
-// Now query the index to get the reference count.
-unsigned ReadReferences = 0;
+// Now query the index to get the name count.
+std::string ReadName;
 LookupRequest Req;
 Req.IDs.insert(TestSymbol.ID);
-Target.lookup(Req, [&](const Symbol ) { ReadReferences = S.References; 
});
-// The index was rebuild if the reference count is up to date.
-return ReadReferences == TestSymbol.References;
+Target.lookup(Req, [&](const Symbol ) { ReadName = S.Name; });
+// The index was rebuild if the name is up to date.
+return ReadName == VersionStorage.back();
   }
 
   Symbol TestSymbol;
   FileSymbols Source;
   SwapIndex Target;
   BackgroundIndexRebuilder Rebuilder;
+
+  unsigned VersionCounter = 0;
+  std::deque VersionStorage;
 };
 
 TEST_F(BackgroundIndexRebuilderTest, IndexingTUs) {


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


[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Mmm. Ok, am i understanding correctly that this was crashing because you bound 
a `0 (Loc)` to a prvalue expression of type `unique_ptr`? Yeah, right, don't do 
that :)

> used like 20 times in the LLVM codebase

That doesn't sound like it's high on our list. That's not too many times. 
Probably very few false positives come out of it. Also modeling smart pointers 
is much harder than modeling regular pointers. We could add some modeling into 
`SmartPtrChecker`, but that'd require actually developing that checker :)


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

https://reviews.llvm.org/D64374



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


[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D64374#1577266 , @NoQ wrote:

> Can you provide more info, eg. the full backtrace?


Well, `unique_dyn_cast<>` and `unique_dyn_cast_or_null<>` is used like 20 times 
in the LLVM codebase, whoops. We want to model it.

Full info:

  clang++: 
/home/username/llvm-project/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:333: 
clang::ento::ProgramStateRef 
clang::ento::ExprEngine::createTemporaryRegionIfNeeded(clang::ento::ProgramStateRef,
 const clang::LocationContext *, const clang::Expr *, const clang::Expr *, 
const clang::ento::SubRegion **): Assertion 
`!InitValWithAdjustments.getAs() || Loc::isLocType(Result->getType()) || 
Result->getType()->isMemberPointerType()' failed.
  Stack dump:
  0.Program arguments: /home/username/llvm-project/build/bin/clang++ -cc1 
-triple x86_64-unknown-linux-gnu -analyze -disable-free -main-file-name 
PrettyVariableDumper.cpp -analyzer-store=region 
-analyzer-opt-analyze-nested-blocks -analyzer-checker=core 
-analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode 
-analyzer-checker=cplusplus 
-analyzer-checker=security.insecureAPI.UncheckedReturn 
-analyzer-checker=security.insecureAPI.getpw 
-analyzer-checker=security.insecureAPI.gets 
-analyzer-checker=security.insecureAPI.mktemp 
-analyzer-checker=security.insecureAPI.mkstemp 
-analyzer-checker=security.insecureAPI.vfork 
-analyzer-checker=nullability.NullPassedToNonnull 
-analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w 
-analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 
-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 -resource-dir 
/home/username/llvm-project/build/lib/clang/9.0.0 -D GTEST_HAS_RTTI=0 -D _DEBUG 
-D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D 
__STDC_LIMIT_MACROS -I tools/llvm-pdbutil -I 
/home/username/gsoc/llvm-project/llvm/tools/llvm-pdbutil -I 
/usr/include/libxml2 -I include -I 
/home/username/gsoc/llvm-project/llvm/include -internal-isystem 
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8 -internal-isystem 
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 
-internal-isystem 
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 
-internal-isystem 
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/backward 
-internal-isystem /usr/local/include -internal-isystem 
/home/username/llvm-project/build/lib/clang/9.0.0/include 
-internal-externc-isystem /usr/include/x86_64-linux-gnu 
-internal-externc-isystem /include -internal-externc-isystem /usr/include 
-Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers 
-Wno-long-long -Wno-maybe-uninitialized -Wno-noexcept-type -Wno-comment 
-std=c++11 -fdeprecated-macro -fdebug-compilation-dir 
/home/username/gsoc/llvm-project/build -ferror-limit 19 -fmessage-length 0 
-fvisibility-inlines-hidden -fno-rtti -fobjc-runtime=gcc 
-fdiagnostics-show-option -fcolor-diagnostics -analyzer-output=html 
-analyzer-config stable-report-filename=true -faddrsig -o 
/home/username/gsoc/scan-build/llvm-project/2019-07-09-085802-2471-1 -x c++ 
/home/username/gsoc/llvm-project/llvm/tools/llvm-pdbutil/PrettyVariableDumper.cpp
 
  1. parser at end of file
  2.While analyzing stack: 
#0 Calling llvm::unique_dyn_cast at line 
/home/username/gsoc/llvm-project/llvm/include/llvm/Support/Casting.h:397:10
#1 Calling llvm::unique_dyn_cast_or_null at line 
/home/username/gsoc/llvm-project/llvm/include/llvm/Support/Casting.h:403:10
#2 Calling llvm::unique_dyn_cast_or_null at line 
/home/username/gsoc/llvm-project/llvm/include/llvm/DebugInfo/PDB/PDBSymbol.h:160:12
#3 Calling llvm::pdb::PDBSymbol::getConcreteSymbolByIdHelper at line 
/home/username/gsoc/llvm-project/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypePointer.h:34:3
 

#4 Calling llvm::pdb::PDBSymbolTypePointer::getPointeeType at line 200
#5 Calling llvm::pdb::VariableDumper::dumpRight
  3.
/home/username/gsoc/llvm-project/llvm/include/llvm/Support/Casting.h:381:10: 
Error evaluating statement
  4.
/home/username/gsoc/llvm-project/llvm/include/llvm/Support/Casting.h:381:10: 
Error evaluating statement
   #0 0x7f2daaccc19f llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
/home/username/llvm-project/llvm/lib/Support/Unix/Signals.inc:494:13
   #1 0x7f2daacca400 llvm::sys::RunSignalHandlers() 
/home/username/llvm-project/llvm/lib/Support/Signals.cpp:69:18
   #2 0x7f2daaccc5a8 SignalHandler(int) 
/home/username/llvm-project/llvm/lib/Support/Unix/Signals.inc:357:1
   #3 0x7f2daa5c2890 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
   #4 0x7f2da8868e97 raise 
/build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
   #5 0x7f2da886a801 abort 

[PATCH] D58418: [clang][DirectoryWatcher] Upstream DirectoryWatcher

2019-07-09 Thread Jan Korous via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365574: [clang] DirectoryWatcher (authored by jkorous, 
committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58418?vs=202833=208833#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58418

Files:
  cfe/trunk/include/clang/DirectoryWatcher/DirectoryWatcher.h
  cfe/trunk/lib/CMakeLists.txt
  cfe/trunk/lib/DirectoryWatcher/CMakeLists.txt
  cfe/trunk/lib/DirectoryWatcher/DirectoryScanner.cpp
  cfe/trunk/lib/DirectoryWatcher/DirectoryScanner.h
  cfe/trunk/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
  cfe/trunk/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
  cfe/trunk/unittests/CMakeLists.txt
  cfe/trunk/unittests/DirectoryWatcher/CMakeLists.txt
  cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Index: cfe/trunk/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
===
--- cfe/trunk/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
+++ cfe/trunk/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
@@ -0,0 +1,233 @@
+//===- DirectoryWatcher-mac.cpp - Mac-platform directory watching -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DirectoryScanner.h"
+#include "clang/DirectoryWatcher/DirectoryWatcher.h"
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include 
+
+using namespace llvm;
+using namespace clang;
+
+static FSEventStreamRef createFSEventStream(
+StringRef Path,
+std::function, bool)>,
+dispatch_queue_t);
+static void stopFSEventStream(FSEventStreamRef);
+
+namespace {
+
+class DirectoryWatcherMac : public clang::DirectoryWatcher {
+public:
+  DirectoryWatcherMac(
+  FSEventStreamRef EventStream,
+  std::function, bool)>
+  Receiver,
+  llvm::StringRef WatchedDirPath)
+  : EventStream(EventStream), Receiver(Receiver),
+WatchedDirPath(WatchedDirPath) {}
+
+  ~DirectoryWatcherMac() override {
+stopFSEventStream(EventStream);
+EventStream = nullptr;
+// Now it's safe to use Receiver as the only other concurrent use would have
+// been in EventStream processing.
+Receiver(DirectoryWatcher::Event(
+ DirectoryWatcher::Event::EventKind::WatcherGotInvalidated, ""),
+ false);
+  }
+
+private:
+  FSEventStreamRef EventStream;
+  std::function, bool)> Receiver;
+  const std::string WatchedDirPath;
+};
+
+struct EventStreamContextData {
+  std::string WatchedPath;
+  std::function, bool)> Receiver;
+
+  EventStreamContextData(
+  std::string &,
+  std::function, bool)>
+  Receiver)
+  : WatchedPath(std::move(WatchedPath)), Receiver(Receiver) {}
+
+  // Needed for FSEvents
+  static void dispose(const void *ctx) {
+delete static_cast(ctx);
+  }
+};
+} // namespace
+
+constexpr const FSEventStreamEventFlags StreamInvalidatingFlags =
+kFSEventStreamEventFlagUserDropped | kFSEventStreamEventFlagKernelDropped |
+kFSEventStreamEventFlagMustScanSubDirs;
+
+constexpr const FSEventStreamEventFlags ModifyingFileEvents =
+kFSEventStreamEventFlagItemCreated | kFSEventStreamEventFlagItemRenamed |
+kFSEventStreamEventFlagItemModified;
+
+static void eventStreamCallback(ConstFSEventStreamRef Stream,
+void *ClientCallBackInfo, size_t NumEvents,
+void *EventPaths,
+const FSEventStreamEventFlags EventFlags[],
+const FSEventStreamEventId EventIds[]) {
+  auto *ctx = static_cast(ClientCallBackInfo);
+
+  std::vector Events;
+  for (size_t i = 0; i < NumEvents; ++i) {
+StringRef Path = ((const char **)EventPaths)[i];
+const FSEventStreamEventFlags Flags = EventFlags[i];
+
+if (Flags & StreamInvalidatingFlags) {
+  Events.emplace_back(DirectoryWatcher::Event{
+  DirectoryWatcher::Event::EventKind::WatcherGotInvalidated, ""});
+  break;
+} else if (!(Flags & kFSEventStreamEventFlagItemIsFile)) {
+  // Subdirectories aren't supported - if some directory got removed it
+  // must've been the watched directory itself.
+  if ((Flags & kFSEventStreamEventFlagItemRemoved) &&
+  Path == ctx->WatchedPath) {
+Events.emplace_back(DirectoryWatcher::Event{
+DirectoryWatcher::Event::EventKind::WatchedDirRemoved, ""});
+Events.emplace_back(DirectoryWatcher::Event{
+DirectoryWatcher::Event::EventKind::WatcherGotInvalidated, ""});
+break;
+  }
+   

r365574 - [clang] DirectoryWatcher

2019-07-09 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Tue Jul  9 15:44:48 2019
New Revision: 365574

URL: http://llvm.org/viewvc/llvm-project?rev=365574=rev
Log:
[clang] DirectoryWatcher

Asynchronously monitors specified directory for changes and passes 
notifications to provided callback.

Dependency for index-while-building.

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

Added:
cfe/trunk/include/clang/DirectoryWatcher/
cfe/trunk/include/clang/DirectoryWatcher/DirectoryWatcher.h
cfe/trunk/lib/DirectoryWatcher/
cfe/trunk/lib/DirectoryWatcher/CMakeLists.txt
cfe/trunk/lib/DirectoryWatcher/DirectoryScanner.cpp
cfe/trunk/lib/DirectoryWatcher/DirectoryScanner.h
cfe/trunk/lib/DirectoryWatcher/linux/
cfe/trunk/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
cfe/trunk/lib/DirectoryWatcher/mac/
cfe/trunk/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
cfe/trunk/unittests/DirectoryWatcher/
cfe/trunk/unittests/DirectoryWatcher/CMakeLists.txt
cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
Modified:
cfe/trunk/lib/CMakeLists.txt
cfe/trunk/unittests/CMakeLists.txt

Added: cfe/trunk/include/clang/DirectoryWatcher/DirectoryWatcher.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/DirectoryWatcher/DirectoryWatcher.h?rev=365574=auto
==
--- cfe/trunk/include/clang/DirectoryWatcher/DirectoryWatcher.h (added)
+++ cfe/trunk/include/clang/DirectoryWatcher/DirectoryWatcher.h Tue Jul  9 
15:44:48 2019
@@ -0,0 +1,123 @@
+//===- DirectoryWatcher.h - Listens for directory file changes --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_DIRECTORYWATCHER_DIRECTORYWATCHER_H
+#define LLVM_CLANG_DIRECTORYWATCHER_DIRECTORYWATCHER_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+/// Provides notifications for file changes in a directory.
+///
+/// Invokes client-provided function on every filesystem event in the watched
+/// directory. Initially the the watched directory is scanned and for every 
file
+/// found, an event is synthesized as if the file was added.
+///
+/// This is not a general purpose directory monitoring tool - list of
+/// limitations follows.
+///
+/// Only flat directories with no subdirectories are supported. In case
+/// subdirectories are present the behavior is unspecified - events *might* be
+/// passed to Receiver on macOS (due to FSEvents being used) while they
+/// *probably* won't be passed on Linux (due to inotify being used).
+///
+/// Known potential inconsistencies
+/// - For files that are deleted befor the initial scan processed them, clients
+/// might receive Removed notification without any prior Added notification.
+/// - Multiple notifications might be produced when a file is added to the
+/// watched directory during the initial scan. We are choosing the lesser evil
+/// here as the only known alternative strategy would be to invalidate the
+/// watcher instance and force user to create a new one whenever filesystem
+/// event occurs during the initial scan but that would introduce continuous
+/// restarting failure mode (watched directory is not always "owned" by the 
same
+/// process that is consuming it). Since existing clients can handle duplicate
+/// events well, we decided for simplicity.
+///
+/// Notifications are provided only for changes done through local user-space
+/// filesystem interface. Specifically, it's unspecified if notification would
+/// be provided in case of a:
+/// - a file mmap-ed and changed
+/// - a file changed via remote (NFS) or virtual (/proc) FS access to monitored
+/// directory
+/// - another filesystem mounted to the watched directory
+///
+/// No support for LLVM VFS.
+///
+/// It is unspecified whether notifications for files being deleted are sent in
+/// case the whole watched directory is sent.
+///
+/// Directories containing "too many" files and/or receiving events "too
+/// frequently" are not supported - if the initial scan can't be finished 
before
+/// the watcher instance gets invalidated (see WatcherGotInvalidated) there's 
no
+/// good error handling strategy - the only option for client is to destroy the
+/// watcher, restart watching with new instance and hope it won't repeat.
+class DirectoryWatcher {
+public:
+  struct Event {
+enum class EventKind {
+  Removed,
+  /// Content of a file was modified.
+  Modified,
+  /// The watched directory got deleted.
+  WatchedDirRemoved,
+  /// The DirectoryWatcher that originated this event is no longer valid 
and
+  /// its behavior is unspecified.
+  ///
+  

[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D64374#1577262 , @Charusso wrote:

> - Add the forgotten `llvm` namespace to the `CallDescription`.


Nice!

In D64374#1577254 , @Charusso wrote:

> The only crash-able code was that:
>
>   #0 Calling llvm::unique_dyn_cast
>


Mmm. What? Can you provide more info, eg. the full backtrace?


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

https://reviews.llvm.org/D64374



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


[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 208831.
Charusso added a comment.

- Add the forgotten `llvm` namespace to the `CallDescription`.


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

https://reviews.llvm.org/D64374

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/test/Analysis/cast-value.cpp
  clang/test/Analysis/return-value-guaranteed.cpp

Index: clang/test/Analysis/return-value-guaranteed.cpp
===
--- clang/test/Analysis/return-value-guaranteed.cpp
+++ clang/test/Analysis/return-value-guaranteed.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 \
-// RUN:  -analyzer-checker=core,apiModeling.ReturnValue \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.ReturnValue \
 // RUN:  -analyzer-output=text -verify=class %s
 
 struct Foo { int Field; };
Index: clang/test/Analysis/cast-value.cpp
===
--- /dev/null
+++ clang/test/Analysis/cast-value.cpp
@@ -0,0 +1,133 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN:  -verify=logic %s
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue \
+// RUN:  -analyzer-output=text -verify %s
+
+void clang_analyzer_numTimesReached();
+void clang_analyzer_warnIfReached();
+void clang_analyzer_eval(bool);
+
+template 
+const X *cast(Y Value);
+
+template 
+const X *dyn_cast(Y Value);
+
+template 
+const X *cast_or_null(Y Value);
+
+template 
+const X *dyn_cast_or_null(Y Value);
+
+class Shape {};
+class Triangle : public Shape {};
+class Circle : public Shape {};
+
+namespace test_cast {
+void evalLogic(const Shape *S) {
+  const Circle *C = cast(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{1}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // no-warning
+
+  if (!S)
+clang_analyzer_warnIfReached(); // no-warning
+}
+} // namespace test_cast
+
+namespace test_dyn_cast {
+void evalLogic(const Shape *S) {
+  const Circle *C = dyn_cast(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{2}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // logic-warning {{REACHABLE}}
+
+  if (!S)
+clang_analyzer_warnIfReached(); // no-warning
+}
+} // namespace test_dyn_cast
+
+namespace test_cast_or_null {
+void evalLogic(const Shape *S) {
+  const Circle *C = cast_or_null(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{2}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // no-warning
+
+  if (!S)
+clang_analyzer_eval(!C); // logic-warning {{TRUE}}
+}
+} // namespace test_cast_or_null
+
+namespace test_dyn_cast_or_null {
+void evalLogic(const Shape *S) {
+  const Circle *C = dyn_cast_or_null(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{3}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // logic-warning {{REACHABLE}}
+
+  if (!S)
+clang_analyzer_eval(!C); // logic-warning {{TRUE}}
+}
+
+void evalNonNullParamNonNullReturn(const Shape *S) {
+  const auto *C = dyn_cast_or_null(S);
+  // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' succeeds}}
+  // expected-note@-2 {{Assuming pointer value is null}}
+  // expected-note@-3 {{'C' initialized here}}
+
+  (void)(1 / !(bool)C);
+  // expected-note@-1 {{'C' is non-null}}
+  // expected-note@-2 {{Division by zero}}
+  // expected-warning@-3 {{Division by zero}}
+  // logic-warning@-4 {{Division by zero}}
+}
+
+void evalNonNullParamNullReturn(const Shape *S) {
+  const auto *C = dyn_cast_or_null(S);
+  // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' fails}}
+  // expected-note@-2 {{Assuming pointer value is null}}
+
+  if (const auto *T = dyn_cast_or_null(S)) {
+// expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Triangle' succeeds}}
+// expected-note@-2 {{'T' initialized here}}
+// expected-note@-3 {{'T' is non-null}}
+// expected-note@-4 {{Taking true branch}}
+
+(void)(1 / !T);
+// expected-note@-1 {{'T' is non-null}}
+// expected-note@-2 {{Division by zero}}
+// expected-warning@-3 {{Division by zero}}
+// logic-warning@-4 {{Division by zero}}
+  }
+}
+
+void evalNullParamNullReturn(const Shape *S) {
+  const auto *C = dyn_cast_or_null(S);
+  // expected-note@-1 {{Assuming null pointer is passed into cast}}
+  // expected-note@-2 {{'C' initialized to a null pointer value}}
+
+  (void)(1 / (bool)C);
+  // 

[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D64374#1577235 , @NoQ wrote:

> Whoops. I underestimated you (:
>
> Ok, anyway, this was my last comment. Great job! Remember to make sure that 
> it works on the actual LLVM, not only on tests; mocked-up test headers are 
> very easy to get wrong.


The only crash-able code was that:

  #0 Calling llvm::unique_dyn_cast

where:

  ProgramStateRef ExprEngine::createTemporaryRegionIfNeeded():
  Assertion `!InitValWithAdjustments.getAs() || 
Loc::isLocType(Result->getType()) || Result->getType()->isMemberPointerType()'

because of `cast<>`:

  template 
  LLVM_NODISCARD inline auto unique_dyn_cast(std::unique_ptr )
  -> decltype(cast(Val)) {
if (!isa(Val))
  return nullptr;
return cast(std::move(Val));
  }

(source: https://llvm.org/doxygen/Casting_8h_source.html)

So we bypass every error with that CXXRecordDecl checking from now. Would we 
like to model that?


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

https://reviews.llvm.org/D64374



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


[PATCH] D64380: Add 'require_designated_init' and 'required' attribute to clang

2019-07-09 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 208829.
emmettneyman added a comment.

Updated tests and diagnostic messages with new attribute spelling


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64380

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCXX/attr-designated-init-required.cpp
  clang/test/SemaCXX/attr-require-designated-init.cpp

Index: clang/test/SemaCXX/attr-require-designated-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/attr-require-designated-init.cpp
@@ -0,0 +1,104 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#define ATTR [[clang::require_designated_init]]
+
+// The require_designated_init attribute only applies to types. It will
+// generate a warning when attached to variables, functions, arrays, etc.
+int ATTR x;// expected-error{{'require_designated_init' attribute cannot be applied to types}}
+void ATTR fun(int x) { // expected-error{{'require_designated_init' attribute cannot be applied to types}}
+  return;
+}
+int ATTR arr[10]; // expected-error{{'require_designated_init' attribute cannot be applied to types}}
+
+// Struct with one field with require_designated_init attribute
+struct ATTR Foo { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int a;
+};
+
+// The following are invalid ways of initializing instances of this struct.
+Foo f1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Foo f2{1};// expected-error{{variable declaration does not use designated initializer syntax}}
+Foo f3 = {1}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this struct.
+Foo f4{};
+Foo f5 = {};
+Foo f6{.a = 1};
+Foo f7 = {.a = 1};
+
+// Struct with multiple fields wth require_designated_init attribute
+struct ATTR Bar { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int b;
+  int c;
+};
+
+// The following are invalid ways of initializing instances of this struct.
+Bar b1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b2{1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b3 = {1, 2};  // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b4{.b = 1, 2};// expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b5 = {.b = 1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this struct.
+Bar b6{};
+Bar b7 = {};
+Bar b8{.b = 1};
+Bar b9 = {.b = 1};
+Bar b10{.b = 1, .c = 2};
+Bar b11 = {.b = 1, .c = 2};
+Bar b12 = {.c = 2, .b = 1};
+
+// Struct without require_designated_init attribute
+struct Baz {
+  int d;
+  int e;
+};
+
+// The following are all valid ways of initializing instances of this struct.
+Baz z1;
+Baz z2{};
+Baz z3 = {};
+Baz z4{1, 2};
+Baz z5 = {1, 2};
+Baz z6{.d = 1, .e = 2};
+Baz z7 = {.d = 1, .e = 2};
+Baz z8{1};
+Baz z9 = {1};
+Baz z10{.d = 1, 2};
+Baz z11 = {.d = 1, 2};
+
+// The require_designated_init attribute can also be attached to unions.
+union ATTR Uni { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int x;
+  int y;
+};
+
+// The following are invalid ways of initializing instances of this union.
+Uni u1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Uni u2{1};// expected-error{{variable declaration does not use designated initializer syntax}}
+Uni u3 = {1}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this union.
+Uni u4{};
+Uni u5 = {};
+Uni u6{.x = 1};
+Uni u7 = {.x = 1};
+
+// The require_designated_init attribute can also be attached to classes.
+class ATTR Cla { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+public:
+  int x;
+  int y;
+};
+
+// The following are invalid ways of initializing instances of this class.
+Cla c1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c2{1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c3 = {1, 2};  // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c4{.x = 1, 2};// expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c5 = {.x = 1, 2}; // 

[PATCH] D64448: gsl::Owner/gsl::Pointer: Add implicit annotations for some std types

2019-07-09 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In D64448#1577109 , @gribozavr wrote:

> > The tests are currently here
> >  I think due to their dependency on a standard library, they are not a good 
> > fit for clang/test/. Where else could I put them?
>
> Make some mocks that reproduce the salient parts of different libraries, the 
> coding patterns they use, and check them into clang/test.


Those are already there in `clang/test/SemaCXX/attr-gsl-owner-pointer.cpp`. I 
was thinking about adding the corresponding tests to libc++ as well so we have 
better chances to get some notifications if a new language 
feature/implementation trick is introduced.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64448



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


[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Whoops. I underestimated you (:

Ok, anyway, this was my last comment. Great job! Remember to make sure that it 
works on the actual LLVM, not only on tests; mocked-up test headers are very 
easy to get wrong.


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

https://reviews.llvm.org/D64374



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


[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked 2 inline comments as done.
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:172
+  !CE->getArg(0)->getType()->getPointeeCXXRecordDecl())
+return false;
+

If we cannot obtain any of the CXXRecordDecls then we bail out. You are right 
about that feature, and I like it.


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

https://reviews.llvm.org/D64374



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


[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:58
+static std::string getCastName(const Expr *Cast) {
+  return Cast->getType()->getPointeeCXXRecordDecl()->getNameAsString();
+}

You should still check if `Cast->getType()->getPointeeCXXRecordDecl()` returns 
null, otherwise you can crash.

But when it's null, you should immediately return `false` from your `evalCall`.


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

https://reviews.llvm.org/D64374



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


[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 208824.
Charusso marked 6 inline comments as done.
Charusso added a comment.

- Move to `apiModeling.llvm`.
- Prevent unknown casts.
- Refactor.


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

https://reviews.llvm.org/D64374

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/test/Analysis/cast-value.cpp
  clang/test/Analysis/return-value-guaranteed.cpp

Index: clang/test/Analysis/return-value-guaranteed.cpp
===
--- clang/test/Analysis/return-value-guaranteed.cpp
+++ clang/test/Analysis/return-value-guaranteed.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 \
-// RUN:  -analyzer-checker=core,apiModeling.ReturnValue \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.ReturnValue \
 // RUN:  -analyzer-output=text -verify=class %s
 
 struct Foo { int Field; };
Index: clang/test/Analysis/cast-value.cpp
===
--- /dev/null
+++ clang/test/Analysis/cast-value.cpp
@@ -0,0 +1,133 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN:  -verify=logic %s
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue \
+// RUN:  -analyzer-output=text -verify %s
+
+void clang_analyzer_numTimesReached();
+void clang_analyzer_warnIfReached();
+void clang_analyzer_eval(bool);
+
+template 
+const X *cast(Y Value);
+
+template 
+const X *dyn_cast(Y Value);
+
+template 
+const X *cast_or_null(Y Value);
+
+template 
+const X *dyn_cast_or_null(Y Value);
+
+class Shape {};
+class Triangle : public Shape {};
+class Circle : public Shape {};
+
+namespace test_cast {
+void evalLogic(const Shape *S) {
+  const Circle *C = cast(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{1}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // no-warning
+
+  if (!S)
+clang_analyzer_warnIfReached(); // no-warning
+}
+} // namespace test_cast
+
+namespace test_dyn_cast {
+void evalLogic(const Shape *S) {
+  const Circle *C = dyn_cast(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{2}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // logic-warning {{REACHABLE}}
+
+  if (!S)
+clang_analyzer_warnIfReached(); // no-warning
+}
+} // namespace test_dyn_cast
+
+namespace test_cast_or_null {
+void evalLogic(const Shape *S) {
+  const Circle *C = cast_or_null(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{2}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // no-warning
+
+  if (!S)
+clang_analyzer_eval(!C); // logic-warning {{TRUE}}
+}
+} // namespace test_cast_or_null
+
+namespace test_dyn_cast_or_null {
+void evalLogic(const Shape *S) {
+  const Circle *C = dyn_cast_or_null(S);
+  clang_analyzer_numTimesReached(); // logic-warning {{3}}
+
+  if (S && C)
+clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // logic-warning {{REACHABLE}}
+
+  if (!S)
+clang_analyzer_eval(!C); // logic-warning {{TRUE}}
+}
+
+void evalNonNullParamNonNullReturn(const Shape *S) {
+  const auto *C = dyn_cast_or_null(S);
+  // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' succeeds}}
+  // expected-note@-2 {{Assuming pointer value is null}}
+  // expected-note@-3 {{'C' initialized here}}
+
+  (void)(1 / !(bool)C);
+  // expected-note@-1 {{'C' is non-null}}
+  // expected-note@-2 {{Division by zero}}
+  // expected-warning@-3 {{Division by zero}}
+  // logic-warning@-4 {{Division by zero}}
+}
+
+void evalNonNullParamNullReturn(const Shape *S) {
+  const auto *C = dyn_cast_or_null(S);
+  // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' fails}}
+  // expected-note@-2 {{Assuming pointer value is null}}
+
+  if (const auto *T = dyn_cast_or_null(S)) {
+// expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Triangle' succeeds}}
+// expected-note@-2 {{'T' initialized here}}
+// expected-note@-3 {{'T' is non-null}}
+// expected-note@-4 {{Taking true branch}}
+
+(void)(1 / !T);
+// expected-note@-1 {{'T' is non-null}}
+// expected-note@-2 {{Division by zero}}
+// expected-warning@-3 {{Division by zero}}
+// logic-warning@-4 {{Division by zero}}
+  }
+}
+
+void evalNullParamNullReturn(const Shape *S) {
+  const auto *C = dyn_cast_or_null(S);
+  // expected-note@-1 {{Assuming null pointer is passed into cast}}
+  // expected-note@-2 {{'C' initialized to a null pointer 

[PATCH] D63082: [Diagnostics] Added support for -Wint-in-bool-context

2019-07-09 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

It would be nice to land this before 9.0 branch date...


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

https://reviews.llvm.org/D63082



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


[PATCH] D63663: [clang-doc] Add html links to references

2019-07-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

I've also just noticed that the YAML generator is missing from this -- could 
you add the `Path` fields to hat output as well?




Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:213
+  llvm::SmallString<128> Path = Type.Path;
+  llvm::sys::path::append(Path, Type.Name + ".html");
+  return genLink(Type.Name, Path);

Now that the paths aren't absolute, you'll need to make this relative to the 
current path (something like 
https://github.com/llvm/llvm-project/blob/master/clang/lib/Lex/PPLexerChange.cpp#L201)


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

https://reviews.llvm.org/D63663



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


[PATCH] D64375: [OpenMP][Docs] Provide implementation status details

2019-07-09 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D64375#1577153 , @jdoerfert wrote:

> @lebedev.ri I'd like to see if we can transition this one into a more generic 
> one with version numbers etc. Is that OK?


I have no further comment at the moment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64375



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


[PATCH] D64375: [OpenMP][Docs] Provide implementation status details

2019-07-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

I will update the table (hopefully tomorrow) and we can then see if we commit 
it and change it in-place or if we have more initial feedback.

Thanks everyone for providing all this information!

@lebedev.ri I'd like to see if we can transition this one into a more generic 
one with version numbers etc. Is that OK?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64375



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


[PATCH] D64383: build: use multiple `install` rather than building up a list

2019-07-09 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd closed this revision.
compnerd added a comment.

SVN r365562


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D64383



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


[PATCH] D64380: Add 'require_designated_init' and 'required' attribute to clang

2019-07-09 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 208814.
emmettneyman marked 3 inline comments as done.
emmettneyman added a comment.

Changed attribute spelling from GNU to CXX11 and renamed the 'required' 
attribute to 'designated_init_required'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64380

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCXX/attr-designated-init-required.cpp
  clang/test/SemaCXX/attr-require-designated-init.cpp

Index: clang/test/SemaCXX/attr-require-designated-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/attr-require-designated-init.cpp
@@ -0,0 +1,104 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#define ATTR [[clang::require_designated_init]]
+
+// The require_designated_init attribute only applies to types. It will
+// generate a warning when attached to variables, functions, arrays, etc.
+int ATTR x;// expected-error{{'require_designated_init' attribute cannot be applied to types}}
+void ATTR fun(int x) { // expected-error{{'require_designated_init' attribute cannot be applied to types}}
+  return;
+}
+int ATTR arr[10]; // expected-error{{'require_designated_init' attribute cannot be applied to types}}
+
+// Struct with one field with require_designated_init attribute
+struct ATTR Foo { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int a;
+};
+
+// The following are invalid ways of initializing instances of this struct.
+Foo f1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Foo f2{1};// expected-error{{variable declaration does not use designated initializer syntax}}
+Foo f3 = {1}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this struct.
+Foo f4{};
+Foo f5 = {};
+Foo f6{.a = 1};
+Foo f7 = {.a = 1};
+
+// Struct with multiple fields wth require_designated_init attribute
+struct ATTR Bar { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int b;
+  int c;
+};
+
+// The following are invalid ways of initializing instances of this struct.
+Bar b1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b2{1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b3 = {1, 2};  // expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b4{.b = 1, 2};// expected-error{{variable declaration does not use designated initializer syntax}}
+Bar b5 = {.b = 1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this struct.
+Bar b6{};
+Bar b7 = {};
+Bar b8{.b = 1};
+Bar b9 = {.b = 1};
+Bar b10{.b = 1, .c = 2};
+Bar b11 = {.b = 1, .c = 2};
+Bar b12 = {.c = 2, .b = 1};
+
+// Struct without require_designated_init attribute
+struct Baz {
+  int d;
+  int e;
+};
+
+// The following are all valid ways of initializing instances of this struct.
+Baz z1;
+Baz z2{};
+Baz z3 = {};
+Baz z4{1, 2};
+Baz z5 = {1, 2};
+Baz z6{.d = 1, .e = 2};
+Baz z7 = {.d = 1, .e = 2};
+Baz z8{1};
+Baz z9 = {1};
+Baz z10{.d = 1, 2};
+Baz z11 = {.d = 1, 2};
+
+// The require_designated_init attribute can also be attached to unions.
+union ATTR Uni { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+  int x;
+  int y;
+};
+
+// The following are invalid ways of initializing instances of this union.
+Uni u1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Uni u2{1};// expected-error{{variable declaration does not use designated initializer syntax}}
+Uni u3 = {1}; // expected-error{{variable declaration does not use designated initializer syntax}}
+// The following are valid ways of initializing instances of this union.
+Uni u4{};
+Uni u5 = {};
+Uni u6{.x = 1};
+Uni u7 = {.x = 1};
+
+// The require_designated_init attribute can also be attached to classes.
+class ATTR Cla { // expected-note 0+ {{required by 'require_designated_init' attribute here}}
+public:
+  int x;
+  int y;
+};
+
+// The following are invalid ways of initializing instances of this class.
+Cla c1;   // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c2{1, 2}; // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c3 = {1, 2};  // expected-error{{variable declaration does not use designated initializer syntax}}
+Cla c4{.x = 1, 2};// 

[PATCH] D64448: gsl::Owner/gsl::Pointer: Add implicit annotations for some std types

2019-07-09 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added a comment.

> The tests are currently here
>  I think due to their dependency on a standard library, they are not a good 
> fit for clang/test/. Where else could I put them?

Make some mocks that reproduce the salient parts of different libraries, the 
coding patterns they use, and check them into clang/test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64448



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


[PATCH] D64448: gsl::Owner/gsl::Pointer: Add implicit annotations for some std types

2019-07-09 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre created this revision.
mgehre added reviewers: gribozavr, xazax.hun.
Herald added a subscriber: rnkovacs.
Herald added a project: clang.

Make the DerefType, i.e. the argument of gsl::Owner/gsl::Pointer optional for 
now.

The DerefType is used when infering lifetime annotations of functions, e.g.
how a return value can relate to the arguments. Our initial checks should
work without that kind of inference and instead use explicit annotations,
so we don't need the DerefType right now.
And having it optional makes the implicit/default annotations for std:: types
easier to implement. I think the DerefType is also optional in the current MSVC
implementation.

This seems to be the first attribute that has an optional Type argument,
so I needed to fix two thinks in tablegen:

- Don't crash AST dump when Owner/Pointer has no Type argument
- Don't crash when pretty-printing an Attribute with optional type argument

Add __is_gsl_owner/__is_gsl_pointer builtins. They are very useful to test
if the annotations have been attached correctly.

Hard code gsl::Owner/gsl::Pointer for std types. The paper mentions
some types explicitly. Generally, all containers and their iterators are
covered. For iterators, we cover both the case that they are defined
as an nested class or as an typedef/using. I have started to test this
implementation against some real standard library implementations, namely
libc++ 7.1.0, libc++ 8.0.1rc2, libstdc++ 4.6.4, libstdc++ 4.8.5,
libstdc++ 4.9.4, libstdc++ 5.4.0, libstdc++ 6.5.0, libstdc++ 7.3.0,
libstdc++ 8.3.0 and libstdc++ 9.1.0.

The tests are currently here

  https://github.com/mgehre/llvm-project/blob/lifetime-ci/lifetime-attr-test.sh
  https://github.com/mgehre/llvm-project/blob/lifetime-ci/lifetime-attr-test.cpp

I think due to their dependency on a standard library, they are not a good fit
for clang/test/. Where else could I put them?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64448

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Basic/TypeTraits.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -303,6 +303,8 @@
 std::string getIsOmitted() const override {
   if (type == "IdentifierInfo *")
 return "!get" + getUpperName().str() + "()";
+  if (type == "TypeSourceInfo *")
+return "!get" + getUpperName().str() + "Loc()";
   if (type == "ParamIdx")
 return "!get" + getUpperName().str() + "().isValid()";
   return "false";
@@ -336,6 +338,8 @@
<< "  OS << \" \" << SA->get" << getUpperName()
<< "()->getName();\n";
   } else if (type == "TypeSourceInfo *") {
+if (isOptional())
+  OS << "if (SA->get" << getUpperName() << "Loc())";
 OS << "OS << \" \" << SA->get" << getUpperName()
<< "().getAsString();\n";
   } else if (type == "bool") {
Index: clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
===
--- clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
+++ clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
@@ -10,14 +10,15 @@
 
 struct S {
 };
+static_assert(!__is_gsl_owner(S), "");
+static_assert(!__is_gsl_pointer(S), "");
 
 S [[gsl::Owner]] Instance;
 // expected-error@-1 {{'Owner' attribute cannot be applied to types}}
 
 class [[gsl::Owner]] OwnerMissingParameter{};
-// expected-error@-1 {{'Owner' attribute takes one argument}}
+
 class [[gsl::Pointer]] PointerMissingParameter{};
-// expected-error@-1 {{'Pointer' attribute takes one argument}}
 
 class [[gsl::Owner(7)]] OwnerDerefNoType{};
 // expected-error@-1 {{expected a type}} expected-error@-1 {{expected ')'}}
@@ -32,8 +33,12 @@
 // expected-note@-2 {{conflicting attribute is here}}
 
 class [[gsl::Owner(int)]] [[gsl::Owner(int)]] DuplicateOwner{};
+static_assert(__is_gsl_owner(DuplicateOwner), "");
+static_assert(!__is_gsl_pointer(DuplicateOwner), "");
 
 class [[gsl::Pointer(int)]] [[gsl::Pointer(int)]] DuplicatePointer{};
+static_assert(!__is_gsl_owner(DuplicatePointer), "");
+static_assert(__is_gsl_pointer(DuplicatePointer), "");
 
 class [[gsl::Owner(void)]] OwnerVoidDerefType{};
 // expected-error@-1 {{'void' is an invalid argument to attribute 'Owner'}}
@@ -41,7 +46,12 @@
 // expected-error@-1 {{'void' is an invalid argument to attribute 'Pointer'}}
 
 class 

[PATCH] D59922: [Attributor] Deduce "no-capture" argument attribute

2019-07-09 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 208811.
jdoerfert added a comment.
Herald added a subscriber: jfb.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59922

Files:
  llvm/include/llvm/Transforms/IPO/Attributor.h
  llvm/lib/Transforms/IPO/Attributor.cpp
  llvm/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll
  llvm/test/Transforms/FunctionAttrs/arg_nocapture.ll
  llvm/test/Transforms/FunctionAttrs/arg_returned.ll
  llvm/test/Transforms/FunctionAttrs/convergent.ll
  llvm/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll
  llvm/test/Transforms/FunctionAttrs/nocapture.ll
  llvm/test/Transforms/FunctionAttrs/nonnull.ll
  llvm/test/Transforms/FunctionAttrs/out-of-bounds-iterator-bug.ll
  llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll
  llvm/test/Transforms/FunctionAttrs/readattrs.ll
  llvm/test/Transforms/FunctionAttrs/readnone.ll

Index: llvm/test/Transforms/FunctionAttrs/readnone.ll
===
--- llvm/test/Transforms/FunctionAttrs/readnone.ll
+++ llvm/test/Transforms/FunctionAttrs/readnone.ll
@@ -1,13 +1,17 @@
-; RUN: opt < %s -functionattrs -S | FileCheck %s
-; RUN: opt < %s -passes=function-attrs -S | FileCheck %s
+; RUN: opt < %s -attributor-disable=false -attributor -functionattrs -S | FileCheck %s
+; RUN: opt < %s -attributor-disable=false -passes="attributor,cgscc(function-attrs)" -S | FileCheck %s
 
-; CHECK: define void @bar(i8* nocapture readnone)
+; FIXME: Because nocapture and readnone deduction in the functionattrs pass are interleaved, it doesn't
+;trigger when nocapture is already present. Once the Attributor derives memory behavior,
+;this should be fixed.
+; FIXME: readnone missing for %0 two times
+; CHECK: define void @bar(i8* nocapture readonly)
 define void @bar(i8* readonly) {
   call void @foo(i8* %0)
 ret void
 }
 
-; CHECK: define void @foo(i8* nocapture readnone)
+; CHECK: define void @foo(i8* nocapture readonly)
 define void @foo(i8* readonly) {
   call void @bar(i8* %0)
   ret void
Index: llvm/test/Transforms/FunctionAttrs/readattrs.ll
===
--- llvm/test/Transforms/FunctionAttrs/readattrs.ll
+++ llvm/test/Transforms/FunctionAttrs/readattrs.ll
@@ -1,5 +1,5 @@
-; RUN: opt < %s -functionattrs -S | FileCheck %s
-; RUN: opt < %s -aa-pipeline=basic-aa -passes='cgscc(function-attrs)' -S | FileCheck %s
+; RUN: opt < %s  -attributor -attributor-disable=false -functionattrs -S | FileCheck %s
+; RUN: opt < %s  -attributor-disable=false -aa-pipeline=basic-aa -passes='attributor,cgscc(function-attrs)' -S | FileCheck %s
 @x = global i32 0
 
 declare void @test1_1(i8* %x1_1, i8* readonly %y1_1, ...)
@@ -13,7 +13,7 @@
   ret void
 }
 
-; CHECK: define i8* @test2(i8* readnone returned %p)
+; CHECK: define i8* @test2(i8* readnone returned "no-capture-maybe-returned" %p)
 define i8* @test2(i8* %p) {
   store i32 0, i32* @x
   ret i8* %p
@@ -55,13 +55,13 @@
   ret void
 }
 
-; CHECK: define i32* @test8_1(i32* readnone returned %p)
+; CHECK: define i32* @test8_1(i32* readnone returned "no-capture-maybe-returned" %p)
 define i32* @test8_1(i32* %p) {
 entry:
   ret i32* %p
 }
 
-; CHECK: define void @test8_2(i32* %p)
+; CHECK: define void @test8_2(i32* nocapture %p)
 define void @test8_2(i32* %p) {
 entry:
   %call = call i32* @test8_1(i32* %p)
Index: llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll
===
--- llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll
+++ llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll
@@ -1,5 +1,5 @@
-; RUN: opt -functionattrs -enable-nonnull-arg-prop -attributor -attributor-disable=false -S < %s | FileCheck %s
-; RUN: opt -functionattrs -enable-nonnull-arg-prop -attributor -attributor-disable=false -attributor-verify=true -S < %s | FileCheck %s
+; RUN: opt -attributor -functionattrs -enable-nonnull-arg-prop -attributor-disable=false -S < %s | FileCheck %s
+; RUN: opt -attributor -functionattrs -enable-nonnull-arg-prop -attributor-disable=false -attributor-verify=true -S < %s | FileCheck %s
 ;
 ; This is an evolved example to stress test SCC parameter attribute propagation.
 ; The SCC in this test is made up of the following six function, three of which
@@ -18,20 +18,23 @@
 ; as well as how the parameters are (transitively) used (n = readnone,
 ; r = readonly, w = writeonly).
 ;
-; What we should see is something along the lines of:
-;   1 - Number of functions marked as norecurse
-;   6 - Number of functions marked argmemonly
-;   6 - Number of functions marked as nounwind
-;  16 - Number of arguments marked nocapture
-;   4 - Number of arguments marked readnone
-;   6 - Number of arguments marked writeonly
-;   6 - Number of arguments marked readonly
-;   6 - Number of arguments 

[PATCH] D64274: [analyzer] VirtualCallChecker overhaul.

2019-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 208807.
NoQ added a comment.

Bring back the option in order to preserve backwards compatibility.

Sneak in an implicit conversion from `CheckName` to `StringRef` so that not to 
repeat myself.


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

https://reviews.llvm.org/D64274

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
  clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  clang/test/Analysis/virtualcall.cpp
  clang/test/Analysis/virtualcall.h

Index: clang/test/Analysis/virtualcall.h
===
--- clang/test/Analysis/virtualcall.h
+++ clang/test/Analysis/virtualcall.h
@@ -2,12 +2,7 @@
   class Z {
   public:
 Z() {
-  foo();
-#if !PUREONLY
-	// expected-warning-re@-2 ^}}Call to virtual function during construction}}
-	// expected-note-re@-3 ^}}This constructor of an object of type 'Z' has not returned when the virtual method was called}}
-	// expected-note-re@-4 ^}}Call to virtual function during construction}}	
-#endif
+  foo(); // impure-warning {{Call to virtual function during construction}}
 }
 virtual int foo();
   };
Index: clang/test/Analysis/virtualcall.cpp
===
--- clang/test/Analysis/virtualcall.cpp
+++ clang/test/Analysis/virtualcall.cpp
@@ -1,6 +1,23 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-output=text -verify -std=c++11 %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.VirtualCall \
+// RUN:-std=c++11 -verify=expected,impure %s
 
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -analyzer-output=text -verify -std=c++11 %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.PureVirtualCall \
+// RUN:-std=c++11 -verify=expected -std=c++11 %s
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.VirtualCall \
+// RUN:-analyzer-config \
+// RUN:optin.cplusplus.VirtualCall:PureOnly=true \
+// RUN:-std=c++11 -verify=expected %s
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.PureVirtualCall \
+// RUN:-analyzer-checker=optin.cplusplus.VirtualCall \
+// RUN:-std=c++11 -verify=expected,impure -std=c++11 %s
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.PureVirtualCall \
+// RUN:-analyzer-checker=optin.cplusplus.VirtualCall \
+// RUN:-analyzer-config \
+// RUN:optin.cplusplus.VirtualCall:PureOnly=true \
+// RUN:-std=c++11 -verify=expected %s
 
 #include "virtualcall.h"
 
@@ -13,54 +30,31 @@
   virtual int foo() = 0;
   virtual void bar() = 0;
   void f() {
-foo();
-	// expected-warning-re@-1 ^}}Call to pure virtual function during construction}}
-	// expected-note-re@-2 ^}}Call to pure virtual function during construction}}
+foo(); // expected-warning{{Call to pure virtual function during construction}}
   }
 };
 
 class B : public A {
 public:
-  B() { // expected-note {{Calling default constructor for 'A'}}
-foo(); 
-#if !PUREONLY
-  	// expected-warning-re@-2 ^}}Call to virtual function during construction}}
-	// expected-note-re@-3 ^}}This constructor of an object of type 'B' has not returned when the virtual method was called}}
-  	// expected-note-re@-4 ^}}Call to virtual function during construction}}
-#endif
+  B() {
+foo(); // impure-warning {{Call to virtual function during construction}}
   }
   ~B();
 
   virtual int foo();
   virtual void bar() {
-foo(); 
-#if !PUREONLY
-  	// expected-warning-re@-2 ^}}Call to virtual function during destruction}}
-  	// expected-note-re@-3 ^}}Call to virtual function during destruction}}
-#endif
-  } 
+foo(); // impure-warning{{Call to virtual function during destruction}}
+  }
 };
 
-A::A() { 
-  f(); 
-// expected-note-re@-1 ^}}This constructor of an object of type 'A' has not returned when the virtual method was called}}
-// expected-note-re@-2 ^}}Calling 'A::f'}}
+A::A() {
+  f();
 }
 
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
-#if !PUREONLY
- 	 // expected-note-re@-2 ^}}This destructor of an object of type '~B' has not returned when the virtual method was called}}
- 	 // expected-note-re@-3 ^}}Calling 'B::bar'}}
-#endif
-  this->foo(); 
-#if !PUREONLY
- 	 // expected-warning-re@-2 ^}}Call to virtual function during destruction}}
- 	 // expected-note-re@-3 ^}}This destructor of an object of type '~B' has not returned when the virtual method was called}}
- 	 // expected-note-re@-4 

r365558 - XFAIL clang/test/Headers/max_align.c on i686

2019-07-09 Thread Andus Yu via cfe-commits
Author: andusy
Date: Tue Jul  9 14:06:34 2019
New Revision: 365558

URL: http://llvm.org/viewvc/llvm-project?rev=365558=rev
Log:
XFAIL clang/test/Headers/max_align.c on i686

Modified:
cfe/trunk/test/Headers/max_align.c

Modified: cfe/trunk/test/Headers/max_align.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/max_align.c?rev=365558=365557=365558=diff
==
--- cfe/trunk/test/Headers/max_align.c (original)
+++ cfe/trunk/test/Headers/max_align.c Tue Jul  9 14:06:34 2019
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c11 -verify %s
 // expected-no-diagnostics
 
-// XFAIL: windows-
+// XFAIL: windows-, i686
 
 #ifndef __BIGGEST_ALIGNMENT__
 #error __BIGGEST_ALIGNMENT__ not defined


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


r365557 - Use the Itanium C++ ABI for the pipe_builtin.cl test

2019-07-09 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Jul  9 14:02:06 2019
New Revision: 365557

URL: http://llvm.org/viewvc/llvm-project?rev=365557=rev
Log:
Use the Itanium C++ ABI for the pipe_builtin.cl test

Certain OpenCL constructs cannot yet be mangled in the MS C++ ABI.
Add a FIXME for it if anyone cares to implement it.

Modified:
cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl

Modified: cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl?rev=365557=365556=365557=diff
==
--- cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl Tue Jul  9 14:02:06 2019
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -emit-llvm -cl-ext=+cl_khr_subgroups -O0 -cl-std=c++ -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm 
-cl-ext=+cl_khr_subgroups -O0 -cl-std=c++ -o - %s | FileCheck %s
+// FIXME: Add MS ABI manglings of OpenCL things and remove %itanium_abi_triple
+// above to support OpenCL in the MS C++ ABI.
 
 // CHECK-DAG: %opencl.pipe_ro_t = type opaque
 // CHECK-DAG: %opencl.pipe_wo_t = type opaque


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


r365556 - De-templatize non-dependent VS macro logic, NFC

2019-07-09 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Jul  9 13:57:28 2019
New Revision: 365556

URL: http://llvm.org/viewvc/llvm-project?rev=365556=rev
Log:
De-templatize non-dependent VS macro logic, NFC

These macro definitions don't depend on the template parameter, so they
don't need to be part of the template. Move them to a .cpp file.

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Basic/Targets.h
cfe/trunk/lib/Basic/Targets/AArch64.cpp
cfe/trunk/lib/Basic/Targets/AArch64.h
cfe/trunk/lib/Basic/Targets/ARM.cpp
cfe/trunk/lib/Basic/Targets/OSTargets.cpp
cfe/trunk/lib/Basic/Targets/OSTargets.h
cfe/trunk/lib/Basic/Targets/X86.h

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=365556=36=365556=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Jul  9 13:57:28 2019
@@ -98,19 +98,6 @@ void addCygMingDefines(const LangOptions
   }
 }
 
-void addMinGWDefines(const llvm::Triple , const LangOptions ,
- MacroBuilder ) {
-  DefineStd(Builder, "WIN32", Opts);
-  DefineStd(Builder, "WINNT", Opts);
-  if (Triple.isArch64Bit()) {
-DefineStd(Builder, "WIN64", Opts);
-Builder.defineMacro("__MINGW64__");
-  }
-  Builder.defineMacro("__MSVCRT__");
-  Builder.defineMacro("__MINGW32__");
-  addCygMingDefines(Opts, Builder);
-}
-
 
//===--===//
 // Driver code
 
//===--===//

Modified: cfe/trunk/lib/Basic/Targets.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.h?rev=365556=36=365556=diff
==
--- cfe/trunk/lib/Basic/Targets.h (original)
+++ cfe/trunk/lib/Basic/Targets.h Tue Jul  9 13:57:28 2019
@@ -39,10 +39,6 @@ void defineCPUMacros(clang::MacroBuilder
  bool Tuning = true);
 
 LLVM_LIBRARY_VISIBILITY
-void addMinGWDefines(const llvm::Triple , const clang::LangOptions 
,
- clang::MacroBuilder );
-
-LLVM_LIBRARY_VISIBILITY
 void addCygMingDefines(const clang::LangOptions ,
clang::MacroBuilder );
 } // namespace targets

Modified: cfe/trunk/lib/Basic/Targets/AArch64.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AArch64.cpp?rev=365556=36=365556=diff
==
--- cfe/trunk/lib/Basic/Targets/AArch64.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/AArch64.cpp Tue Jul  9 13:57:28 2019
@@ -534,16 +534,10 @@ MicrosoftARM64TargetInfo::MicrosoftARM64
   TheCXXABI.set(TargetCXXABI::Microsoft);
 }
 
-void MicrosoftARM64TargetInfo::getVisualStudioDefines(
-const LangOptions , MacroBuilder ) const {
-  WindowsTargetInfo::getVisualStudioDefines(Opts, 
Builder);
-  Builder.defineMacro("_M_ARM64", "1");
-}
-
 void MicrosoftARM64TargetInfo::getTargetDefines(const LangOptions ,
 MacroBuilder ) const {
-  WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  getVisualStudioDefines(Opts, Builder);
+  WindowsARM64TargetInfo::getTargetDefines(Opts, Builder);
+  Builder.defineMacro("_M_ARM64", "1");
 }
 
 TargetInfo::CallingConvKind

Modified: cfe/trunk/lib/Basic/Targets/AArch64.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AArch64.h?rev=365556=36=365556=diff
==
--- cfe/trunk/lib/Basic/Targets/AArch64.h (original)
+++ cfe/trunk/lib/Basic/Targets/AArch64.h Tue Jul  9 13:57:28 2019
@@ -123,8 +123,6 @@ public:
   MicrosoftARM64TargetInfo(const llvm::Triple ,
const TargetOptions );
 
-  void getVisualStudioDefines(const LangOptions ,
-  MacroBuilder ) const;
   void getTargetDefines(const LangOptions ,
 MacroBuilder ) const override;
   TargetInfo::CallingConvKind

Modified: cfe/trunk/lib/Basic/Targets/ARM.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/ARM.cpp?rev=365556=36=365556=diff
==
--- cfe/trunk/lib/Basic/Targets/ARM.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/ARM.cpp Tue Jul  9 13:57:28 2019
@@ -1030,8 +1030,6 @@ WindowsARMTargetInfo::WindowsARMTargetIn
 
 void WindowsARMTargetInfo::getVisualStudioDefines(const LangOptions ,
   MacroBuilder ) const 
{
-  WindowsTargetInfo::getVisualStudioDefines(Opts, Builder);
-
   // FIXME: this is invalid for WindowsCE
   Builder.defineMacro("_M_ARM_NT", "1");
   Builder.defineMacro("_M_ARMT", "_M_ARM");

Modified: cfe/trunk/lib/Basic/Targets/OSTargets.cpp
URL: 

r365555 - [CXX] Exercise all paths through these tests.

2019-07-09 Thread Paul Robinson via cfe-commits
Author: probinson
Date: Tue Jul  9 13:49:07 2019
New Revision: 36

URL: http://llvm.org/viewvc/llvm-project?rev=36=rev
Log:
[CXX] Exercise all paths through these tests.

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

Modified:
cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
cfe/trunk/test/SemaCXX/class.cpp
cfe/trunk/test/SemaCXX/linkage2.cpp

Modified: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp?rev=36=365554=36=diff
==
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp Tue Jul  
9 13:49:07 2019
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
 
 // C++03 [namespace.udecl]p4:

Modified: cfe/trunk/test/SemaCXX/class.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/class.cpp?rev=36=365554=36=diff
==
--- cfe/trunk/test/SemaCXX/class.cpp (original)
+++ cfe/trunk/test/SemaCXX/class.cpp Tue Jul  9 13:49:07 2019
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s 
+// RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s -std=c++98
 class C {
 public:
   auto int errx; // expected-error {{storage class specified for a member 
declaration}}

Modified: cfe/trunk/test/SemaCXX/linkage2.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/linkage2.cpp?rev=36=365554=36=diff
==
--- cfe/trunk/test/SemaCXX/linkage2.cpp (original)
+++ cfe/trunk/test/SemaCXX/linkage2.cpp Tue Jul  9 13:49:07 2019
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=gnu++11 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions 
-Wno-local-type-template-args %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions 
-Wno-local-type-template-args %s -std=gnu++98
 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions 
-Wno-local-type-template-args -fmodules %s
 
 namespace test1 {


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


[PATCH] D63894: [CXX] Exercise all paths through these tests

2019-07-09 Thread Paul Robinson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL36: [CXX] Exercise all paths through these tests. 
(authored by probinson, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63894?vs=206921=208802#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63894

Files:
  cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
  cfe/trunk/test/SemaCXX/class.cpp
  cfe/trunk/test/SemaCXX/linkage2.cpp


Index: cfe/trunk/test/SemaCXX/linkage2.cpp
===
--- cfe/trunk/test/SemaCXX/linkage2.cpp
+++ cfe/trunk/test/SemaCXX/linkage2.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=gnu++11 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions 
-Wno-local-type-template-args %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions 
-Wno-local-type-template-args %s -std=gnu++98
 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions 
-Wno-local-type-template-args -fmodules %s
 
 namespace test1 {
Index: cfe/trunk/test/SemaCXX/class.cpp
===
--- cfe/trunk/test/SemaCXX/class.cpp
+++ cfe/trunk/test/SemaCXX/class.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s 
+// RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s -std=c++98
 class C {
 public:
   auto int errx; // expected-error {{storage class specified for a member 
declaration}}
Index: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
===
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
 
 // C++03 [namespace.udecl]p4:


Index: cfe/trunk/test/SemaCXX/linkage2.cpp
===
--- cfe/trunk/test/SemaCXX/linkage2.cpp
+++ cfe/trunk/test/SemaCXX/linkage2.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=gnu++11 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions -Wno-local-type-template-args %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions -Wno-local-type-template-args %s -std=gnu++98
 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions -Wno-local-type-template-args -fmodules %s
 
 namespace test1 {
Index: cfe/trunk/test/SemaCXX/class.cpp
===
--- cfe/trunk/test/SemaCXX/class.cpp
+++ cfe/trunk/test/SemaCXX/class.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s 
+// RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s -std=c++98
 class C {
 public:
   auto int errx; // expected-error {{storage class specified for a member declaration}}
Index: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
===
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
 
 // C++03 [namespace.udecl]p4:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64356: [OPENMP]Initial fix PR42392: Improve -Wuninitialized warnings for OpenMP programs.

2019-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Yay, great!


Repository:
  rC Clang

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

https://reviews.llvm.org/D64356



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


Re: r365499 - [OpenCL][Sema] Fix builtin rewriting

2019-07-09 Thread Reid Kleckner via cfe-commits
FYI, your test seems to fail on Windows:
FAIL: Clang :: CodeGenOpenCL/pipe_builtin.cl (4679 of 15176)
 TEST 'Clang :: CodeGenOpenCL/pipe_builtin.cl' FAILED

Script:
--
: 'RUN: at line 1';
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\clang.exe -cc1
-internal-isystem
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\lib\clang\9.0.0\include
-nostdsysteminc -emit-llvm -cl-ext=+cl_khr_subgroups -O0 -cl-std=c++ -o -
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\CodeGenOpenCL\
pipe_builtin.cl |
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\filecheck.exe
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\CodeGenOpenCL\
pipe_builtin.cl
--
Exit Code: 2

Command Output (stdout):
--
$ ":" "RUN: at line 1"
$ "c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\clang.exe"
"-cc1" "-internal-isystem"
"c:\b\slave\clang-x64-windows-msvc\build\build\stage1\lib\clang\9.0.0\include"
"-nostdsysteminc" "-emit-llvm" "-cl-ext=+cl_khr_subgroups" "-O0"
"-cl-std=c++" "-o" "-"
"C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\CodeGenOpenCL\
pipe_builtin.cl"
# command stderr:
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\CodeGenOpenCL\pipe_builtin.cl:9:1:
error: cannot mangle this OpenCL pipe type yet

void test1(read_only pipe int p, global int *ptr) {

^~~

1 error generated.

On Tue, Jul 9, 2019 at 8:04 AM Marco Antognini via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: mantognini
> Date: Tue Jul  9 08:04:23 2019
> New Revision: 365499
>
> URL: http://llvm.org/viewvc/llvm-project?rev=365499=rev
> Log:
> [OpenCL][Sema] Fix builtin rewriting
>
> This patch ensures built-in functions are rewritten using the proper
> parent declaration.
>
> Existing tests are modified to run in C++ mode to ensure the
> functionality works also with C++ for OpenCL while not increasing the
> testing runtime.
>
> Modified:
> cfe/trunk/include/clang/Basic/Builtins.def
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/test/CodeGenOpenCL/builtins.cl
> cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
> cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl
>
> Modified: cfe/trunk/include/clang/Basic/Builtins.def
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=365499=365498=365499=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/Builtins.def (original)
> +++ cfe/trunk/include/clang/Basic/Builtins.def Tue Jul  9 08:04:23 2019
> @@ -1478,6 +1478,7 @@ BUILTIN(__builtin_coro_begin, "v*v*", "n
>  BUILTIN(__builtin_coro_end, "bv*Ib", "n")
>  BUILTIN(__builtin_coro_suspend, "cIb", "n")
>  BUILTIN(__builtin_coro_param, "bv*v*", "n")
> +
>  // OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
>  // We need the generic prototype, since the packet type could be anything.
>  LANGBUILTIN(read_pipe, "i.", "tn", OCLC20_LANG)
> @@ -1513,6 +1514,8 @@ LANGBUILTIN(get_kernel_max_sub_group_siz
>  LANGBUILTIN(get_kernel_sub_group_count_for_ndrange, "Ui.", "tn",
> OCLC20_LANG)
>
>  // OpenCL v2.0 s6.13.9 - Address space qualifier functions.
> +// FIXME: Pointer parameters of OpenCL builtins should have their address
> space
> +// requirement defined.
>  LANGBUILTIN(to_global, "v*v*", "tn", OCLC20_LANG)
>  LANGBUILTIN(to_local, "v*v*", "tn", OCLC20_LANG)
>  LANGBUILTIN(to_private, "v*v*", "tn", OCLC20_LANG)
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=365499=365498=365499=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jul  9 08:04:23 2019
> @@ -5360,7 +5360,7 @@ static bool checkArgsForPlaceholders(Sem
>  ///  FunctionDecl is returned.
>  /// TODO: Handle pointer return types.
>  static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext
> ,
> -const FunctionDecl *FDecl,
> +FunctionDecl *FDecl,
>  MultiExprArg ArgExprs) {
>
>QualType DeclType = FDecl->getType();
> @@ -5408,7 +5408,7 @@ static FunctionDecl *rewriteBuiltinFunct
>FunctionProtoType::ExtProtoInfo EPI;
>QualType OverloadTy = Context.getFunctionType(FT->getReturnType(),
>  OverloadParams, EPI);
> -  DeclContext *Parent = Context.getTranslationUnitDecl();
> +  DeclContext *Parent = FDecl->getParent();
>FunctionDecl *OverloadDecl = FunctionDecl::Create(Context, Parent,
>  FDecl->getLocation(),
>  FDecl->getLocation(),
>
> Modified: 

[PATCH] D62855: [clangd] Implementation of auto type expansion.

2019-07-09 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Great, let's land this!
We can enhance further later, but this covers the most common cases.

(I think the remaining comments are trivial - then I/you can land without 
further review)




Comment at: clang-tools-extra/clangd/AST.cpp:181
+
+  u_int DifferentAt = 0;
+  while (DifferentAt < MinLength &&

unsigned rather than u_int (just common llvm style)



Comment at: clang-tools-extra/clangd/AST.h:79
+/// Example: shortenNamespace("ns1::MyClass", "ns1")
+///--> "MyClass"
+std::string  shortenNamespace(const llvm::StringRef OriginalName,

can you leave a FIXME that this should take a DeclContext for lookup instead of 
the current namespace name, take in to account using directives etc?
(Otherwise it's not obvious why it belongs in `AST` instead of `SourceCode` - 
but it does)



Comment at: clang-tools-extra/clangd/Selection.cpp:369
 
+const DeclContext* SelectionTree::getDeclContext(const Node* StartNode) {
+

I think this function is not quite correct. At least, it returns the enclosing 
DC outside the enclosing Decl, but that doesn't seem quite right.

There are three critical cases:
 - StartNode is a DeclContext
 - StartNode is (e.g.) an Expr whose containing Decl is a DeclContext
 - StartNode is an Expr whose containing Decl is **not** a DeclContext

Currently, you return the second, second, and first DeclContext encountered, 
respectively.
- If the definition is "enclosing DC that is not the node itself", it should be 
second, first, first.
- If the definition is "enclosing DC that may be the node itself", it should be 
first, first, first.

I think "enclosing DC that's not the node itself" is simplest in which case you 
should add something like `if (CurrentNode != StartNode) if (auto *DC = 
dyn_cast(DC)) return DC;` in the inner if.



Comment at: clang-tools-extra/clangd/Selection.h:104
   const Node *root() const { return Root; }
+  // Get the DeclContext for the Node.
+  // Return nullptr if no DeclContext is found.

, which is not the node itself. (Is this the intended behavior? worth calling 
out either way)



Comment at: clang-tools-extra/clangd/Selection.h:105
+  // Get the DeclContext for the Node.
+  // Return nullptr if no DeclContext is found.
+  static const DeclContext *getDeclContext(const Node* CurrentNode);

Thinking about this again - this can't ever happen, it violates the invariant 
that a tree must be rooted at TranslationUnitDecl. Just return a reference and 
add an assert to the implementation.



Comment at: clang-tools-extra/clangd/Selection.h:106
+  // Return nullptr if no DeclContext is found.
+  static const DeclContext *getDeclContext(const Node* CurrentNode);
 

nit: I think this would be slightly clearer as a (non-static) member function 
on Node. (It also makes it obvious node can't be null).



Comment at: clang-tools-extra/clangd/Selection.h:106
+  // Return nullptr if no DeclContext is found.
+  static const DeclContext *getDeclContext(const Node* CurrentNode);
 

sammccall wrote:
> nit: I think this would be slightly clearer as a (non-static) member function 
> on Node. (It also makes it obvious node can't be null).
please run git clang-format.
(LLVM uses `type *var` not `type* var`)



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp:88
+
+  // if it's a function expression, return an error message
+  if (isa(*DeducedType) and

comment should say why
`// naively replacing 'auto' with the type will break declarations.`



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp:89
+  // if it's a function expression, return an error message
+  if (isa(*DeducedType) and
+  dyn_cast(*DeducedType)->isFunctionPointerType()) {

no need for this first check/cast: isFunctionPointerType is a member of Type



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp:90
+  if (isa(*DeducedType) and
+  dyn_cast(*DeducedType)->isFunctionPointerType()) {
+return createErrorMessage("Could not expand type of function pointer",

please also check isFunctionReferenceType, isMemberPointerType, isArrayType for 
the same reason



Comment at: clang-tools-extra/clangd/unittests/ASTTests.cpp:34
+
+  /* FIXME: template types are ignored right now, we should add this in the
+   * future

rather than commenting out the test, assert the (bad) behavior and keep the 
comment.
That way someone gets a happy surprise when they fix it :-)



Comment at: clang-tools-extra/clangd/unittests/ASTTests.cpp:42
+
+//FIXME: add tests for printType
+

[PATCH] D63161: Devirtualize destructor of final class.

2019-07-09 Thread Hiroshi Yamauchi via Phabricator via cfe-commits
yamauchi added a comment.

Recommitted as https://reviews.llvm.org/rL365509


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63161



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


[PATCH] D61466: [Rewrite][NFC] Add FIXMEs and tests for RemoveLineIfEmpty bug

2019-07-09 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 208795.
jdenny retitled this revision from "[Rewrite][NFC] Add FIXME about 
RemoveLineIfEmpty" to "[Rewrite][NFC] Add FIXMEs and tests for 
RemoveLineIfEmpty bug".
jdenny edited the summary of this revision.
jdenny added a comment.

Rebase, and add a unit test to demonstrate the bug.


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

https://reviews.llvm.org/D61466

Files:
  clang/include/clang/Rewrite/Core/Rewriter.h
  clang/lib/Rewrite/Rewriter.cpp
  clang/unittests/Rewrite/RewriteBufferTest.cpp

Index: clang/unittests/Rewrite/RewriteBufferTest.cpp
===
--- clang/unittests/Rewrite/RewriteBufferTest.cpp
+++ clang/unittests/Rewrite/RewriteBufferTest.cpp
@@ -14,6 +14,16 @@
 
 namespace {
 
+#define EXPECT_OUTPUT(Buf, Output) EXPECT_EQ(Output, writeOutput(Buf))
+
+static std::string writeOutput(const RewriteBuffer ) {
+  std::string Result;
+  raw_string_ostream OS(Result);
+  Buf.write(OS);
+  OS.flush();
+  return Result;
+}
+
 static void tagRange(unsigned Offset, unsigned Len, StringRef tagName,
  RewriteBuffer ) {
   std::string BeginTag;
@@ -40,11 +50,64 @@
   tagRange(Pos, TagStr.size(), "outer", Buf);
   tagRange(Pos, TagStr.size(), "inner", Buf);
 
-  std::string Result;
-  raw_string_ostream OS(Result);
-  Buf.write(OS);
-  OS.flush();
-  EXPECT_EQ(Output, Result);
+  EXPECT_OUTPUT(Buf, Output);
+}
+
+TEST(RewriteBuffer, DISABLED_RemoveLineIfEmpty_XFAIL) {
+  StringRef Input = "def\n"
+"ghi\n"
+"jkl\n";
+  RewriteBuffer Buf;
+  Buf.Initialize(Input);
+
+  // Insert "abc\n" at the start.
+  Buf.InsertText(0, "abc\n");
+  EXPECT_OUTPUT(Buf, "abc\n"
+ "def\n"
+ "ghi\n"
+ "jkl\n");
+
+  // Remove "def\n".
+  //
+  // After the removal of "def", we have:
+  //
+  //   "abc\n"
+  //   "\n"
+  //   "ghi\n"
+  //   "jkl\n"
+  //
+  // Because removeLineIfEmpty=true, RemoveText has to remove the "\n" left on
+  // the line.  This happens correctly for the rewrite buffer itself, so the
+  // next check below passes.
+  //
+  // However, RemoveText's implementation incorrectly records the delta for
+  // removing the "\n" using the rewrite buffer offset, 4, where it was
+  // supposed to use the original input offset, 3.  Interpreted as an original
+  // input offset, 4 points to "g" not to "\n".  Thus, any future modifications
+  // at the original input's "g" will incorrectly see "g" as having become an
+  // empty string and so will map to the next character, "h", in the rewrite
+  // buffer.
+  StringRef RemoveStr0 = "def";
+  Buf.RemoveText(Input.find(RemoveStr0), RemoveStr0.size(),
+ /*removeLineIfEmpty*/ true);
+  EXPECT_OUTPUT(Buf, "abc\n"
+ "ghi\n"
+ "jkl\n");
+
+  // Try to remove "ghi\n".
+  //
+  // As discussed above, the original input offset for "ghi\n" incorrectly
+  // maps to the rewrite buffer offset for "hi\nj", so we end up with:
+  //
+  //   "abc\n"
+  //   "gkl\n"
+  //
+  // To show that removeLineIfEmpty=true is the culprit, change true to false
+  // and append a newline to RemoveStr0 above.  The test then passes.
+  StringRef RemoveStr1 = "ghi\n";
+  Buf.RemoveText(Input.find(RemoveStr1), RemoveStr1.size());
+  EXPECT_OUTPUT(Buf, "abc\n"
+ "jkl\n");
 }
 
 } // anonymous namespace
Index: clang/lib/Rewrite/Rewriter.cpp
===
--- clang/lib/Rewrite/Rewriter.cpp
+++ clang/lib/Rewrite/Rewriter.cpp
@@ -96,6 +96,15 @@
 }
 if (posI != end() && *posI == '\n') {
   Buffer.erase(curLineStartOffs, lineSize + 1/* + '\n'*/);
+  // FIXME: Here, the offset of the start of the line is supposed to be
+  // expressed in terms of the original input not the "real" rewrite
+  // buffer.  How do we compute that reliably?  It might be tempting to use
+  // curLineStartOffs + OrigOffset - RealOffset, but that assumes the
+  // difference between the original and real offset is the same at the
+  // removed text and at the start of the line, but that's not true if
+  // edits were previously made earlier on the line.  This bug is also
+  // documented by a FIXME on the definition of
+  // clang::Rewriter::RewriteOptions::RemoveLineIfEmpty.
   AddReplaceDelta(curLineStartOffs, -(lineSize + 1/* + '\n'*/));
 }
   }
Index: clang/include/clang/Rewrite/Core/Rewriter.h
===
--- clang/include/clang/Rewrite/Core/Rewriter.h
+++ clang/include/clang/Rewrite/Core/Rewriter.h
@@ -46,6 +46,17 @@
 
 /// If true and removing some text leaves a blank line
 /// also remove the empty line (false by default).
+///
+/// FIXME: This sometimes corrupts the file's rewrite buffer due to
+/// incorrect indexing in the 

[PATCH] D64375: [OpenMP][Docs] Provide implementation status details

2019-07-09 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/docs/OpenMPSupport.rst:205
++--+--+--++
+| device extension | clause: device_type   
   | claimed  ||
++--+--+--++

kkwli0 wrote:
> ABataev wrote:
> > Can't find this in the standard.
> Section 2.12.7
Then it is unclaimed, I think.



Comment at: clang/docs/OpenMPSupport.rst:233
++--+--+--++
+| device extension | mapping lambda expression 
   | claimed  | D51107 |
++--+--+--++

kkwli0 wrote:
> ABataev wrote:
> > Done
> Do we support the behavior in 318:7-14?
Yes.



Comment at: clang/docs/OpenMPSupport.rst:237
++--+--+--++
+| device extension | map(replicate) or map(local) when requires 
unified_shared_me | done | D55719,D55892  |
++--+--+--++

kkwli0 wrote:
> ABataev wrote:
> > Not sure 100%, but seems to me it is not done.
> I think we still need the codegen patch and I am not sure about the runtime 
> part.
I don't think it works with unified memory since we don't fully support unified 
memory.



Comment at: clang/docs/OpenMPSupport.rst:243
++--+--+--++
+| atomic extension | hints for the atomic construct
   | done | D51233 |
++--+--+--++

kkwli0 wrote:
> ABataev wrote:
> > This is just the runtime part, the compiler does not support this
> Since it is a hint according to the specification, I guess it is up to us 
> whether we want to declare this feature done or not.  If we do that, we 
> should mention it in the limitation section.
Still, compiler does not use this. WE can mark this as partial, but definitely 
not done. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64375



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


[PATCH] D63908: hwasan: Improve precision of checks using short granule tags.

2019-07-09 Thread Peter Collingbourne via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365551: hwasan: Improve precision of checks using short 
granule tags. (authored by pcc, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D63908?vs=208758=208794#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63908

Files:
  cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst
  compiler-rt/trunk/lib/hwasan/hwasan_allocator.cpp
  compiler-rt/trunk/lib/hwasan/hwasan_checks.h
  compiler-rt/trunk/lib/hwasan/hwasan_flags.inc
  compiler-rt/trunk/lib/hwasan/hwasan_report.cpp
  compiler-rt/trunk/lib/hwasan/hwasan_report.h
  compiler-rt/trunk/test/hwasan/TestCases/heap-buffer-overflow.c
  compiler-rt/trunk/test/hwasan/TestCases/random-align-right.c
  compiler-rt/trunk/test/hwasan/TestCases/stack-oob.c
  compiler-rt/trunk/test/hwasan/TestCases/tail-magic.c
  llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp
  llvm/trunk/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
  llvm/trunk/test/CodeGen/AArch64/hwasan-check-memaccess.ll
  llvm/trunk/test/Instrumentation/HWAddressSanitizer/alloca-with-calls.ll
  llvm/trunk/test/Instrumentation/HWAddressSanitizer/alloca.ll
  llvm/trunk/test/Instrumentation/HWAddressSanitizer/basic.ll
  llvm/trunk/test/Instrumentation/HWAddressSanitizer/kernel-alloca.ll

Index: cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst
===
--- cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst
+++ cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst
@@ -38,6 +38,30 @@
 
 For a more detailed discussion of this approach see https://arxiv.org/pdf/1802.09517.pdf
 
+Short granules
+--
+
+A short granule is a granule of size between 1 and `TG-1` bytes. The size
+of a short granule is stored at the location in shadow memory where the
+granule's tag is normally stored, while the granule's actual tag is stored
+in the last byte of the granule. This means that in order to verify that a
+pointer tag matches a memory tag, HWASAN must check for two possibilities:
+
+* the pointer tag is equal to the memory tag in shadow memory, or
+* the shadow memory tag is actually a short granule size, the value being loaded
+  is in bounds of the granule and the pointer tag is equal to the last byte of
+  the granule.
+
+Pointer tags between 1 to `TG-1` are possible and are as likely as any other
+tag. This means that these tags in memory have two interpretations: the full
+tag interpretation (where the pointer tag is between 1 and `TG-1` and the
+last byte of the granule is ordinary data) and the short tag interpretation
+(where the pointer tag is stored in the granule).
+
+When HWASAN detects an error near a memory tag between 1 and `TG-1`, it
+will show both the memory tag and the last byte of the granule. Currently,
+it is up to the user to disambiguate the two possibilities.
+
 Instrumentation
 ===
 
@@ -46,24 +70,40 @@
 All memory accesses are prefixed with an inline instruction sequence that
 verifies the tags. Currently, the following sequence is used:
 
-
 .. code-block:: none
 
   // int foo(int *a) { return *a; }
-  // clang -O2 --target=aarch64-linux -fsanitize=hwaddress -c load.c
+  // clang -O2 --target=aarch64-linux -fsanitize=hwaddress -fsanitize-recover=hwaddress -c load.c
   foo:
-   0:	08 00 00 90 	adrp	x8, 0 <__hwasan_shadow>
-   4:	08 01 40 f9 	ldr	x8, [x8]  // shadow base (to be resolved by the loader)
-   8:	09 dc 44 d3 	ubfx	x9, x0, #4, #52 // shadow offset
-   c:	28 69 68 38 	ldrb	w8, [x9, x8]// load shadow tag
-  10:	09 fc 78 d3 	lsr	x9, x0, #56   // extract address tag
-  14:	3f 01 08 6b 	cmp	w9, w8// compare tags
-  18:	61 00 00 54 	b.ne	24  // jump on mismatch
-  1c:	00 00 40 b9 	ldr	w0, [x0]  // original load
-  20:	c0 03 5f d6 	ret
-  24:	40 20 21 d4 	brk	#0x902// trap
+   0:	9008 	adrp	x8, 0 <__hwasan_shadow>
+   4:	f9400108 	ldr	x8, [x8] // shadow base (to be resolved by the loader)
+   8:	d344dc09 	ubfx	x9, x0, #4, #52  // shadow offset
+   c:	38696909 	ldrb	w9, [x8, x9] // load shadow tag
+  10:	d378fc08 	lsr	x8, x0, #56  // extract address tag
+  14:	6b09011f 	cmp	w8, w9   // compare tags
+  18:	5461 	b.ne	24 // jump to short tag handler on mismatch
+  1c:	b940 	ldr	w0, [x0] // original load
+  20:	d65f03c0 	ret
+  24:	7100413f 	cmp	w9, #0x10// is this a short tag?
+  28:	54000142 	b.cs	50 // if not, trap
+  2c:	12000c0a 	and	w10, w0, #0xf// find the address's position in the short granule
+  30:	11000d4a 	add	w10, w10, #0x3   // adjust to the position of the last byte loaded
+  34:	6b09015f 	cmp	w10, w9  // check that position is 

r365551 - hwasan: Improve precision of checks using short granule tags.

2019-07-09 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Jul  9 13:22:36 2019
New Revision: 365551

URL: http://llvm.org/viewvc/llvm-project?rev=365551=rev
Log:
hwasan: Improve precision of checks using short granule tags.

A short granule is a granule of size between 1 and `TG-1` bytes. The size
of a short granule is stored at the location in shadow memory where the
granule's tag is normally stored, while the granule's actual tag is stored
in the last byte of the granule. This means that in order to verify that a
pointer tag matches a memory tag, HWASAN must check for two possibilities:

* the pointer tag is equal to the memory tag in shadow memory, or
* the shadow memory tag is actually a short granule size, the value being loaded
  is in bounds of the granule and the pointer tag is equal to the last byte of
  the granule.

Pointer tags between 1 to `TG-1` are possible and are as likely as any other
tag. This means that these tags in memory have two interpretations: the full
tag interpretation (where the pointer tag is between 1 and `TG-1` and the
last byte of the granule is ordinary data) and the short tag interpretation
(where the pointer tag is stored in the granule).

When HWASAN detects an error near a memory tag between 1 and `TG-1`, it
will show both the memory tag and the last byte of the granule. Currently,
it is up to the user to disambiguate the two possibilities.

Because this functionality obsoletes the right aligned heap feature of
the HWASAN memory allocator (and because we can no longer easily test
it), the feature is removed.

Also update the documentation to cover both short granule tags and
outlined checks.

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

Modified:
cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst

Modified: cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst?rev=365551=365550=365551=diff
==
--- cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst (original)
+++ cfe/trunk/docs/HardwareAssistedAddressSanitizerDesign.rst Tue Jul  9 
13:22:36 2019
@@ -38,6 +38,30 @@ Algorithm
 
 For a more detailed discussion of this approach see 
https://arxiv.org/pdf/1802.09517.pdf
 
+Short granules
+--
+
+A short granule is a granule of size between 1 and `TG-1` bytes. The size
+of a short granule is stored at the location in shadow memory where the
+granule's tag is normally stored, while the granule's actual tag is stored
+in the last byte of the granule. This means that in order to verify that a
+pointer tag matches a memory tag, HWASAN must check for two possibilities:
+
+* the pointer tag is equal to the memory tag in shadow memory, or
+* the shadow memory tag is actually a short granule size, the value being 
loaded
+  is in bounds of the granule and the pointer tag is equal to the last byte of
+  the granule.
+
+Pointer tags between 1 to `TG-1` are possible and are as likely as any other
+tag. This means that these tags in memory have two interpretations: the full
+tag interpretation (where the pointer tag is between 1 and `TG-1` and the
+last byte of the granule is ordinary data) and the short tag interpretation
+(where the pointer tag is stored in the granule).
+
+When HWASAN detects an error near a memory tag between 1 and `TG-1`, it
+will show both the memory tag and the last byte of the granule. Currently,
+it is up to the user to disambiguate the two possibilities.
+
 Instrumentation
 ===
 
@@ -46,24 +70,40 @@ Memory Accesses
 All memory accesses are prefixed with an inline instruction sequence that
 verifies the tags. Currently, the following sequence is used:
 
-
 .. code-block:: none
 
   // int foo(int *a) { return *a; }
-  // clang -O2 --target=aarch64-linux -fsanitize=hwaddress -c load.c
+  // clang -O2 --target=aarch64-linux -fsanitize=hwaddress 
-fsanitize-recover=hwaddress -c load.c
   foo:
-   0:  08 00 00 90 adrpx8, 0 <__hwasan_shadow>
-   4:  08 01 40 f9 ldr x8, [x8]  // shadow base (to be 
resolved by the loader)
-   8:  09 dc 44 d3 ubfxx9, x0, #4, #52 // shadow offset
-   c:  28 69 68 38 ldrbw8, [x9, x8]// load shadow tag
-  10:  09 fc 78 d3 lsr x9, x0, #56   // extract address tag
-  14:  3f 01 08 6b cmp w9, w8// compare tags
-  18:  61 00 00 54 b.ne24  // jump on mismatch
-  1c:  00 00 40 b9 ldr w0, [x0]  // original load
-  20:  c0 03 5f d6 ret
-  24:  40 20 21 d4 brk #0x902// trap
+   0:  9008adrpx8, 0 <__hwasan_shadow>
+   4:  f9400108ldr x8, [x8] // shadow base (to be 
resolved by the loader)
+   8:  d344dc09ubfxx9, x0, #4, #52  // shadow offset
+   c:  38696909

[PATCH] D64418: [Docs][OpenCL] Documentation of C++ for OpenCL mode

2019-07-09 Thread Ronan Keryell via Phabricator via cfe-commits
keryell added a comment.

Good improvement!




Comment at: docs/LanguageExtensions.rst:1758
+to enqueue constructor initialization kernel that has a name
+``@_GLOBAL__sub_I_``. This kernel is only present if there
+are any global objects to be initialized in the compiled binary. One way to

"https://reviews.llvm.org/D64418/new/

https://reviews.llvm.org/D64418



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


[PATCH] D64375: [OpenMP][Docs] Provide implementation status details

2019-07-09 Thread Kelvin Li via Phabricator via cfe-commits
kkwli0 added inline comments.



Comment at: clang/docs/OpenMPSupport.rst:205
++--+--+--++
+| device extension | clause: device_type   
   | claimed  ||
++--+--+--++

ABataev wrote:
> Can't find this in the standard.
Section 2.12.7



Comment at: clang/docs/OpenMPSupport.rst:233
++--+--+--++
+| device extension | mapping lambda expression 
   | claimed  | D51107 |
++--+--+--++

ABataev wrote:
> Done
Do we support the behavior in 318:7-14?



Comment at: clang/docs/OpenMPSupport.rst:237
++--+--+--++
+| device extension | map(replicate) or map(local) when requires 
unified_shared_me | done | D55719,D55892  |
++--+--+--++

ABataev wrote:
> Not sure 100%, but seems to me it is not done.
I think we still need the codegen patch and I am not sure about the runtime 
part.



Comment at: clang/docs/OpenMPSupport.rst:243
++--+--+--++
+| atomic extension | hints for the atomic construct
   | done | D51233 |
++--+--+--++

ABataev wrote:
> This is just the runtime part, the compiler does not support this
Since it is a hint according to the specification, I guess it is up to us 
whether we want to declare this feature done or not.  If we do that, we should 
mention it in the limitation section.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64375



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


[PATCH] D63663: [clang-doc] Add html links to references

2019-07-09 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:567
+  ParentI->Namespace = llvm::SmallVector(
+  Enum.Namespace.begin() + 1, Enum.Namespace.end());
+  ParentI->Path = getInfoOutputFile(OutDirectory, ParentI->Namespace);

juliehockett wrote:
> nit: use `++Enum.Namespace.begin()`
++ operator cannot be used in that expression because it's not assignable.


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

https://reviews.llvm.org/D63663



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


[PATCH] D63857: [clang-doc] Add a structured HTML generator

2019-07-09 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 208792.

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

https://reviews.llvm.org/D63857

Files:
  clang-tools-extra/clang-doc/CMakeLists.txt
  clang-tools-extra/clang-doc/Generators.cpp
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -0,0 +1,276 @@
+//===-- clang-doc/HTMLGeneratorTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+std::unique_ptr getHTMLGenerator() {
+  auto G = doc::findGeneratorByName("html");
+  if (!G)
+return nullptr;
+  return std::move(G.get());
+}
+
+TEST(HTMLGeneratorTest, emitNamespaceHTML) {
+  NamespaceInfo I;
+  I.Name = "Namespace";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
+ InfoType::IT_namespace);
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getHTMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual);
+  assert(!Err);
+  std::string Expected = R"raw(
+
+namespace Namespace
+
+  namespace Namespace
+  Namespaces
+  
+ChildNamespace
+  
+  Records
+  
+ChildStruct
+  
+  Functions
+  
+OneFunction
+
+   OneFunction()
+
+  
+  Enums
+  
+enum OneEnum
+  
+
+)raw";
+
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(HTMLGeneratorTest, emitRecordHTML) {
+  RecordInfo I;
+  I.Name = "r";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
+
+  I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
+  I.TagType = TagTypeKind::TTK_Class;
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
+  I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getHTMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual);
+  assert(!Err);
+  std::string Expected = R"raw(
+
+class r
+
+  class r
+  
+Defined at line 10 of test.cpp
+  
+  
+Inherits from F, G
+  
+  Members
+  
+private int X
+  
+  Records
+  
+ChildStruct
+  
+  Functions
+  
+OneFunction
+
+   OneFunction()
+
+  
+  Enums
+  
+enum OneEnum
+  
+
+)raw";
+
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(HTMLGeneratorTest, emitFunctionHTML) {
+  FunctionInfo I;
+  I.Name = "f";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
+
+  I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+  I.Params.emplace_back("int", "P");
+  I.IsMethod = true;
+  I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
+
+  auto G = getHTMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual);
+  assert(!Err);
+  std::string Expected = R"raw(
+
+
+
+  f
+  
+void f(int P)
+  
+  
+Defined at line 10 of test.cpp
+  
+
+)raw";
+
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(HTMLGeneratorTest, emitEnumHTML) {
+  EnumInfo I;
+  I.Name = "e";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
+
+  I.Members.emplace_back("X");
+  I.Scoped = true;
+
+  auto G = getHTMLGenerator();
+  assert(G);
+  std::string Buffer;
+ 

[PATCH] D64283: [PowerPC] Support -mabi=ieeelongdouble and -mabi=ibmlongdouble

2019-07-09 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

Ah, fun with overloaded, legacy command-line options...




Comment at: lib/Driver/ToolChains/Clang.cpp:1825
+  // that don't use the altivec abi.
+  if (!SeenOther)
+ABIName = A->getValue();

This seems like an unintentional behavior change on top of the existing 
behavior (which may have also been not quite right). As best I can tell, we're 
trying to set ABIName equal to the last ABI type specified, unless that type is 
"altivec", in which case the ABI name should be its default value (either a 
nullptr or something like "elfv2"). With this change, we'll now take the first 
ABI name seen, not the last (as we'll get SeenOther to true after the first 
name).

Maybe we should loop over the list multiple times, once to get the long-double 
format, once to get the basic ABI name (where we save the default, and then if 
the last name found is "altivec", then reset to the default)?



Repository:
  rC Clang

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

https://reviews.llvm.org/D64283



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


[PATCH] D63908: hwasan: Improve precision of checks using short granule tags.

2019-07-09 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63908



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


[PATCH] D63663: [clang-doc] Add html links to references

2019-07-09 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 208789.
DiegoAstiazaran marked 5 inline comments as done.
DiegoAstiazaran added a comment.

The info path generated in serialization was the composite of the out directory 
and the parent namespaces. Now it's only the parent namespaces; the out 
directory path is appended until the directory is actually created in the doc 
generation phase.


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

https://reviews.llvm.org/D63663

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.h
  clang-tools-extra/clang-doc/Generators.cpp
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -57,7 +57,8 @@
   
 OneFunction
 
-   OneFunction()
+  OneFunction(
+  )
 
   
   Enums
@@ -78,9 +79,10 @@
   I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
-  I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
+  I.Members.emplace_back("int", "/path/to", "X", AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
-  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record,
+ llvm::SmallString<128>("/path/to"));
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
 
   I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
@@ -104,11 +106,14 @@
 Defined at line 10 of test.cpp
   
   
-Inherits from F, G
+Inherits from 
+F
+, 
+G
   
   Members
   
-private int X
+private int X
   
   Records
   
@@ -118,7 +123,8 @@
   
 OneFunction
 
-   OneFunction()
+  OneFunction(
+  )
 
   
   Enums
@@ -139,8 +145,8 @@
   I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
-  I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
-  I.Params.emplace_back("int", "P");
+  I.ReturnType = TypeInfo(EmptySID, "float", InfoType::IT_default, "/path/to");
+  I.Params.emplace_back("int", "/path/to", "P");
   I.IsMethod = true;
   I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
 
@@ -156,7 +162,12 @@
 
   f
   
-void f(int P)
+float
+ 
+f(
+int
+ P
+)
   
   
 Defined at line 10 of test.cpp
@@ -250,7 +261,15 @@
 
   f
   
-void f(int I, int J)
+void
+ 
+f(
+int
+ I
+, 
+int
+ J
+)
   
   
 Defined at line 10 of test.cpp
Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -110,12 +110,13 @@
   return false;
 }
 
-// A function to extract the appropriate path name for a given info's
-// documentation. The path returned is a composite of the parent namespaces as
-// directories plus the decl name as the filename.
+// A function to extract the appropriate file name for a given info's
+// documentation. The path returned is a composite of the output directory, the
+// info's relative path and name and the extension. The relative path should
+// have been constructed in the serialization phase.
 //
-// Example: Given the below, the  path for class C will be <
-// root>/A/B/C.
+// Example: Given the below, the  path for class C will be
+// /A/B/C.
 //
 // namespace A {
 // namesapce B {
@@ -124,16 +125,14 @@
 //
 // }
 // }
-llvm::Expected>
-getInfoOutputFile(StringRef Root,
-  llvm::SmallVectorImpl ,
-  StringRef Name, StringRef Ext) {
+llvm::Expected> getInfoOutputFile(StringRef Root,
+ StringRef RelativePath,
+ StringRef Name,
+ StringRef Ext) {
   std::error_code OK;
   llvm::SmallString<128> Path;
   llvm::sys::path::native(Root, Path);
-  for (auto R = Namespaces.rbegin(), E = Namespaces.rend(); R != E; ++R)
-llvm::sys::path::append(Path, R->Name);
-
+  llvm::sys::path::append(Path, RelativePath);
   if (CreateDirectory(Path))
 return 

[PATCH] D64089: [Driver] Introduce -stdlib++-isystem

2019-07-09 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In D64089#1576902 , @ldionne wrote:

> Background question: I'm familiar with the behavior on Darwin, where we 
> prefer C++ headers in the toolchain (alongside the driver), however do other 
> platforms behave the same? I thought this was something specific to Darwin.


The Linux toolchain (which is used for non-GNU Linux targets, e.g. Android) 
also prefers C++ headers in the toolchain: 
https://github.com/llvm/llvm-project/blob/a6548d04375b49da989103c403d83475cc2f8ce4/clang/lib/Driver/ToolChains/Linux.cpp#L891.
 There's a FIXME in the GCC toolchain to adopt that behavior too: 
https://github.com/llvm/llvm-project/blob/a6548d04375b49da989103c403d83475cc2f8ce4/clang/lib/Driver/ToolChains/Gnu.cpp#L2619


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64089



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


[PATCH] D64089: [Driver] Introduce -stdlib++-isystem

2019-07-09 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

Background question: I'm familiar with the behavior on Darwin, where we prefer 
C++ headers in the toolchain (alongside the driver), however do other platforms 
behave the same? I thought this was something specific to Darwin.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64089



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


[PATCH] D63085: Provide a fix-it hint for -Wswitch, which adds missing cases. If there are >3 cases, the inserted text will contain newlines so it will not be shown in console output (but will be appl

2019-07-09 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Ping... it'd be nice to have for clangd-9, though it's getting late.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63085



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


[PATCH] D63098: [CodeComplete] Allow completing enum values within case statements, and insert 'case' as a fixit.

2019-07-09 Thread Sam McCall via Phabricator via cfe-commits
sammccall planned changes to this revision.
sammccall added a comment.

I'll give this a try. I expect it to feel quite glitchy when the enum type has 
a long name.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63098



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


[PATCH] D63894: [CXX] Exercise all paths through these tests

2019-07-09 Thread Paul Robinson via Phabricator via cfe-commits
probinson marked an inline comment as done.
probinson added inline comments.



Comment at: clang/test/SemaCXX/linkage2.cpp:3
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions 
-Wno-local-type-template-args %s -std=gnu++98
 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions 
-Wno-local-type-template-args -fmodules %s
 

rsmith wrote:
> Should this one be run in C++98 mode too? (The use of `-Wno-c++11-extensions` 
> suggests to me that C++98 was expected.)
I don't think so; `-Wno-c++11-extensions` will not suppress diagnostics about 
GNU extensions.  I think GNU++98 is what's wanted here (and is the old default 
dialect).


Repository:
  rC Clang

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

https://reviews.llvm.org/D63894



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


[PATCH] D64271: [analyzer] Don't track the right hand side of the last store for conditions

2019-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I'd rather not abandon this patch, because it looks like a strict improvement 
over the lack of condition tracking, and it might as well still be an 
improvement over "zealous" condition tracking, as my counterexample is fairly 
artificial. It indicates that a slightly more sophisticated algorithm is 
necessary (i'm not sure if it's single-pass or even linear). But i'll be 
perfectly happy with simply adding it as a FIXME test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64271



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


[PATCH] D64287: [analyzer] Track the right hand side of the last store regardless of its value

2019-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Whoa, the new notes are amazing. Looks like you've found a pretty bad omission.




Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1436-1437
-}
-ReturnVisitor::addVisitorIfNecessary(StoreSite, InitE->IgnoreParenCasts(),
- BR, EnableNullFPSuppression);
   }

You're removing this visitor, does it cause any removal of notes?



Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1989-1991
+}
+else if (const auto *AR = L->getRegionAs())
+  CanDereference = false;

Fair enough. Did we already have a test case for this? I wonder if function 
pointers might also cause problems here.

Ugh, this code is so underdebugged.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64287



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


[PATCH] D61749: [clang-tidy] initial version of readability-static-const-method

2019-07-09 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre updated this revision to Diff 208785.
mgehre added a comment.

Move checks into AST matchers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61749

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/StaticMethodCheck.cpp
  clang-tools-extra/clang-tidy/readability/StaticMethodCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-static-method.rst
  clang-tools-extra/test/clang-tidy/readability-static-method.cpp

Index: clang-tools-extra/test/clang-tidy/readability-static-method.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-static-method.cpp
@@ -0,0 +1,195 @@
+// RUN: %check_clang_tidy %s readability-static-method %t
+
+class DoNotMakeEmptyStatic {
+  void emptyMethod() {}
+  void empty_method_out_of_line();
+};
+
+void DoNotMakeEmptyStatic::empty_method_out_of_line() {}
+
+class A {
+  int field;
+  const int const_field;
+  static int static_field;
+
+  void no_use() {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'no_use' can be made static
+// CHECK-FIXES: {{^}}  static void no_use() {
+int i = 1;
+  }
+
+  int read_field() {
+return field;
+  }
+
+  void write_field() {
+field = 1;
+  }
+
+  int call_non_const_member() { return read_field(); }
+
+  int call_static_member() {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'call_static_member' can be made static
+// CHECK-FIXES: {{^}}  static int call_static_member() {
+already_static();
+  }
+
+  int read_static() {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'read_static' can be made static
+// CHECK-FIXES: {{^}}  static int read_static() {
+return static_field;
+  }
+  void write_static() {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'write_static' can be made static
+// CHECK-FIXES: {{^}}  static void write_static() {
+static_field = 1;
+  }
+
+  static int already_static() { return static_field; }
+
+  int already_const() const { return field; }
+
+  int already_const_convert_to_static() const {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'already_const_convert_to_static' can be made static
+// CHECK-FIXES: {{^}}  static int already_const_convert_to_static() {
+return static_field;
+  }
+
+  static int out_of_line_already_static();
+
+  void out_of_line_call_static();
+  // CHECK-FIXES: {{^}}  static void out_of_line_call_static();
+  int out_of_line_const_to_static() const;
+  // CHECK-FIXES: {{^}}  static int out_of_line_const_to_static() ;
+};
+
+int A::out_of_line_already_static() { return 0; }
+
+void A::out_of_line_call_static() {
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: method 'out_of_line_call_static' can be made static
+  // CHECK-FIXES: {{^}}void A::out_of_line_call_static() {
+  already_static();
+}
+
+int A::out_of_line_const_to_static() const {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'out_of_line_const_to_static' can be made static
+  // CHECK-FIXES: {{^}}int A::out_of_line_const_to_static() {
+  return 0;
+}
+
+struct KeepVirtual {
+  virtual int f() { return 0; }
+  virtual int h() const { return 0; }
+};
+
+struct KeepVirtualDerived : public KeepVirtual {
+  int f() { return 0; }
+  int h() const override { return 0; }
+};
+
+// Don't add 'static' to special member functions and operators.
+struct KeepSpecial {
+  KeepSpecial() { int L = 0; }
+  ~KeepSpecial() { int L = 0; }
+  int operator+() { return 0; }
+  operator int() { return 0; }
+};
+
+void KeepLambdas() {
+  using FT = int (*)();
+  auto F = static_cast([]() { return 0; });
+  auto F2 = []() { return 0; };
+}
+
+template 
+struct KeepWithTemplateBase : public Base {
+  int i;
+  // We cannot make these methods static because they might need to override
+  // a function from Base.
+  int static_f() { return 0; }
+};
+
+template 
+struct KeepTemplateClass {
+  int i;
+  // We cannot make these methods static because a specialization
+  // might use *this differently.
+  int static_f() { return 0; }
+};
+
+struct KeepTemplateMethod {
+  int i;
+  // We cannot make these methods static because a specialization
+  // might use *this differently.
+  template 
+  static int static_f() { return 0; }
+};
+
+void instantiate() {
+  struct S {};
+  KeepWithTemplateBase I1;
+  I1.static_f();
+
+  KeepTemplateClass I2;
+  I2.static_f();
+
+  KeepTemplateMethod I3;
+  I3.static_f();
+}
+
+struct Trailing {
+  auto g() const -> int {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'g' can be made static
+// CHECK-FIXES: {{^}}  static auto g() -> int {
+return 0;
+  }
+
+  void vol() volatile {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 

[PATCH] D64356: [OPENMP]Initial fix PR42392: Improve -Wuninitialized warnings for OpenMP programs.

2019-07-09 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D64356#1576813 , @NoQ wrote:

> Something like this:
>
> F9509417: photo_2019-07-09_12-21-46.jpg 
>
> Like, you can construct a CFG for an arbitrary statement. CFG₁ is the CFG for 
> xxx() and CFG₂ is the CFG for the CapturedStmt (and its children). I'm trying 
> to say that even if used expressions are duplicated in the AST, they should 
> not be duplicated in our CFGs.
>
> But that's more, like, for the future patches. I'll be happy to accept this 
> patch once you add CFG tests :)


I don't expect such duplication here. Those expressions associated with the 
directive have no relation with the CapturedStmt. They are associated only with 
the directive itself through the OpenMP clauses.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64356



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


[PATCH] D64317: [Driver] Add float-divide-by-zero back to supported sanitizers after D63793/rC365272

2019-07-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D64317



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


[PATCH] D63894: [CXX] Exercise all paths through these tests

2019-07-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/SemaCXX/linkage2.cpp:3
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions 
-Wno-local-type-template-args %s -std=gnu++98
 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions 
-Wno-local-type-template-args -fmodules %s
 

Should this one be run in C++98 mode too? (The use of `-Wno-c++11-extensions` 
suggests to me that C++98 was expected.)


Repository:
  rC Clang

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

https://reviews.llvm.org/D63894



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


[PATCH] D64423: [OpenMP] Simplify getFloatTypeSemantics

2019-07-09 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365545: [OpenMP] Simplify getFloatTypeSemantics (authored by 
MaskRay, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64423

Files:
  cfe/trunk/lib/AST/ASTContext.cpp


Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -1525,13 +1525,11 @@
   case BuiltinType::Float:  return Target->getFloatFormat();
   case BuiltinType::Double: return Target->getDoubleFormat();
   case BuiltinType::LongDouble:
-if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
->getLongDoubleFormat() != >getLongDoubleFormat())
+if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
   return AuxTarget->getLongDoubleFormat();
 return Target->getLongDoubleFormat();
   case BuiltinType::Float128:
-if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
->getFloat128Format() != >getFloat128Format())
+if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
   return AuxTarget->getFloat128Format();
 return Target->getFloat128Format();
   }


Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -1525,13 +1525,11 @@
   case BuiltinType::Float:  return Target->getFloatFormat();
   case BuiltinType::Double: return Target->getDoubleFormat();
   case BuiltinType::LongDouble:
-if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
->getLongDoubleFormat() != >getLongDoubleFormat())
+if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
   return AuxTarget->getLongDoubleFormat();
 return Target->getLongDoubleFormat();
   case BuiltinType::Float128:
-if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
->getFloat128Format() != >getFloat128Format())
+if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
   return AuxTarget->getFloat128Format();
 return Target->getFloat128Format();
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r365545 - [OpenMP] Simplify getFloatTypeSemantics

2019-07-09 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Tue Jul  9 12:36:22 2019
New Revision: 365545

URL: http://llvm.org/viewvc/llvm-project?rev=365545=rev
Log:
[OpenMP] Simplify getFloatTypeSemantics

When the float point representations are the same on the host and on the target 
device,
(`>getLongDoubleFormat() == >getLongDoubleFormat()`),
we can just use `AuxTarget->getLongDoubleFormat()`.

Reviewed By: ABataev

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

Modified:
cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=365545=365544=365545=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jul  9 12:36:22 2019
@@ -1525,13 +1525,11 @@ const llvm::fltSemantics ::ge
   case BuiltinType::Float:  return Target->getFloatFormat();
   case BuiltinType::Double: return Target->getDoubleFormat();
   case BuiltinType::LongDouble:
-if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
->getLongDoubleFormat() != >getLongDoubleFormat())
+if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
   return AuxTarget->getLongDoubleFormat();
 return Target->getLongDoubleFormat();
   case BuiltinType::Float128:
-if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
->getFloat128Format() != >getFloat128Format())
+if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
   return AuxTarget->getFloat128Format();
 return Target->getFloat128Format();
   }


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


Re: [libunwind] r364217 - Merging r360861:

2019-07-09 Thread Tom Stellard via cfe-commits
On 07/09/2019 12:28 PM, Dimitry Andric wrote:
> On 9 Jul 2019, at 04:54, Tom Stellard  wrote:
>>
>> On 07/08/2019 11:51 AM, Dimitry Andric wrote:
>>> On 24 Jun 2019, at 20:40, Tom Stellard via cfe-commits 
>>>  wrote:

 Author: tstellar
 Date: Mon Jun 24 11:40:58 2019
 New Revision: 364217

 URL: http://llvm.org/viewvc/llvm-project?rev=364217=rev
 Log:
 Merging r360861:

 
 r360861 | mstorsjo | 2019-05-15 23:49:13 -0700 (Wed, 15 May 2019) | 13 
 lines

 [PPC64][libunwind] Fix r2 not properly restored
>>> 
 Modified: libunwind/branches/release_80/src/assembly.h
 URL: 
 http://llvm.org/viewvc/llvm-project/libunwind/branches/release_80/src/assembly.h?rev=364217=364216=364217=diff
 ==
 --- libunwind/branches/release_80/src/assembly.h (original)
 +++ libunwind/branches/release_80/src/assembly.h Mon Jun 24 11:40:58 2019
 @@ -35,6 +35,20 @@
 #define SEPARATOR ;
 #endif

 +#if defined(__powerpc64__) && (!defined(_CALL_ELF) || _CALL_ELF == 1)
 +#define PPC64_OPD1 .section .opd,"aw",@progbits SEPARATOR
 +#define PPC64_OPD2 SEPARATOR \
 +  .p2align 3 SEPARATOR \
 +  .quad .Lfunc_begin0 SEPARATOR \
 +  .quad .TOC.@tocbase SEPARATOR \
 +  .quad 0 SEPARATOR \
 +  .text SEPARATOR \
 +.Lfunc_begin0:
 +#else
 +#define PPC64_OPD1
 +#define PPC64_OPD2
 +#endif
 +
 #define GLUE2(a, b) a ## b
 #define GLUE(a, b) GLUE2(a, b)
 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
 @@ -95,7 +109,9 @@
  .globl SYMBOL_NAME(name) SEPARATOR  \
  EXPORT_SYMBOL(name) SEPARATOR   \
  SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
 -  SYMBOL_NAME(name):
 +  PPC64_OPD1  \
 +  SYMBOL_NAME(name):  \
 +  PPC64_OPD2

 #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name)   \
  .globl SYMBOL_NAME(name) SEPARATOR  \

>>>
>>> I think this merge missed that the DEFINE_LIBUNWIND_PRIVATE_FUNCTION
>>> macro went away in r357640 ("[libunwind] Export the unw_* symbols as
>>> weak symbols").
>>>
>>> It looks like the PPC64_OPD1 and PPC64_OPD2 lines should also be added
>>> to the expansion of DEFINE_LIBUNWIND_PRIVATE_FUNCTION?
>>>
>>
>> Is someone else able to try to remerge and fix this up?  I don't have
>> a good way to test this.  If we can't get this resolved by Wednesday,
>> I am going to revert it, because it's the only thing blocking the release
>> at this point.
> 
> I reverted the merge in https://reviews.llvm.org/rL365539, and reapplied
> it with the additional lines in https://reviews.llvm.org/rL365542.  I
> hope you don't mind.
> 
> This is also going to end up in the next merge to FreeBSD's libunwind.
> 

Ok, thank you.

-Tom

> -Dimitry
> 

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


[PATCH] D64423: [OpenMP] Simplify getFloatTypeSemantics

2019-07-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 208780.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Update description


Repository:
  rC Clang

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

https://reviews.llvm.org/D64423

Files:
  lib/AST/ASTContext.cpp


Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -1525,13 +1525,11 @@
   case BuiltinType::Float:  return Target->getFloatFormat();
   case BuiltinType::Double: return Target->getDoubleFormat();
   case BuiltinType::LongDouble:
-if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
->getLongDoubleFormat() != >getLongDoubleFormat())
+if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
   return AuxTarget->getLongDoubleFormat();
 return Target->getLongDoubleFormat();
   case BuiltinType::Float128:
-if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
->getFloat128Format() != >getFloat128Format())
+if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
   return AuxTarget->getFloat128Format();
 return Target->getFloat128Format();
   }


Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -1525,13 +1525,11 @@
   case BuiltinType::Float:  return Target->getFloatFormat();
   case BuiltinType::Double: return Target->getDoubleFormat();
   case BuiltinType::LongDouble:
-if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
->getLongDoubleFormat() != >getLongDoubleFormat())
+if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
   return AuxTarget->getLongDoubleFormat();
 return Target->getLongDoubleFormat();
   case BuiltinType::Float128:
-if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
->getFloat128Format() != >getFloat128Format())
+if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
   return AuxTarget->getFloat128Format();
 return Target->getFloat128Format();
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63279: [Analyzer] Unroll for-loops where the upper boundary is a variable with know value

2019-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Core/LoopUnrolling.cpp:214-216
+  const Expr *BoundExpr = CondOp->getLHS()->IgnoreParenImpCasts();
+  if (BoundExpr == Matches[0].getNodeAs("boundVarOperand"))
+BoundExpr = CondOp->getRHS()->IgnoreParenImpCasts();

Szelethus wrote:
> Alright, I stood on top of this for longer than I'd like to admit, what's 
> happening here? Like, `CondExpr`, with the given testfile, should be `i < n`, 
> right? Then `BoundExpr` is supposed to be `i`, and if that is equal to 
> `Matches[0].getNodeAs("boundVarOperand")` (which I guess is supposed to 
> `n`), which I'm not sure how it could ever happen, we assign the RHS of the 
> assignment to `BoundExpr`?
> 
> What does this do? Why is it needed? Which 2 test cases cover these lines?
I think this is about `i < n` vs. `n > i`.



Comment at: lib/StaticAnalyzer/Core/LoopUnrolling.cpp:221-230
+  if (BoundNumVal.isUnknown()) {
+if (const auto *BoundDeclRefExpr = dyn_cast(BoundExpr)) {
+  // FIXME: Add other declarations such as Objective-C fields
+  if (const auto *BoundVarDecl =
+  dyn_cast(BoundDeclRefExpr->getDecl())) {
+BoundNumVal = State->getSVal(
+State->getLValue(BoundVarDecl, Pred->getLocationContext()));

Szelethus wrote:
> I don't see obvious test case for which `BoundNumVal` would be unknown, am I 
> wrong?
We need an `ExprInspection` method that reliably produces an `UnknownVal`, 
because there's no truly valid reason to produce `UnknownVal` apart from 
"something is unimplemented".


Repository:
  rC Clang

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

https://reviews.llvm.org/D63279



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


Re: [libunwind] r364217 - Merging r360861:

2019-07-09 Thread Dimitry Andric via cfe-commits
On 9 Jul 2019, at 04:54, Tom Stellard  wrote:
> 
> On 07/08/2019 11:51 AM, Dimitry Andric wrote:
>> On 24 Jun 2019, at 20:40, Tom Stellard via cfe-commits 
>>  wrote:
>>> 
>>> Author: tstellar
>>> Date: Mon Jun 24 11:40:58 2019
>>> New Revision: 364217
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=364217=rev
>>> Log:
>>> Merging r360861:
>>> 
>>> 
>>> r360861 | mstorsjo | 2019-05-15 23:49:13 -0700 (Wed, 15 May 2019) | 13 lines
>>> 
>>> [PPC64][libunwind] Fix r2 not properly restored
>> 
>>> Modified: libunwind/branches/release_80/src/assembly.h
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/libunwind/branches/release_80/src/assembly.h?rev=364217=364216=364217=diff
>>> ==
>>> --- libunwind/branches/release_80/src/assembly.h (original)
>>> +++ libunwind/branches/release_80/src/assembly.h Mon Jun 24 11:40:58 2019
>>> @@ -35,6 +35,20 @@
>>> #define SEPARATOR ;
>>> #endif
>>> 
>>> +#if defined(__powerpc64__) && (!defined(_CALL_ELF) || _CALL_ELF == 1)
>>> +#define PPC64_OPD1 .section .opd,"aw",@progbits SEPARATOR
>>> +#define PPC64_OPD2 SEPARATOR \
>>> +  .p2align 3 SEPARATOR \
>>> +  .quad .Lfunc_begin0 SEPARATOR \
>>> +  .quad .TOC.@tocbase SEPARATOR \
>>> +  .quad 0 SEPARATOR \
>>> +  .text SEPARATOR \
>>> +.Lfunc_begin0:
>>> +#else
>>> +#define PPC64_OPD1
>>> +#define PPC64_OPD2
>>> +#endif
>>> +
>>> #define GLUE2(a, b) a ## b
>>> #define GLUE(a, b) GLUE2(a, b)
>>> #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
>>> @@ -95,7 +109,9 @@
>>>  .globl SYMBOL_NAME(name) SEPARATOR  \
>>>  EXPORT_SYMBOL(name) SEPARATOR   \
>>>  SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
>>> -  SYMBOL_NAME(name):
>>> +  PPC64_OPD1  \
>>> +  SYMBOL_NAME(name):  \
>>> +  PPC64_OPD2
>>> 
>>> #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name)   \
>>>  .globl SYMBOL_NAME(name) SEPARATOR  \
>>> 
>> 
>> I think this merge missed that the DEFINE_LIBUNWIND_PRIVATE_FUNCTION
>> macro went away in r357640 ("[libunwind] Export the unw_* symbols as
>> weak symbols").
>> 
>> It looks like the PPC64_OPD1 and PPC64_OPD2 lines should also be added
>> to the expansion of DEFINE_LIBUNWIND_PRIVATE_FUNCTION?
>> 
> 
> Is someone else able to try to remerge and fix this up?  I don't have
> a good way to test this.  If we can't get this resolved by Wednesday,
> I am going to revert it, because it's the only thing blocking the release
> at this point.

I reverted the merge in https://reviews.llvm.org/rL365539, and reapplied
it with the additional lines in https://reviews.llvm.org/rL365542.  I
hope you don't mind.

This is also going to end up in the next merge to FreeBSD's libunwind.

-Dimitry



signature.asc
Description: Message signed with OpenPGP
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64356: [OPENMP]Initial fix PR42392: Improve -Wuninitialized warnings for OpenMP programs.

2019-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Something like this:

F9509417: photo_2019-07-09_12-21-46.jpg 

Like, you can construct a CFG for an arbitrary statement. CFG₁ is the CFG for 
xxx() and CFG₂ is the CFG for the CapturedStmt (and its children). I'm trying 
to say that even if used expressions are duplicated in the AST, they should not 
be duplicated in our CFGs.

But that's more, like, for the future patches. I'll be happy to accept this 
patch once you add CFG tests :)


Repository:
  rC Clang

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

https://reviews.llvm.org/D64356



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


  1   2   3   >