r304411 - Increase the limit for the number of DiagnosticLexKinds.td diags.

2017-06-01 Thread Yaron Keren via cfe-commits
Author: yrnkrn
Date: Thu Jun  1 07:46:59 2017
New Revision: 304411

URL: http://llvm.org/viewvc/llvm-project?rev=304411=rev
Log:
Increase the limit for the number of DiagnosticLexKinds.td diags.
300 was reached in r304190, 400 should be enough for a while.


Modified:
cfe/trunk/include/clang/Basic/DiagnosticIDs.h

Modified: cfe/trunk/include/clang/Basic/DiagnosticIDs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticIDs.h?rev=304411=304410=304411=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticIDs.h (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticIDs.h Thu Jun  1 07:46:59 2017
@@ -32,7 +32,7 @@ namespace clang {
   DIAG_START_FRONTEND  = DIAG_START_DRIVER  +  200,
   DIAG_START_SERIALIZATION = DIAG_START_FRONTEND+  100,
   DIAG_START_LEX   = DIAG_START_SERIALIZATION   +  120,
-  DIAG_START_PARSE = DIAG_START_LEX +  300,
+  DIAG_START_PARSE = DIAG_START_LEX +  400,
   DIAG_START_AST   = DIAG_START_PARSE   +  500,
   DIAG_START_COMMENT   = DIAG_START_AST +  110,
   DIAG_START_SEMA  = DIAG_START_COMMENT +  100,


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


[PATCH] D33398: Mangle __unaligned in Itanium ABI

2017-06-01 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.

Looks great, thanks!




Comment at: lib/AST/ItaniumMangle.cpp:2210
+  if (Quals.hasUnaligned())
+  mangleVendorQualifier("__unaligned");
+

rogfer01 wrote:
> rsmith wrote:
> > Too much indentation here. Also, the ABI requires the "unordered" vendor 
> > qualifiers to be emitted in reverse alphabetical order, so this should be 
> > emitted after `__weak` and `__strong` but before `__autoreleasing`.
> I think you meant after `__weak` but before `__strong` and `__autoreleasing`? 
> Maybe I'm misinterpreting something here.
> 
> The current patch emits `__weak`, then `__unaligned` and then the remaining 
> ARC ones.
The alphabet is hard, apparently :) Yes, thanks!



Comment at: lib/AST/ItaniumMangle.cpp:2184
+  //
+  // Note: we emit first __weak to preserve the order as
+  // required by the Itanium ABI.

first `__weak` -> `__weak` first


https://reviews.llvm.org/D33398



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


[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it

2017-06-01 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

Looks good.. Are you also planning to change DIBuilder to not finalize 
subprograms automatically any more (and not insert them into AllSubprograms)? 
(That will be the more impactful change as it will force all non-clang 
frontends to make a similar change).


https://reviews.llvm.org/D33705



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


[PATCH] D33305: [ubsan] Add a check for pointer overflow UB

2017-06-01 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304459: [ubsan] Add a check for pointer overflow UB 
(authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D33305?vs=100475=101078#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33305

Files:
  cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
  cfe/trunk/include/clang/Basic/Sanitizers.def
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGExprScalar.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/test/CodeGen/ubsan-pointer-overflow.m
  cfe/trunk/test/Driver/fsanitize.c

Index: cfe/trunk/test/CodeGen/ubsan-pointer-overflow.m
===
--- cfe/trunk/test/CodeGen/ubsan-pointer-overflow.m
+++ cfe/trunk/test/CodeGen/ubsan-pointer-overflow.m
@@ -0,0 +1,171 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s -fsanitize=pointer-overflow | FileCheck %s
+
+// CHECK-LABEL: define void @unary_arith
+void unary_arith(char *p) {
+  // CHECK:  [[BASE:%.*]] = ptrtoint i8* {{.*}} to i64, !nosanitize
+  // CHECK-NEXT: [[COMPGEP:%.*]] = add i64 [[BASE]], 1, !nosanitize
+  // CHECK-NEXT: [[POSVALID:%.*]] = icmp uge i64 [[COMPGEP]], [[BASE]], !nosanitize
+  // CHECK-NEXT: [[NEGVALID:%.*]] = icmp ult i64 [[COMPGEP]], [[BASE]], !nosanitize
+  // CHECK-NEXT: [[DIFFVALID:%.*]] = select i1 true, i1 [[POSVALID]], i1 [[NEGVALID]], !nosanitize
+  // CHECK-NEXT: [[VALID:%.*]] = and i1 true, [[DIFFVALID]], !nosanitize
+  // CHECK-NEXT: br i1 [[VALID]]{{.*}}, !nosanitize
+  // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}, i64 [[BASE]], i64 [[COMPGEP]]){{.*}}, !nosanitize
+  ++p;
+
+  // CHECK: ptrtoint i8* {{.*}} to i64, !nosanitize
+  // CHECK-NEXT: add i64 {{.*}}, -1, !nosanitize
+  // CHECK: select i1 false{{.*}}, !nosanitize
+  // CHECK-NEXT: and i1 true{{.*}}, !nosanitize
+  // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
+  --p;
+
+  // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
+  p++;
+
+  // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
+  p--;
+}
+
+// CHECK-LABEL: define void @binary_arith
+void binary_arith(char *p, int i) {
+  // CHECK: [[SMUL:%.*]] = call { i64, i1 } @llvm.smul.with.overflow.i64(i64 1, i64 %{{.*}}), !nosanitize
+  // CHECK-NEXT: [[SMULOFLOW:%.*]] = extractvalue { i64, i1 } [[SMUL]], 1, !nosanitize
+  // CHECK-NEXT: [[OFFSETOFLOW:%.*]] = or i1 false, [[SMULOFLOW]], !nosanitize
+  // CHECK-NEXT: [[SMULVAL:%.*]] = extractvalue { i64, i1 } [[SMUL]], 0, !nosanitize
+  // CHECK-NEXT: [[BASE:%.*]] = ptrtoint i8* {{.*}} to i64, !nosanitize
+  // CHECK-NEXT: [[COMPGEP:%.*]] = add i64 [[BASE]], [[SMULVAL]], !nosanitize
+  // CHECK-NEXT: [[POSVALID:%.*]] = icmp uge i64 [[COMPGEP]], [[BASE]], !nosanitize
+  // CHECK-NEXT: [[NEGVALID:%.*]] = icmp ult i64 [[COMPGEP]], [[BASE]], !nosanitize
+  // CHECK-NEXT: [[POSOFFSET:%.*]] = icmp sge i64 [[SMULVAL]], 0, !nosanitize
+  // CHECK-NEXT: [[OFFSETVALID:%.*]] = xor i1 [[OFFSETOFLOW]], true, !nosanitize
+  // CHECK-NEXT: [[DIFFVALID:%.*]] = select i1 [[POSOFFSET]], i1 [[POSVALID]], i1 [[NEGVALID]], !nosanitize
+  // CHECK-NEXT: [[VALID:%.*]] = and i1 [[OFFSETVALID]], [[DIFFVALID]], !nosanitize
+  // CHECK-NEXT: br i1 [[VALID]]{{.*}}, !nosanitize
+  // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}, i64 [[BASE]], i64 [[COMPGEP]]){{.*}}, !nosanitize
+  p + i;
+
+  // CHECK: [[OFFSET:%.*]] = sub i64 0, {{.*}}
+  // CHECK-NEXT: getelementptr inbounds {{.*}} [[OFFSET]]
+  // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
+  p - i;
+}
+
+// CHECK-LABEL: define void @fixed_len_array
+void fixed_len_array(int k) {
+  // CHECK: getelementptr inbounds [10 x [10 x i32]], [10 x [10 x i32]]* [[ARR:%.*]], i64 0, i64 [[IDXPROM:%.*]]
+  // CHECK-NEXT: [[SMUL:%.*]] = call { i64, i1 } @llvm.smul.with.overflow.i64(i64 40, i64 [[IDXPROM]]), !nosanitize
+  // CHECK-NEXT: [[SMULOFLOW:%.*]] = extractvalue { i64, i1 } [[SMUL]], 1, !nosanitize
+  // CHECK-NEXT: [[OFFSETOFLOW:%.*]] = or i1 false, [[SMULOFLOW]], !nosanitize
+  // CHECK-NEXT: [[SMULVAL:%.*]] = extractvalue { i64, i1 } [[SMUL]], 0, !nosanitize
+  // CHECK-NEXT: [[BASE:%.*]] = ptrtoint [10 x [10 x i32]]* [[ARR]] to i64, !nosanitize
+  // CHECK-NEXT: [[COMPGEP:%.*]] = add i64 [[BASE]], [[SMULVAL]], !nosanitize
+  // CHECK-NEXT: [[POSVALID:%.*]] = icmp uge i64 [[COMPGEP]], [[BASE]], !nosanitize
+  // CHECK-NEXT: [[NEGVALID:%.*]] = icmp ult i64 [[COMPGEP]], [[BASE]], !nosanitize
+  // CHECK-NEXT: [[POSOFFSET:%.*]] = icmp sge i64 [[SMULVAL]], 0, !nosanitize
+  // CHECK-NEXT: [[OFFSETVALID:%.*]] = xor i1 [[OFFSETOFLOW]], true, !nosanitize
+  // CHECK-NEXT: [[DIFFVALID:%.*]] = select i1 [[POSOFFSET]], i1 [[POSVALID]], i1 [[NEGVALID]], !nosanitize
+  // CHECK-NEXT: [[VALID:%.*]] = and i1 [[OFFSETVALID]], [[DIFFVALID]], !nosanitize
+  // CHECK-NEXT: br i1 [[VALID]]{{.*}}, !nosanitize
+  // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}, i64 [[BASE]], i64 

r304459 - [ubsan] Add a check for pointer overflow UB

2017-06-01 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Thu Jun  1 14:22:18 2017
New Revision: 304459

URL: http://llvm.org/viewvc/llvm-project?rev=304459=rev
Log:
[ubsan] Add a check for pointer overflow UB

Check pointer arithmetic for overflow.

For some more background on this check, see:

  https://wdtz.org/catching-pointer-overflow-bugs.html
  https://reviews.llvm.org/D20322

Patch by Will Dietz and John Regehr!

This version of the patch is different from the original in a few ways:

  - It introduces the EmitCheckedInBoundsGEP utility which inserts
checks when the pointer overflow check is enabled.

  - It does some constant-folding to reduce instrumentation overhead.

  - It does not check some GEPs in CGExprCXX. I'm not sure that
inserting checks here, or in CGClass, would catch many bugs.

Possible future directions for this check:

  - Introduce CGF.EmitCheckedStructGEP, to detect overflows when
accessing structures.

Testing: Apart from the added lit test, I ran check-llvm and check-clang
with a stage2, ubsan-instrumented clang. Will and John have also done
extensive testing on numerous open source projects.

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

Added:
cfe/trunk/test/CodeGen/ubsan-pointer-overflow.m
Modified:
cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
cfe/trunk/include/clang/Basic/Sanitizers.def
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UndefinedBehaviorSanitizer.rst?rev=304459=304458=304459=diff
==
--- cfe/trunk/docs/UndefinedBehaviorSanitizer.rst (original)
+++ cfe/trunk/docs/UndefinedBehaviorSanitizer.rst Thu Jun  1 14:22:18 2017
@@ -106,6 +106,8 @@ Available checks are:
  invalid pointers. These checks are made in terms of
  ``__builtin_object_size``, and consequently may be able to detect more
  problems at higher optimization levels.
+  -  ``-fsanitize=pointer-overflow``: Performing pointer arithmetic which
+ overflows.
   -  ``-fsanitize=return``: In C++, reaching the end of a
  value-returning function without returning a value.
   -  ``-fsanitize=returns-nonnull-attribute``: Returning null pointer

Modified: cfe/trunk/include/clang/Basic/Sanitizers.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.def?rev=304459=304458=304459=diff
==
--- cfe/trunk/include/clang/Basic/Sanitizers.def (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.def Thu Jun  1 14:22:18 2017
@@ -73,6 +73,7 @@ SANITIZER("nullability-return", Nullabil
 SANITIZER_GROUP("nullability", Nullability,
 NullabilityArg | NullabilityAssign | NullabilityReturn)
 SANITIZER("object-size", ObjectSize)
+SANITIZER("pointer-overflow", PointerOverflow)
 SANITIZER("return", Return)
 SANITIZER("returns-nonnull-attribute", ReturnsNonnullAttribute)
 SANITIZER("shift-base", ShiftBase)
@@ -108,9 +109,9 @@ SANITIZER("safe-stack", SafeStack)
 SANITIZER_GROUP("undefined", Undefined,
 Alignment | Bool | ArrayBounds | Enum | FloatCastOverflow |
 FloatDivideByZero | IntegerDivideByZero | NonnullAttribute 
|
-Null | ObjectSize | Return | ReturnsNonnullAttribute |
-Shift | SignedIntegerOverflow | Unreachable | VLABound |
-Function | Vptr)
+Null | ObjectSize | PointerOverflow | Return |
+ReturnsNonnullAttribute | Shift | SignedIntegerOverflow |
+Unreachable | VLABound | Function | Vptr)
 
 // -fsanitize=undefined-trap is an alias for -fsanitize=undefined.
 SANITIZER_GROUP("undefined-trap", UndefinedTrap, Undefined)

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=304459=304458=304459=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jun  1 14:22:18 2017
@@ -3002,9 +3002,10 @@ static llvm::Value *emitArraySubscriptGE
   llvm::Value *ptr,
   ArrayRef indices,
   bool inbounds,
+  SourceLocation loc,
 const llvm::Twine  = "arrayidx") {
   if (inbounds) {
-return CGF.Builder.CreateInBoundsGEP(ptr, indices, name);
+return CGF.EmitCheckedInBoundsGEP(ptr, indices, loc, name);
   } else {
 return CGF.Builder.CreateGEP(ptr, indices, name);
   }
@@ -3035,8 +3036,9 @@ static QualType getFixedSizeElementType(
 }
 
 static Address 

Re: r304346 - [modules] When compiling a preprocessed module map, look for headers relative

2017-06-01 Thread Richard Smith via cfe-commits
On 1 June 2017 at 11:10, Galina Kistanova  wrote:

> Hello Richard,
>
> This commit broke tests on few of our builders:
>
> Failing Tests (2):
> Clang :: Modules/preprocess-module.cpp
> Clang :: Modules/preprocess-nested.cpp
>
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-
> scei-ps4-windows10pro-fast/builds/10199
> and
> http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensiv
> e-checks-win/builds/2819
>
> Please have a look at this?
>

Sure, looking.


> Also I see that email notifications on these failures were sent.
>

They certainly did not arrive here. As I've mentioned before, I have not
received any mail from any lab.llvm.org bots since early March.


> Thanks
>
> Galina
>
>
> On Wed, May 31, 2017 at 1:56 PM, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: rsmith
>> Date: Wed May 31 15:56:55 2017
>> New Revision: 304346
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=304346=rev
>> Log:
>> [modules] When compiling a preprocessed module map, look for headers
>> relative
>> to the original module map.
>>
>> Also use the path and name of the original module map when emitting that
>> information into the .pcm file. The upshot of this is that the produced
>> .pcm
>> file will track information for headers in their original locations
>> (where the
>> module was preprocessed), not relative to whatever directory the
>> preprocessed
>> module map was in when it was built.
>>
>> Modified:
>> cfe/trunk/include/clang/Basic/Module.h
>> cfe/trunk/include/clang/Lex/HeaderSearch.h
>> cfe/trunk/lib/Frontend/FrontendAction.cpp
>> cfe/trunk/lib/Lex/HeaderSearch.cpp
>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>> cfe/trunk/test/Modules/preprocess-module.cpp
>> cfe/trunk/test/Modules/preprocess-nested.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/Module.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Basic/Module.h?rev=304346=304345=304346=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Basic/Module.h (original)
>> +++ cfe/trunk/include/clang/Basic/Module.h Wed May 31 15:56:55 2017
>> @@ -83,6 +83,10 @@ public:
>>/// are found.
>>const DirectoryEntry *Directory;
>>
>> +  /// \brief The presumed file name for the module map defining this
>> module.
>> +  /// Only non-empty when building from preprocessed source.
>> +  std::string PresumedModuleMapFile;
>> +
>>/// \brief The umbrella header or directory.
>>llvm::PointerUnion Umbrella;
>>
>>
>> Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Lex/HeaderSearch.h?rev=304346=304345=304346=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
>> +++ cfe/trunk/include/clang/Lex/HeaderSearch.h Wed May 31 15:56:55 2017
>> @@ -543,10 +543,13 @@ public:
>>/// \param Offset [inout] An offset within ID to start parsing. On
>> exit,
>>///filled by the end of the parsed contents (either EOF or the
>>///location of an end-of-module-map pragma).
>> -  ///
>> +  /// \param OriginalModuleMapFile The original path to the module map
>> file,
>> +  ///used to resolve paths within the module (this is required
>> when
>> +  ///building the module from preprocessed source).
>>/// \returns true if an error occurred, false otherwise.
>>bool loadModuleMapFile(const FileEntry *File, bool IsSystem,
>> - FileID ID = FileID(), unsigned *Offset =
>> nullptr);
>> + FileID ID = FileID(), unsigned *Offset =
>> nullptr,
>> + StringRef OriginalModuleMapFile = StringRef());
>>
>>/// \brief Collect the set of all known, top-level modules.
>>///
>>
>> Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/F
>> rontendAction.cpp?rev=304346=304345=304346=diff
>> 
>> ==
>> --- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
>> +++ cfe/trunk/lib/Frontend/FrontendAction.cpp Wed May 31 15:56:55 2017
>> @@ -373,10 +373,11 @@ collectModuleHeaderIncludes(const LangOp
>>return std::error_code();
>>  }
>>
>> -static bool
>> -loadModuleMapForModuleBuild(CompilerInstance , StringRef Filename,
>> -bool IsSystem, bool IsPreprocessed,
>> -unsigned ) {
>> +static bool loadModuleMapForModuleBuild(CompilerInstance ,
>> +StringRef Filename, bool
>> IsSystem,
>> +bool IsPreprocessed,
>> +std::string
>> ,
>> +unsigned ) {
>>auto  = 

r304463 - [Modules] Handle sanitizer feature mismatches when importing modules

2017-06-01 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Thu Jun  1 15:01:01 2017
New Revision: 304463

URL: http://llvm.org/viewvc/llvm-project?rev=304463=rev
Log:
[Modules] Handle sanitizer feature mismatches when importing modules

This patch makes it an error to have a mismatch between the enabled
sanitizers in a CU, and in any module being imported into the CU. Only
mismatches between non-modular sanitizers are treated as errors.

This patch also includes non-modular sanitizers in module hashes, in
order to ensure module rebuilds occur when -fsanitize=X is toggled on
and off for non-modular sanitizers, and to cut down on module rebuilds
when the option is toggled for modular sanitizers.

This fixes a longstanding issue with implicit modules and sanitizers,
which Duncan originally diagnosed.

When building with implicit modules it's possible to hit a scenario
where modules are built without -fsanitize=address, and are subsequently
imported into CUs with -fsanitize=address enabled. This causes strange
failures at runtime. The case Duncan found affects libcxx, since its
vector implementation behaves differently when ASan is enabled.

Implicit module builds should "just work" when -fsanitize=X is toggled
on and off across multiple compiler invocations, which is what this
patch does.

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

Added:
cfe/trunk/test/Modules/Inputs/check-for-sanitizer-feature/
cfe/trunk/test/Modules/Inputs/check-for-sanitizer-feature/check.h
cfe/trunk/test/Modules/Inputs/check-for-sanitizer-feature/map
cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp
Modified:
cfe/trunk/include/clang/Basic/Sanitizers.h
cfe/trunk/lib/Basic/LangOptions.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Basic/Sanitizers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.h?rev=304463=304462=304463=diff
==
--- cfe/trunk/include/clang/Basic/Sanitizers.h (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.h Thu Jun  1 15:01:01 2017
@@ -61,8 +61,8 @@ struct SanitizerSet {
 Mask = Value ? (Mask | K) : (Mask & ~K);
   }
 
-  /// \brief Disable all sanitizers.
-  void clear() { Mask = 0; }
+  /// Disable the sanitizers specified in \p K.
+  void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
 
   /// \brief Returns true if at least one sanitizer is enabled.
   bool empty() const { return Mask == 0; }
@@ -79,6 +79,12 @@ SanitizerMask parseSanitizerValue(String
 /// this group enables.
 SanitizerMask expandSanitizerGroups(SanitizerMask Kinds);
 
+/// Return the sanitizers which do not affect preprocessing.
+static inline SanitizerMask getPPTransparentSanitizers() {
+  return SanitizerKind::CFI | SanitizerKind::Integer |
+ SanitizerKind::Nullability | SanitizerKind::Undefined;
+}
+
 }  // end namespace clang
 
 #endif

Modified: cfe/trunk/lib/Basic/LangOptions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/LangOptions.cpp?rev=304463=304462=304463=diff
==
--- cfe/trunk/lib/Basic/LangOptions.cpp (original)
+++ cfe/trunk/lib/Basic/LangOptions.cpp Thu Jun  1 15:01:01 2017
@@ -29,9 +29,7 @@ void LangOptions::resetNonModularOptions
   Name = Default;
 #include "clang/Basic/LangOptions.def"
 
-  // FIXME: This should not be reset; modules can be different with different
-  // sanitizer options (this affects __has_feature(address_sanitizer) etc).
-  Sanitize.clear();
+  // These options do not affect AST generation.
   SanitizerBlacklistFiles.clear();
   XRayAlwaysInstrumentFiles.clear();
   XRayNeverInstrumentFiles.clear();

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=304463=304462=304463=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Jun  1 15:01:01 2017
@@ -2700,6 +2700,13 @@ std::string CompilerInvocation::getModul
 code = ext->hashExtension(code);
   }
 
+  // Extend the signature with the enabled sanitizers, if at least one is
+  // enabled. Sanitizers which cannot affect AST generation aren't hashed.
+  SanitizerSet SanHash = LangOpts->Sanitize;
+  SanHash.clear(getPPTransparentSanitizers());
+  if (!SanHash.empty())
+code = hash_combine(code, SanHash.Mask);
+
   return llvm::APInt(64, code).toString(36, /*Signed=*/false);
 }
 

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=304463=304462=304463=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ 

[PATCH] D32724: [Modules] Handle sanitizer feature mismatches when importing modules

2017-06-01 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304463: [Modules] Handle sanitizer feature mismatches when 
importing modules (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D32724?vs=98371=101088#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32724

Files:
  cfe/trunk/include/clang/Basic/Sanitizers.h
  cfe/trunk/lib/Basic/LangOptions.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/test/Modules/Inputs/check-for-sanitizer-feature/check.h
  cfe/trunk/test/Modules/Inputs/check-for-sanitizer-feature/map
  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
@@ -61,8 +61,8 @@
 Mask = Value ? (Mask | K) : (Mask & ~K);
   }
 
-  /// \brief Disable all sanitizers.
-  void clear() { Mask = 0; }
+  /// Disable the sanitizers specified in \p K.
+  void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
 
   /// \brief Returns true if at least one sanitizer is enabled.
   bool empty() const { return Mask == 0; }
@@ -79,6 +79,12 @@
 /// this group enables.
 SanitizerMask expandSanitizerGroups(SanitizerMask Kinds);
 
+/// Return the sanitizers which do not affect preprocessing.
+static inline SanitizerMask getPPTransparentSanitizers() {
+  return SanitizerKind::CFI | SanitizerKind::Integer |
+ SanitizerKind::Nullability | SanitizerKind::Undefined;
+}
+
 }  // end namespace clang
 
 #endif
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
@@ -0,0 +1,66 @@
+// RUN: rm -rf %t.1 %t.2
+// RUN: mkdir %t.1 %t.2
+
+// Build and use an ASan-enabled module.
+// RUN: %clang_cc1 -fsanitize=address -fmodules -fmodules-cache-path=%t.1 \
+// RUN:   -fmodule-map-file=%S/Inputs/check-for-sanitizer-feature/map \
+// RUN:   -I %S/Inputs/check-for-sanitizer-feature -verify %s
+// RUN: ls %t.1 | count 2
+
+// Force a module rebuild by disabling ASan.
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t.1 \
+// RUN:   -fmodule-map-file=%S/Inputs/check-for-sanitizer-feature/map \
+// RUN:   -I %S/Inputs/check-for-sanitizer-feature -verify %s
+// RUN: ls %t.1 | count 3
+
+// Enable ASan again: check that there is no import failure, and no rebuild.
+// RUN: %clang_cc1 -fsanitize=address -fmodules -fmodules-cache-path=%t.1 \
+// RUN:   -fmodule-map-file=%S/Inputs/check-for-sanitizer-feature/map \
+// RUN:   -I %S/Inputs/check-for-sanitizer-feature -verify %s
+// RUN: ls %t.1 | count 3
+
+// Some sanitizers can not affect AST generation when enabled. Check that
+// module rebuilds don't occur when these sanitizers are enabled.
+//
+// First, build without any sanitization.
+// RUN: %clang_cc1 -fmodules -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
+// 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:   -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
+// RUN: ls %t.2 | count 2
+
+// Finally, test that including enabled sanitizers in the module hash isn't
+// required to ensure correctness of module imports.
+//
+// Emit a PCH with ASan enabled.
+// RUN: %clang_cc1 -x c -fsanitize=address %S/Inputs/check-for-sanitizer-feature/check.h -emit-pch -o %t.asan_pch
+//
+// Import the PCH without ASan enabled (we expect an error).
+// RUN: not %clang_cc1 -x c -include-pch %t.asan_pch %s -verify 2>&1 | FileCheck %s --check-prefix=PCH_MISMATCH
+// PCH_MISMATCH: AST file was compiled with the target feature'-fsanitize=address' but the current translation unit is not
+//
+// Emit a PCH with UBSan enabled.
+// RUN: %clang_cc1 -x c -fsanitize=null %S/Inputs/check-for-sanitizer-feature/check.h -emit-pch -o %t.ubsan_pch
+//
+// Import the PCH without UBSan enabled (should work just fine).
+// RUN: %clang_cc1 -x c -include-pch %t.ubsan_pch %s -I %S/Inputs/check-for-sanitizer-feature -verify
+
+#include "check.h"
+
+#if __has_feature(address_sanitizer)
+#if HAS_ASAN != 1
+#error Module doesn't have the address_sanitizer feature, but main program does.
+#endif
+#else
+#if HAS_ASAN != 0
+#error Module has the address_sanitizer feature, but main program doesn't.
+#endif
+#endif
+
+// expected-no-diagnostics
Index: cfe/trunk/test/Modules/Inputs/check-for-sanitizer-feature/map

[libcxx] r304462 - Mark two coroutine tests as unsupported under ubsan

2017-06-01 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Thu Jun  1 15:00:40 2017
New Revision: 304462

URL: http://llvm.org/viewvc/llvm-project?rev=304462=rev
Log:
Mark two coroutine tests as unsupported under ubsan

They appear to crash inside of SelectionDAG on some Linux bots, when
ubsan is enabled.

https://bugs.llvm.org/show_bug.cgi?id=33271

Modified:

libcxx/trunk/test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp

libcxx/trunk/test/std/experimental/language.support/support.coroutines/end.to.end/generator.pass.cpp

Modified: 
libcxx/trunk/test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp?rev=304462=304461=304462=diff
==
--- 
libcxx/trunk/test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp
 Thu Jun  1 15:00:40 2017
@@ -10,6 +10,9 @@
 
 // UNSUPPORTED: c++98, c++03, c++11
 
+// See https://bugs.llvm.org/show_bug.cgi?id=33271
+// UNSUPPORTED: ubsan
+
 #include 
 #include 
 

Modified: 
libcxx/trunk/test/std/experimental/language.support/support.coroutines/end.to.end/generator.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/language.support/support.coroutines/end.to.end/generator.pass.cpp?rev=304462=304461=304462=diff
==
--- 
libcxx/trunk/test/std/experimental/language.support/support.coroutines/end.to.end/generator.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/experimental/language.support/support.coroutines/end.to.end/generator.pass.cpp
 Thu Jun  1 15:00:40 2017
@@ -10,6 +10,9 @@
 
 // UNSUPPORTED: c++98, c++03, c++11
 
+// See https://bugs.llvm.org/show_bug.cgi?id=33271
+// UNSUPPORTED: ubsan
+
 #include 
 #include 
 #include 


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


[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it

2017-06-01 Thread Keno Fischer via Phabricator via cfe-commits
loladiro updated this revision to Diff 101092.
loladiro added a comment.

Finalize all subprograms when we're done emitting them.
The one we're interested in is a side effect, but doing
this uniformly might be cleaner and help avoid similar errors in the future.


https://reviews.llvm.org/D33705

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CodeGenFunction.cpp


Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -348,7 +348,7 @@
 
   // Emit debug descriptor for function end.
   if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitFunctionEnd(Builder);
+DI->EmitFunctionEnd(Builder, CurFn);
 
   // Reset the debug location to that of the simple 'return' expression, if any
   // rather than that of the end of the function's scope '}'.
Index: lib/CodeGen/CGDebugInfo.h
===
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -367,7 +367,7 @@
   void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType);
 
   /// Constructs the debug code for exiting a function.
-  void EmitFunctionEnd(CGBuilderTy );
+  void EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn);
 
   /// Emit metadata to indicate the beginning of a new lexical block
   /// and push the block onto the stack.
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3263,7 +3263,7 @@
 
 void CGDebugInfo::EmitInlineFunctionEnd(CGBuilderTy ) {
   assert(CurInlinedAt && "unbalanced inline scope stack");
-  EmitFunctionEnd(Builder);
+  EmitFunctionEnd(Builder, nullptr);
   setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt());
 }
 
@@ -3332,7 +3332,7 @@
   LexicalBlockStack.pop_back();
 }
 
-void CGDebugInfo::EmitFunctionEnd(CGBuilderTy ) {
+void CGDebugInfo::EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn) {
   assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
   unsigned RCount = FnBeginRegionCount.back();
   assert(RCount <= LexicalBlockStack.size() && "Region stack mismatch");
@@ -3344,6 +3344,9 @@
 LexicalBlockStack.pop_back();
   }
   FnBeginRegionCount.pop_back();
+
+  if (Fn && Fn->getSubprogram())
+DBuilder.finalizeSubprogram(Fn->getSubprogram());
 }
 
 llvm::DIType *CGDebugInfo::EmitTypeForVarWithBlocksAttr(const VarDecl *VD,


Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -348,7 +348,7 @@
 
   // Emit debug descriptor for function end.
   if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitFunctionEnd(Builder);
+DI->EmitFunctionEnd(Builder, CurFn);
 
   // Reset the debug location to that of the simple 'return' expression, if any
   // rather than that of the end of the function's scope '}'.
Index: lib/CodeGen/CGDebugInfo.h
===
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -367,7 +367,7 @@
   void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType);
 
   /// Constructs the debug code for exiting a function.
-  void EmitFunctionEnd(CGBuilderTy );
+  void EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn);
 
   /// Emit metadata to indicate the beginning of a new lexical block
   /// and push the block onto the stack.
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3263,7 +3263,7 @@
 
 void CGDebugInfo::EmitInlineFunctionEnd(CGBuilderTy ) {
   assert(CurInlinedAt && "unbalanced inline scope stack");
-  EmitFunctionEnd(Builder);
+  EmitFunctionEnd(Builder, nullptr);
   setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt());
 }
 
@@ -3332,7 +3332,7 @@
   LexicalBlockStack.pop_back();
 }
 
-void CGDebugInfo::EmitFunctionEnd(CGBuilderTy ) {
+void CGDebugInfo::EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn) {
   assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
   unsigned RCount = FnBeginRegionCount.back();
   assert(RCount <= LexicalBlockStack.size() && "Region stack mismatch");
@@ -3344,6 +3344,9 @@
 LexicalBlockStack.pop_back();
   }
   FnBeginRegionCount.pop_back();
+
+  if (Fn && Fn->getSubprogram())
+DBuilder.finalizeSubprogram(Fn->getSubprogram());
 }
 
 llvm::DIType *CGDebugInfo::EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it

2017-06-01 Thread Keno Fischer via Phabricator via cfe-commits
loladiro added a comment.

@aprantl @dblaikie See if you like this better.


https://reviews.llvm.org/D33705



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


Re: r304346 - [modules] When compiling a preprocessed module map, look for headers relative

2017-06-01 Thread Richard Smith via cfe-commits
On 1 June 2017 at 12:53, Richard Smith  wrote:

> On 1 June 2017 at 11:10, Galina Kistanova  wrote:
>
>> Hello Richard,
>>
>> This commit broke tests on few of our builders:
>>
>> Failing Tests (2):
>> Clang :: Modules/preprocess-module.cpp
>> Clang :: Modules/preprocess-nested.cpp
>>
>> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei
>> -ps4-windows10pro-fast/builds/10199
>> and
>> http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensiv
>> e-checks-win/builds/2819
>>
>> Please have a look at this?
>>
>
> Sure, looking.
>

Should be fixed in r304464.


> Also I see that email notifications on these failures were sent.
>>
>
> They certainly did not arrive here. As I've mentioned before, I have not
> received any mail from any lab.llvm.org bots since early March.
>
>
>> Thanks
>>
>> Galina
>>
>>
>> On Wed, May 31, 2017 at 1:56 PM, Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: rsmith
>>> Date: Wed May 31 15:56:55 2017
>>> New Revision: 304346
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=304346=rev
>>> Log:
>>> [modules] When compiling a preprocessed module map, look for headers
>>> relative
>>> to the original module map.
>>>
>>> Also use the path and name of the original module map when emitting that
>>> information into the .pcm file. The upshot of this is that the produced
>>> .pcm
>>> file will track information for headers in their original locations
>>> (where the
>>> module was preprocessed), not relative to whatever directory the
>>> preprocessed
>>> module map was in when it was built.
>>>
>>> Modified:
>>> cfe/trunk/include/clang/Basic/Module.h
>>> cfe/trunk/include/clang/Lex/HeaderSearch.h
>>> cfe/trunk/lib/Frontend/FrontendAction.cpp
>>> cfe/trunk/lib/Lex/HeaderSearch.cpp
>>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>>> cfe/trunk/test/Modules/preprocess-module.cpp
>>> cfe/trunk/test/Modules/preprocess-nested.cpp
>>>
>>> Modified: cfe/trunk/include/clang/Basic/Module.h
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>>> Basic/Module.h?rev=304346=304345=304346=diff
>>> 
>>> ==
>>> --- cfe/trunk/include/clang/Basic/Module.h (original)
>>> +++ cfe/trunk/include/clang/Basic/Module.h Wed May 31 15:56:55 2017
>>> @@ -83,6 +83,10 @@ public:
>>>/// are found.
>>>const DirectoryEntry *Directory;
>>>
>>> +  /// \brief The presumed file name for the module map defining this
>>> module.
>>> +  /// Only non-empty when building from preprocessed source.
>>> +  std::string PresumedModuleMapFile;
>>> +
>>>/// \brief The umbrella header or directory.
>>>llvm::PointerUnion
>>> Umbrella;
>>>
>>>
>>> Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>>> Lex/HeaderSearch.h?rev=304346=304345=304346=diff
>>> 
>>> ==
>>> --- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
>>> +++ cfe/trunk/include/clang/Lex/HeaderSearch.h Wed May 31 15:56:55 2017
>>> @@ -543,10 +543,13 @@ public:
>>>/// \param Offset [inout] An offset within ID to start parsing. On
>>> exit,
>>>///filled by the end of the parsed contents (either EOF or the
>>>///location of an end-of-module-map pragma).
>>> -  ///
>>> +  /// \param OriginalModuleMapFile The original path to the module map
>>> file,
>>> +  ///used to resolve paths within the module (this is required
>>> when
>>> +  ///building the module from preprocessed source).
>>>/// \returns true if an error occurred, false otherwise.
>>>bool loadModuleMapFile(const FileEntry *File, bool IsSystem,
>>> - FileID ID = FileID(), unsigned *Offset =
>>> nullptr);
>>> + FileID ID = FileID(), unsigned *Offset =
>>> nullptr,
>>> + StringRef OriginalModuleMapFile = StringRef());
>>>
>>>/// \brief Collect the set of all known, top-level modules.
>>>///
>>>
>>> Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/F
>>> rontendAction.cpp?rev=304346=304345=304346=diff
>>> 
>>> ==
>>> --- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
>>> +++ cfe/trunk/lib/Frontend/FrontendAction.cpp Wed May 31 15:56:55 2017
>>> @@ -373,10 +373,11 @@ collectModuleHeaderIncludes(const LangOp
>>>return std::error_code();
>>>  }
>>>
>>> -static bool
>>> -loadModuleMapForModuleBuild(CompilerInstance , StringRef Filename,
>>> -bool IsSystem, bool IsPreprocessed,
>>> -unsigned ) {
>>> +static bool loadModuleMapForModuleBuild(CompilerInstance ,
>>> +

[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it

2017-06-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

I guess this would need a cross-project test case (ie: it'd have to run LLVM 
optimizations to fail/pass/demonstrate the fix). I think it'd be OK to add one 
if there's a neat/clean/obvious optimization that can be reliably triggered to 
do the cloning that would assert/crash - please add one if you think that's 
practical/reasonable.


https://reviews.llvm.org/D33705



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


r304465 - Don't assume that a store source is a vector type just because the destination is (PR26099)

2017-06-01 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Thu Jun  1 15:13:34 2017
New Revision: 304465

URL: http://llvm.org/viewvc/llvm-project?rev=304465=rev
Log:
Don't assume that a store source is a vector type just because the destination 
is (PR26099)

Added:
cfe/trunk/test/CodeGen/pr26099.c
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=304465=304464=304465=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jun  1 15:13:34 2017
@@ -1487,9 +1487,9 @@ void CodeGenFunction::EmitStoreOfScalar(
 // Handle vectors differently to get better performance.
 if (Ty->isVectorType()) {
   llvm::Type *SrcTy = Value->getType();
-  auto *VecTy = cast(SrcTy);
+  auto *VecTy = dyn_cast(SrcTy);
   // Handle vec3 special.
-  if (VecTy->getNumElements() == 3) {
+  if (VecTy && VecTy->getNumElements() == 3) {
 // Our source is a vec3, do a shuffle vector to make it a vec4.
 llvm::Constant *Mask[] = {Builder.getInt32(0), Builder.getInt32(1),
   Builder.getInt32(2),

Added: cfe/trunk/test/CodeGen/pr26099.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pr26099.c?rev=304465=auto
==
--- cfe/trunk/test/CodeGen/pr26099.c (added)
+++ cfe/trunk/test/CodeGen/pr26099.c Thu Jun  1 15:13:34 2017
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -ffreestanding %s -triple=i686-apple-darwin -target-feature 
+mmx -emit-llvm -o - -Wall -Werror
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +mmx -emit-llvm -o - -Wall -Werror
+// REQUIRES: asserts
+
+#include 
+
+int __attribute__ ((__vector_size__ (8))) b;
+
+void bar(int a)
+{
+  b = __builtin_ia32_vec_init_v2si (0, a);
+}
\ No newline at end of file


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


[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it

2017-06-01 Thread Keno Fischer via Phabricator via cfe-commits
loladiro added a comment.

There's already such a test case, but the cloning currently doesn't assert 
properly (but it can generate incorrect code). https://reviews.llvm.org/D33655 
fixes that up, so I think the testing is covered once that LLVM commit goes in. 
I'll hold off a little while to give @aprantl a chance to look at this as well, 
but I do want to get this in in short order, so I can recommit 
https://reviews.llvm.org/D33655.


https://reviews.llvm.org/D33705



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


[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it

2017-06-01 Thread Keno Fischer via Phabricator via cfe-commits
loladiro added a comment.

I don't think that change is entirely necessary. I don't have any strong 
objections to it, but I also don't see a good reason to require it. In any 
case, let me get this in to be able to re-land https://reviews.llvm.org/D33655 
and we can revisit the more disruptive change later.


https://reviews.llvm.org/D33705



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


[PATCH] D33797: [coroutines] Fix rebuilding of dependent coroutine parameters

2017-06-01 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov created this revision.

We were not handling correctly rebuilding of parameter and were not creating 
copies for them.
With this checking, we will be always rebuilding parameter moves in 
TreeTransform's TransformCoroutineBodyStmt.


https://reviews.llvm.org/D33797

Files:
  lib/Sema/CoroutineStmtBuilder.h
  lib/Sema/SemaCoroutine.cpp
  lib/Sema/TreeTransform.h
  test/CodeGenCoroutines/coro-params.cpp


Index: test/CodeGenCoroutines/coro-params.cpp
===
--- test/CodeGenCoroutines/coro-params.cpp
+++ test/CodeGenCoroutines/coro-params.cpp
@@ -93,3 +93,26 @@
   // CHECK-NEXT: call void @_ZN8MoveOnlyD1Ev(%struct.MoveOnly* %[[MoCopy]]
   // CHECK-NEXT: call i8* @llvm.coro.free(
 }
+
+// CHECK-LABEL: void @_Z16dependent_paramsI1AEvT_(%struct.A* %x
+template 
+void dependent_params(T x) {
+  // CHECK: %[[x_copy:.+]] = alloca %struct.A
+
+  // CHECK: call i8* @llvm.coro.begin
+  // CHECK-NEXT: call void @_ZN1AC1EOS_(%struct.A* %x1, %struct.A* 
dereferenceable(512) %x)
+  // CHECK-NEXT: call void 
@_ZNSt12experimental16coroutine_traitsIJv1AEE12promise_typeC1Ev
+
+  co_return;
+}
+
+struct A {
+  int WontFitIntoRegisterForSure[128];
+  A();
+  A(A&&);
+  ~A();
+};
+
+void call_dependent_params() {
+  dependent_params(A{});
+}
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -6959,6 +6959,7 @@
   Builder.ReturnStmt = Res.get();
 }
   }
+  Builder.buildParameterMoves();
 
   return getDerived().RebuildCoroutineBodyStmt(Builder);
 }
Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -822,6 +822,12 @@
   return this->IsValid;
 }
 
+bool CoroutineStmtBuilder::buildParameterMoves() {
+  assert(this->IsValid && "coroutine already invalid");
+  assert(this->ParamMoves.empty() && "param moves already built");
+  return this->IsValid = makeParamMoves();
+}
+
 bool CoroutineStmtBuilder::buildDependentStatements() {
   assert(this->IsValid && "coroutine already invalid");
   assert(!this->IsPromiseDependentType &&
Index: lib/Sema/CoroutineStmtBuilder.h
===
--- lib/Sema/CoroutineStmtBuilder.h
+++ lib/Sema/CoroutineStmtBuilder.h
@@ -51,6 +51,9 @@
   /// name lookup.
   bool buildDependentStatements();
 
+  /// \brief Build just parameter moves. To use for rebuilding in 
TreeTransform.
+  bool buildParameterMoves();
+
   bool isInvalid() const { return !this->IsValid; }
 
 private:


Index: test/CodeGenCoroutines/coro-params.cpp
===
--- test/CodeGenCoroutines/coro-params.cpp
+++ test/CodeGenCoroutines/coro-params.cpp
@@ -93,3 +93,26 @@
   // CHECK-NEXT: call void @_ZN8MoveOnlyD1Ev(%struct.MoveOnly* %[[MoCopy]]
   // CHECK-NEXT: call i8* @llvm.coro.free(
 }
+
+// CHECK-LABEL: void @_Z16dependent_paramsI1AEvT_(%struct.A* %x
+template 
+void dependent_params(T x) {
+  // CHECK: %[[x_copy:.+]] = alloca %struct.A
+
+  // CHECK: call i8* @llvm.coro.begin
+  // CHECK-NEXT: call void @_ZN1AC1EOS_(%struct.A* %x1, %struct.A* dereferenceable(512) %x)
+  // CHECK-NEXT: call void @_ZNSt12experimental16coroutine_traitsIJv1AEE12promise_typeC1Ev
+
+  co_return;
+}
+
+struct A {
+  int WontFitIntoRegisterForSure[128];
+  A();
+  A(A&&);
+  ~A();
+};
+
+void call_dependent_params() {
+  dependent_params(A{});
+}
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -6959,6 +6959,7 @@
   Builder.ReturnStmt = Res.get();
 }
   }
+  Builder.buildParameterMoves();
 
   return getDerived().RebuildCoroutineBodyStmt(Builder);
 }
Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -822,6 +822,12 @@
   return this->IsValid;
 }
 
+bool CoroutineStmtBuilder::buildParameterMoves() {
+  assert(this->IsValid && "coroutine already invalid");
+  assert(this->ParamMoves.empty() && "param moves already built");
+  return this->IsValid = makeParamMoves();
+}
+
 bool CoroutineStmtBuilder::buildDependentStatements() {
   assert(this->IsValid && "coroutine already invalid");
   assert(!this->IsPromiseDependentType &&
Index: lib/Sema/CoroutineStmtBuilder.h
===
--- lib/Sema/CoroutineStmtBuilder.h
+++ lib/Sema/CoroutineStmtBuilder.h
@@ -51,6 +51,9 @@
   /// name lookup.
   bool buildDependentStatements();
 
+  /// \brief Build just parameter moves. To use for rebuilding in TreeTransform.
+  bool buildParameterMoves();
+
   bool isInvalid() const { return !this->IsValid; }
 
 private:
___
cfe-commits mailing 

r304464 - Escape filenames in module map line marker directives, to unbreak Windows build bots.

2017-06-01 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Jun  1 15:10:35 2017
New Revision: 304464

URL: http://llvm.org/viewvc/llvm-project?rev=304464=rev
Log:
Escape filenames in module map line marker directives, to unbreak Windows build 
bots.

Modified:
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=304464=304463=304464=diff
==
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Thu Jun  1 15:10:35 2017
@@ -546,8 +546,11 @@ void PrintPreprocessedAction::ExecuteAct
   // module itself before switching to the input buffer.
   auto  = getCurrentInput();
   if (Input.getKind().getFormat() == InputKind::ModuleMap) {
-if (Input.isFile())
-  (*OS) << "# 1 \"" << Input.getFile() << "\"\n";
+if (Input.isFile()) {
+  (*OS) << "# 1 \"";
+  OS->write_escaped(Input.getFile());
+  (*OS) << "\"\n";
+}
 // FIXME: Include additional information here so that we don't need the
 // original source files to exist on disk.
 getCurrentModule()->print(*OS);

Modified: cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp?rev=304464=304463=304464=diff
==
--- cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp Thu Jun  1 15:10:35 2017
@@ -200,8 +200,11 @@ void RewriteIncludesAction::ExecuteActio
   // module itself before switching to the input buffer.
   auto  = getCurrentInput();
   if (Input.getKind().getFormat() == InputKind::ModuleMap) {
-if (Input.isFile())
-  (*OS) << "# 1 \"" << Input.getFile() << "\"\n";
+if (Input.isFile()) {
+  (*OS) << "# 1 \"";
+  OS->write_escaped(Input.getFile());
+  (*OS) << "\"\n";
+}
 // FIXME: Include additional information here so that we don't need the
 // original source files to exist on disk.
 getCurrentModule()->print(*OS);


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


[PATCH] D33735: [DebugInfo] Add ThisOrSelf attribute for emission of FlagObjectPointer.

2017-06-01 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In https://reviews.llvm.org/D33735#770288, @aaron.ballman wrote:

> Can you help me to understand what problem is being solved with this new 
> attribute? Under what circumstances would the first argument be an 
> `ImplicitParamDecl` but not an implicit this or self?


For captured regions an outlined function is created, where all parameters are 
ImplicitParamDecls. And the very first parameter is wrongly treated as 'this' 
argument of the member function.


https://reviews.llvm.org/D33735



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


[PATCH] D33588: Fix two sources of UB in __next_hash_pow2 (from __hash_table)

2017-06-01 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added inline comments.



Comment at: include/__hash_table:139
 {
-return size_t(1) << (std::numeric_limits::digits - __clz(__n-1));
+return (__n > 1) ? (size_t(1) << (std::numeric_limits::digits - 
__clz(__n-1))) : __n;
 }

EricWF wrote:
> Shouldn't this return  `__n + 1` when `__n <= 1`, or even 2 in both cases?
I thought "next_hash_pow2(n)" meant "a hash based on n or the first 
power-of-two GTE n", but I suppose it's actually "first power-of-two GTE than 
n, for hash tables". In this case, returning `1` when `__n <= 1` makes the most 
sense to me, since it's the first power of two GTE 0 and 1. What do you think?


https://reviews.llvm.org/D33588



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


r304444 - Remove late nullptr pointer test (PR32447)

2017-06-01 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Thu Jun  1 13:13:02 2017
New Revision: 30

URL: http://llvm.org/viewvc/llvm-project?rev=30=rev
Log:
Remove late nullptr pointer test (PR32447)

IgnoreNarrowingConversion should never return nullptr, but I've added an assert 
just in case.

Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=30=304443=30=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Jun  1 13:13:02 2017
@@ -330,13 +330,13 @@ StandardConversionSequence::getNarrowing
 } else if (FromType->isIntegralType(Ctx) && ToType->isRealFloatingType()) {
   llvm::APSInt IntConstantValue;
   const Expr *Initializer = IgnoreNarrowingConversion(Converted);
+  assert(Initializer && "Unknown conversion expression");
 
   // If it's value-dependent, we can't tell whether it's narrowing.
   if (Initializer->isValueDependent())
 return NK_Dependent_Narrowing;
 
-  if (Initializer &&
-  Initializer->isIntegerConstantExpr(IntConstantValue, Ctx)) {
+  if (Initializer->isIntegerConstantExpr(IntConstantValue, Ctx)) {
 // Convert the integer to the floating type.
 llvm::APFloat Result(Ctx.getFloatTypeSemantics(ToType));
 Result.convertFromAPInt(IntConstantValue, IntConstantValue.isSigned(),


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


[PATCH] D33698: [CodeGen][ObjC] Fix assertion failure in CodeGenFunction::EmitARCStoreStrongCall

2017-06-01 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304449: [CodeGen][ObjC] Fix assertion failure in 
EmitARCStoreStrongCall. (authored by ahatanak).

Changed prior to commit:
  https://reviews.llvm.org/D33698?vs=100787=101060#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33698

Files:
  cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
  cfe/trunk/test/CodeGenObjC/parameterized_classes.m


Index: cfe/trunk/test/CodeGenObjC/parameterized_classes.m
===
--- cfe/trunk/test/CodeGenObjC/parameterized_classes.m
+++ cfe/trunk/test/CodeGenObjC/parameterized_classes.m
@@ -68,3 +68,31 @@
   // CHECK: call i8* @objc_retainBlock
   // CHECK: ret void
 }
+
+// CHECK-LABEL: define internal void @"\01-[Derived setDest:]
+// CHECK: %[[SELFADDR:.*]] = alloca %[[SELFTY:.*]]*
+// CHECK: %[[AADDR:.*]] = alloca %[[IVARTY:.*]]*
+// CHECK: %[[V2:.*]] = load %[[IVARTY]]*, %[[IVARTY]]** %[[AADDR]]
+// CHECK: %[[V3:.*]] = load %[[SELFTY]]*, %[[SELFTY]]** %[[SELFADDR]]
+// CHECK: %[[IVAR:.*]] = load i64, i64* @"OBJC_IVAR_$_Base._destination"
+// CHECK: %[[V4:.*]] = bitcast %[[SELFTY]]* %[[V3]] to i8*
+// CHECK: %[[ADDPTR:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 
%[[IVAR]]
+// CHECK: %[[V5:.*]] = bitcast i8* %[[ADDPTR]] to %[[IVARTY]]**
+// CHECK: %[[V6:.*]] = bitcast %[[IVARTY]]** %[[V5]] to i8**
+// CHECK: %[[V7:.*]] = bitcast %[[IVARTY]]* %[[V2]] to i8*
+// CHECK: call void @objc_storeStrong(i8** %[[V6]], i8* %[[V7]])
+
+@interface Base : NSObject {
+  DestType _destination;
+}
+@end
+
+@interface Derived : Base
+- (void)setDest:(NSObject *)a;
+@end
+
+@implementation Derived
+- (void)setDest:(NSObject *)a {
+  _destination = a;
+}
+@end
Index: cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
===
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
@@ -90,7 +90,11 @@
unsigned CVRQualifiers,
llvm::Value *Offset) {
   // Compute (type*) ( (char *) BaseValue + Offset)
-  QualType IvarTy = Ivar->getType().withCVRQualifiers(CVRQualifiers);
+  QualType InterfaceTy{OID->getTypeForDecl(), 0};
+  QualType ObjectPtrTy =
+  CGF.CGM.getContext().getObjCObjectPointerType(InterfaceTy);
+  QualType IvarTy =
+  Ivar->getUsageType(ObjectPtrTy).withCVRQualifiers(CVRQualifiers);
   llvm::Type *LTy = CGF.CGM.getTypes().ConvertTypeForMem(IvarTy);
   llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, CGF.Int8PtrTy);
   V = CGF.Builder.CreateInBoundsGEP(V, Offset, "add.ptr");


Index: cfe/trunk/test/CodeGenObjC/parameterized_classes.m
===
--- cfe/trunk/test/CodeGenObjC/parameterized_classes.m
+++ cfe/trunk/test/CodeGenObjC/parameterized_classes.m
@@ -68,3 +68,31 @@
   // CHECK: call i8* @objc_retainBlock
   // CHECK: ret void
 }
+
+// CHECK-LABEL: define internal void @"\01-[Derived setDest:]
+// CHECK: %[[SELFADDR:.*]] = alloca %[[SELFTY:.*]]*
+// CHECK: %[[AADDR:.*]] = alloca %[[IVARTY:.*]]*
+// CHECK: %[[V2:.*]] = load %[[IVARTY]]*, %[[IVARTY]]** %[[AADDR]]
+// CHECK: %[[V3:.*]] = load %[[SELFTY]]*, %[[SELFTY]]** %[[SELFADDR]]
+// CHECK: %[[IVAR:.*]] = load i64, i64* @"OBJC_IVAR_$_Base._destination"
+// CHECK: %[[V4:.*]] = bitcast %[[SELFTY]]* %[[V3]] to i8*
+// CHECK: %[[ADDPTR:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 %[[IVAR]]
+// CHECK: %[[V5:.*]] = bitcast i8* %[[ADDPTR]] to %[[IVARTY]]**
+// CHECK: %[[V6:.*]] = bitcast %[[IVARTY]]** %[[V5]] to i8**
+// CHECK: %[[V7:.*]] = bitcast %[[IVARTY]]* %[[V2]] to i8*
+// CHECK: call void @objc_storeStrong(i8** %[[V6]], i8* %[[V7]])
+
+@interface Base : NSObject {
+  DestType _destination;
+}
+@end
+
+@interface Derived : Base
+- (void)setDest:(NSObject *)a;
+@end
+
+@implementation Derived
+- (void)setDest:(NSObject *)a {
+  _destination = a;
+}
+@end
Index: cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
===
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
@@ -90,7 +90,11 @@
unsigned CVRQualifiers,
llvm::Value *Offset) {
   // Compute (type*) ( (char *) BaseValue + Offset)
-  QualType IvarTy = Ivar->getType().withCVRQualifiers(CVRQualifiers);
+  QualType InterfaceTy{OID->getTypeForDecl(), 0};
+  QualType ObjectPtrTy =
+  CGF.CGM.getContext().getObjCObjectPointerType(InterfaceTy);
+  QualType IvarTy =
+  Ivar->getUsageType(ObjectPtrTy).withCVRQualifiers(CVRQualifiers);
   llvm::Type *LTy = CGF.CGM.getTypes().ConvertTypeForMem(IvarTy);
   llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, CGF.Int8PtrTy);
   V = CGF.Builder.CreateInBoundsGEP(V, Offset, "add.ptr");
___
cfe-commits mailing 

Re: [PATCH] D33424: Lexer: allow imaginary constants in GNU mode (only).

2017-06-01 Thread Richard Smith via cfe-commits
On 1 June 2017 at 14:36, Tim Northover  wrote:

> On 26 May 2017 at 11:29, Richard Smith  wrote:
> > If we generally think that distinction is a good thing, then (because
> this
> > is a conforming extension) consistency weakly suggests that it should
> not be
> > controlled by GNU mode. But I don't find that argument decisive; the
> > important thing is that we don't enable non-conforming extensions by
> default
> > in non-GNU (and non-MS-compat) modes, not that GNU mode consists of
> /only/
> > non-conforming extensions.
>
> I'm pretty convinced by the conforming/non-conforming distinction and
> consistency argument. And think that the Microsoft way seems even
> better for the future.
>
> Making the libc++ test pass is pretty ugly, but I've managed to get it
> working by building with "-Werror=gnu-imaginary-constant".
>
> Marshall, I know this really isn't your preferred solution but can you
> stomach it if I also make sure we do the extra diagnostics so it's
> difficult to misuse?
>
> > Looking at the
> >
> >   std::complex x = 1.0if;
> >
> > case again, I think there's another problem here: we support an implicit
> > conversion from _Complex float to float in C++ (without even a warning).
> > This conversion is valid in C, but at least GCC disallows it in its C++
> > mode. We should probably at least warn on that.
>
> Definitely. I think the error from G++ is probably the right choice.
> I'll get cracking on that, it's a good idea regardless of what happens
> here.
>

Great, thanks, your intended direction makes sense to me.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r304459 - [ubsan] Add a check for pointer overflow UB

2017-06-01 Thread Galina Kistanova via cfe-commits
Hello Vedant,

This commit broke tests on some of our builders:

Failing Tests (1):
Clang :: CodeGen/ubsan-pointer-overflow.m

http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/2865/steps/test-check-all/logs/stdio
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/10259
http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/3097
etc

Thanks

Galina

On Thu, Jun 1, 2017 at 12:22 PM, Vedant Kumar via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: vedantk
> Date: Thu Jun  1 14:22:18 2017
> New Revision: 304459
>
> URL: http://llvm.org/viewvc/llvm-project?rev=304459=rev
> Log:
> [ubsan] Add a check for pointer overflow UB
>
> Check pointer arithmetic for overflow.
>
> For some more background on this check, see:
>
>   https://wdtz.org/catching-pointer-overflow-bugs.html
>   https://reviews.llvm.org/D20322
>
> Patch by Will Dietz and John Regehr!
>
> This version of the patch is different from the original in a few ways:
>
>   - It introduces the EmitCheckedInBoundsGEP utility which inserts
> checks when the pointer overflow check is enabled.
>
>   - It does some constant-folding to reduce instrumentation overhead.
>
>   - It does not check some GEPs in CGExprCXX. I'm not sure that
> inserting checks here, or in CGClass, would catch many bugs.
>
> Possible future directions for this check:
>
>   - Introduce CGF.EmitCheckedStructGEP, to detect overflows when
> accessing structures.
>
> Testing: Apart from the added lit test, I ran check-llvm and check-clang
> with a stage2, ubsan-instrumented clang. Will and John have also done
> extensive testing on numerous open source projects.
>
> Differential Revision: https://reviews.llvm.org/D33305
>
> Added:
> cfe/trunk/test/CodeGen/ubsan-pointer-overflow.m
> Modified:
> cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
> cfe/trunk/include/clang/Basic/Sanitizers.def
> cfe/trunk/lib/CodeGen/CGExpr.cpp
> cfe/trunk/lib/CodeGen/CGExprScalar.cpp
> cfe/trunk/lib/CodeGen/CodeGenFunction.h
> cfe/trunk/test/Driver/fsanitize.c
>
> Modified: cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/
> UndefinedBehaviorSanitizer.rst?rev=304459=304458=304459=diff
> 
> ==
> --- cfe/trunk/docs/UndefinedBehaviorSanitizer.rst (original)
> +++ cfe/trunk/docs/UndefinedBehaviorSanitizer.rst Thu Jun  1 14:22:18 2017
> @@ -106,6 +106,8 @@ Available checks are:
>   invalid pointers. These checks are made in terms of
>   ``__builtin_object_size``, and consequently may be able to detect
> more
>   problems at higher optimization levels.
> +  -  ``-fsanitize=pointer-overflow``: Performing pointer arithmetic which
> + overflows.
>-  ``-fsanitize=return``: In C++, reaching the end of a
>   value-returning function without returning a value.
>-  ``-fsanitize=returns-nonnull-attribute``: Returning null pointer
>
> Modified: cfe/trunk/include/clang/Basic/Sanitizers.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/Sanitizers.def?rev=304459=304458=304459=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/Sanitizers.def (original)
> +++ cfe/trunk/include/clang/Basic/Sanitizers.def Thu Jun  1 14:22:18 2017
> @@ -73,6 +73,7 @@ SANITIZER("nullability-return", Nullabil
>  SANITIZER_GROUP("nullability", Nullability,
>  NullabilityArg | NullabilityAssign | NullabilityReturn)
>  SANITIZER("object-size", ObjectSize)
> +SANITIZER("pointer-overflow", PointerOverflow)
>  SANITIZER("return", Return)
>  SANITIZER("returns-nonnull-attribute", ReturnsNonnullAttribute)
>  SANITIZER("shift-base", ShiftBase)
> @@ -108,9 +109,9 @@ SANITIZER("safe-stack", SafeStack)
>  SANITIZER_GROUP("undefined", Undefined,
>  Alignment | Bool | ArrayBounds | Enum | FloatCastOverflow
> |
>  FloatDivideByZero | IntegerDivideByZero |
> NonnullAttribute |
> -Null | ObjectSize | Return | ReturnsNonnullAttribute |
> -Shift | SignedIntegerOverflow | Unreachable |
> VLABound |
> -Function | Vptr)
> +Null | ObjectSize | PointerOverflow | Return |
> +ReturnsNonnullAttribute | Shift |
> SignedIntegerOverflow |
> +Unreachable | VLABound | Function | Vptr)
>
>  // -fsanitize=undefined-trap is an alias for -fsanitize=undefined.
>  SANITIZER_GROUP("undefined-trap", UndefinedTrap, Undefined)
>
> Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/
> CGExpr.cpp?rev=304459=304458=304459=diff
> 
> ==
> --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
> +++ 

[PATCH] D33774: [CodeGen] Make __attribute__(const) calls speculatable

2017-06-01 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

Definition of `__attibute__((const))` from 
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes

> Many functions do not examine any values except their arguments, and have no 
> effects except the return value. Basically this is just slightly more strict 
> class than the pure attribute below, since function is not allowed to read 
> global memory.
>  Note that a function that has pointer arguments and examines the data 
> pointed to must not be declared const. Likewise, a function that calls a 
> non-const function usually must not be const. It does not make sense for a 
> const function to return void.

Definition of `speculatable` from 
http://llvm.org/docs/LangRef.html#function-attributes

> This function attribute indicates that the function does not have any effects 
> besides calculating its result and does not have undefined behavior.


https://reviews.llvm.org/D33774



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


[PATCH] D33776: [libcxx] LWG2221: No formatted output operator for nullptr

2017-06-01 Thread Agustín Bergé via Phabricator via cfe-commits
K-ballo created this revision.

With effects equivalent to `os << (const void*)nullptr`.


https://reviews.llvm.org/D33776

Files:
  include/ostream
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/nullptr_t.pass.cpp
  www/cxx1z_status.html

Index: www/cxx1z_status.html
===
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -356,7 +356,7 @@
  	
 	http://wg21.link/LWG2062;>2062Effect contradictions w/o no-throw guarantee of std::function swapsIssaquahComplete
 	http://wg21.link/LWG2166;>2166Heap property underspecified?Issaquah
-	http://wg21.link/LWG2221;>2221No formatted output operator for nullptrIssaquah
+	http://wg21.link/LWG2221;>2221No formatted output operator for nullptrIssaquahComplete
 	http://wg21.link/LWG2223;>2223shrink_to_fit effect on iterator validityIssaquahComplete
 	http://wg21.link/LWG2261;>2261Are containers required to use their 'pointer' type internally?Issaquah
 	http://wg21.link/LWG2394;>2394locale::name specification unclear - what is implementation-defined?IssaquahComplete
Index: test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/nullptr_t.pass.cpp
===
--- /dev/null
+++ test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/nullptr_t.pass.cpp
@@ -0,0 +1,81 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  >
+//   class basic_ostream;
+
+// operator<<(nullptr_t);
+
+#include 
+#include 
+#include 
+
+template 
+class testbuf
+: public std::basic_streambuf
+{
+typedef std::basic_streambuf base;
+std::basic_string str_;
+public:
+testbuf()
+{
+}
+
+std::basic_string str() const
+{return std::basic_string(base::pbase(), base::pptr());}
+
+protected:
+
+virtual typename base::int_type
+overflow(typename base::int_type __c = base::traits_type::eof())
+{
+if (__c != base::traits_type::eof())
+{
+int n = static_cast(str_.size());
+str_.push_back(static_cast(__c));
+str_.resize(str_.capacity());
+base::setp(const_cast(str_.data()),
+   const_cast(str_.data() + str_.size()));
+base::pbump(n+1);
+}
+return __c;
+}
+};
+
+int main()
+{
+{
+std::ostream os((std::streambuf*)0);
+std::nullptr_t n = nullptr;
+os << n;
+assert(os.bad());
+assert(os.fail());
+}
+{
+testbuf sb;
+std::ostream os();
+std::nullptr_t n = nullptr;
+os << n;
+assert(os.good());
+std::string s(sb.str());
+
+// Implementation defined. Instead of validating the output,
+// at least ensure that it does not generate an empty string.
+assert(!s.empty());
+}
+{
+testbuf sb;
+std::ostream os();
+std::nullptr_t const n = nullptr;
+os << n;
+assert(os.good());
+}
+}
Index: include/ostream
===
--- include/ostream
+++ include/ostream
@@ -56,6 +56,7 @@
 basic_ostream& operator<<(double f);
 basic_ostream& operator<<(long double f);
 basic_ostream& operator<<(const void* p);
+basic_ostream& operator<<(nullptr_t);
 basic_ostream& operator<<(basic_streambuf* sb);
 
 // 27.7.2.7 Unformatted output:
@@ -140,6 +141,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -218,6 +220,10 @@
 basic_ostream& operator<<(const void* __p);
 basic_ostream& operator<<(basic_streambuf* __sb);
 
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
+basic_ostream& operator<<(nullptr_t)
+{ return *this << (const void*)0; }
+
 // 27.7.2.7 Unformatted output:
 basic_ostream& put(char_type __c);
 basic_ostream& write(const char_type* __s, streamsize __n);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


<    1   2