Re: [PATCH] D24330: Add some MS aliases for existing intrinsics

2016-09-13 Thread Alexander Shaposhnikov via cfe-commits
alexshap added a subscriber: alexshap.


Comment at: include/clang/Basic/Builtins.h:142
@@ -141,1 +141,3 @@
 
+  // \brief Returns true if this builtin requires appropriate header in other
+  // compilers. In Clang it will work even without including it, but we can 
emit

should the doxygen comment start with /// here ? 


https://reviews.llvm.org/D24330



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


Re: [PATCH] D24330: Add some MS aliases for existing intrinsics

2016-09-13 Thread Reid Kleckner via cfe-commits
rnk added a comment.

lgtm We could define a macro that conditionally expands to `extern "C"`, but 
then we'd have to undef it, and that seems like no good.


https://reviews.llvm.org/D24330



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


r281436 - [docs] Fix formatting of characters so that tables line up properly. Add

2016-09-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Sep 13 21:24:50 2016
New Revision: 281436

URL: http://llvm.org/viewvc/llvm-project?rev=281436=rev
Log:
[docs] Fix formatting of  characters so that tables line up properly. Add
padding around table cells so the borders of adjacent tables don't run into
each other (now that they're perfectly aligned).

Modified:
cfe/trunk/docs/DiagnosticsReference.rst
cfe/trunk/include/clang/Basic/DiagnosticDocs.td

Modified: cfe/trunk/docs/DiagnosticsReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/DiagnosticsReference.rst?rev=281436=281435=281436=diff
==
--- cfe/trunk/docs/DiagnosticsReference.rst (original)
+++ cfe/trunk/docs/DiagnosticsReference.rst Tue Sep 13 21:24:50 2016
@@ -14,10 +14,11 @@
 }
 table.docutils td {
   border: none;
-  padding: 0;
+  padding: 0 0 0 0.2em;
   vertical-align: middle;
   white-space: nowrap;
   width: 1px;
+  font-family: monospace;
 }
 table.docutils tr + tr {
   border-top: 0.2em solid #aaa;
@@ -43,7 +44,8 @@
 }
 
 
-.. FIXME: Format this as .diagtext. rST appears to not support this. :(
+.. FIXME: rST doesn't support formatting this, so we format all  elements
+  as monospace font face instead.
 .. |nbsp| unicode:: 0xA0
:trim:
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDocs.td?rev=281436=281435=281436=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDocs.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDocs.td Tue Sep 13 21:24:50 2016
@@ -24,10 +24,11 @@ def GlobalDocumentation {
 }
 table.docutils td {
   border: none;
-  padding: 0;
+  padding: 0 0 0 0.2em;
   vertical-align: middle;
   white-space: nowrap;
   width: 1px;
+  font-family: monospace;
 }
 table.docutils tr + tr {
   border-top: 0.2em solid #aaa;
@@ -53,7 +54,8 @@ def GlobalDocumentation {
 }
 
 
-.. FIXME: Format this as .diagtext. rST appears to not support this. :(
+.. FIXME: rST doesn't support formatting this, so we format all  elements
+  as monospace font face instead.
 .. |nbsp| unicode:: 0xA0
:trim:
 


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


r281434 - [docs] Order diagnostic cross-references alphabetically rather than based on

2016-09-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Sep 13 20:55:42 2016
New Revision: 281434

URL: http://llvm.org/viewvc/llvm-project?rev=281434=rev
Log:
[docs] Order diagnostic cross-references alphabetically rather than based on
order in the .td file.

Modified:
cfe/trunk/docs/DiagnosticsReference.rst
cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp

Modified: cfe/trunk/docs/DiagnosticsReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/DiagnosticsReference.rst?rev=281434=281433=281434=diff
==
--- cfe/trunk/docs/DiagnosticsReference.rst (original)
+++ cfe/trunk/docs/DiagnosticsReference.rst Tue Sep 13 20:55:42 2016
@@ -312,7 +312,7 @@ This diagnostic is enabled by default.
 -
 This diagnostic is enabled by default.
 
-Controls `-Warc-unsafe-retained-assign`_, `-Warc-retain-cycles`_, 
`-Warc-non-pod-memaccess`_.
+Controls `-Warc-non-pod-memaccess`_, `-Warc-retain-cycles`_, 
`-Warc-unsafe-retained-assign`_.
 
 
 -Warc-bridge-casts-disallowed-in-nonarc
@@ -538,7 +538,7 @@ This diagnostic is enabled by default.
 
 -Watomic-properties
 ---
-Controls `-Wimplicit-atomic-properties`_, `-Wcustom-atomic-properties`_.
+Controls `-Wcustom-atomic-properties`_, `-Wimplicit-atomic-properties`_.
 
 
 -Watomic-property-with-user-defined-accessor
@@ -571,7 +571,7 @@ This diagnostic is enabled by default.
 
 This diagnostic is enabled by default.
 
-Controls `-Wunknown-attributes`_, `-Wignored-attributes`_.
+Controls `-Wignored-attributes`_, `-Wunknown-attributes`_.
 
 
 -Wauto-disable-vptr-sanitizer
@@ -918,7 +918,7 @@ Synonym for `-Wc++11-narrowing`_.
 --
 Some of the diagnostics controlled by this flag are enabled by default.
 
-Also controls `-Wc++11-narrowing`_, 
`-Wc++11-compat-reserved-user-defined-literal`_, 
`-Wc++11-compat-deprecated-writable-strings`_, `-Wc++98-c++11-compat`_, 
`-Wc++98-c++11-c++14-compat`_.
+Also controls `-Wc++11-compat-deprecated-writable-strings`_, 
`-Wc++11-compat-reserved-user-defined-literal`_, `-Wc++11-narrowing`_, 
`-Wc++98-c++11-c++14-compat`_, `-Wc++98-c++11-compat`_.
 
 **Diagnostic text:**
 
@@ -984,7 +984,7 @@ This diagnostic is enabled by default.
 
 -Wc++11-compat-pedantic
 ---
-Controls `-Wc++98-c++11-compat-pedantic`_, 
`-Wc++98-c++11-c++14-compat-pedantic`_.
+Controls `-Wc++98-c++11-c++14-compat-pedantic`_, 
`-Wc++98-c++11-compat-pedantic`_.
 
 
 -Wc++11-compat-reserved-user-defined-literal
@@ -1304,7 +1304,7 @@ Synonym for `-Wc++14-extensions`_.
 --
 This diagnostic is enabled by default.
 
-Controls `-Wdeprecated-register`_, `-Wdeprecated-increment-bool`_.
+Controls `-Wdeprecated-increment-bool`_, `-Wdeprecated-register`_.
 
 
 -Wc++1z-extensions
@@ -1504,7 +1504,7 @@ Also controls `-Wc++98-c++11-compat`_.
 
 -Wc++98-compat
 --
-Also controls `-Wc++98-compat-local-type-template-args`_, 
`-Wc++98-compat-unnamed-type-template-args`_, `-Wc++98-c++11-compat`_, 
`-Wc++98-c++11-c++14-compat`_.
+Also controls `-Wc++98-c++11-c++14-compat`_, `-Wc++98-c++11-compat`_, 
`-Wc++98-compat-local-type-template-args`_, 
`-Wc++98-compat-unnamed-type-template-args`_.
 
 **Diagnostic text:**
 
@@ -1845,7 +1845,7 @@ Also controls `-Wc++98-compat-local-type
 
 -Wc++98-compat-pedantic
 ---
-Also controls `-Wc++98-compat`_, `-Wc++98-compat-bind-to-temporary-copy`_, 
`-Wc++98-c++11-compat-pedantic`_, `-Wc++98-c++11-c++14-compat-pedantic`_.
+Also controls `-Wc++98-c++11-c++14-compat-pedantic`_, 
`-Wc++98-c++11-compat-pedantic`_, `-Wc++98-compat`_, 
`-Wc++98-compat-bind-to-temporary-copy`_.
 
 **Diagnostic text:**
 
@@ -2307,7 +2307,7 @@ This diagnostic is enabled by default.
 
 Some of the diagnostics controlled by this flag are enabled by default.
 
-Also controls `-Wbool-conversion`_, `-Wconstant-conversion`_, 
`-Wenum-conversion`_, `-Wfloat-conversion`_, `-Wshorten-64-to-32`_, 
`-Wint-conversion`_, `-Wliteral-conversion`_, `-Wnon-literal-null-conversion`_, 
`-Wnull-conversion`_, `-Wobjc-literal-conversion`_, `-Wsign-conversion`_, 
`-Wstring-conversion`_.
+Also controls `-Wbool-conversion`_, `-Wconstant-conversion`_, 
`-Wenum-conversion`_, `-Wfloat-conversion`_, `-Wint-conversion`_, 
`-Wliteral-conversion`_, `-Wnon-literal-null-conversion`_, 
`-Wnull-conversion`_, `-Wobjc-literal-conversion`_, `-Wshorten-64-to-32`_, 
`-Wsign-conversion`_, `-Wstring-conversion`_.
 
 **Diagnostic text:**
 
@@ -2822,7 +2822,7 @@ This diagnostic is enabled by default.
 
 -Wdocumentation
 ---
-Also controls `-Wdocumentation-html`_, `-Wdocumentation-deprecated-sync`_.
+Also controls `-Wdocumentation-deprecated-sync`_, `-Wdocumentation-html`_.
 
 **Diagnostic text:**
 
@@ -3326,7 +3326,7 @@ This diagnostic is enabled by default.
 ---
 Some of the diagnostics controlled by this flag are enabled by default.
 
-Controls `-Wmissing-field-initializers`_, `-Wignored-qualifiers`_, 
`-Winitializer-overrides`_, 

r281433 - Update DiagnosticsReference and fix emitter to emit -Wpedantic diagnostics and groups in a deterministic order.

2016-09-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Sep 13 20:51:10 2016
New Revision: 281433

URL: http://llvm.org/viewvc/llvm-project?rev=281433=rev
Log:
Update DiagnosticsReference and fix emitter to emit -Wpedantic diagnostics and 
groups in a deterministic order.

Modified:
cfe/trunk/docs/DiagnosticsReference.rst
cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp

Modified: cfe/trunk/docs/DiagnosticsReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/DiagnosticsReference.rst?rev=281433=281432=281433=diff
==
--- cfe/trunk/docs/DiagnosticsReference.rst (original)
+++ cfe/trunk/docs/DiagnosticsReference.rst Tue Sep 13 20:51:10 2016
@@ -2769,7 +2769,8 @@ This diagnostic is enabled by default.
 
 -Wdiv-by-zero
 -
-This diagnostic flag exists for GCC compatibility, and has no effect in Clang.
+Synonym for `-Wdivision-by-zero`_.
+
 
 -Wdivision-by-zero
 --
@@ -3107,7 +3108,8 @@ This diagnostic is enabled by default.
 
 -Weffc++
 
-This diagnostic flag exists for GCC compatibility, and has no effect in Clang.
+Synonym for `-Wnon-virtual-dtor`_.
+
 
 -Wembedded-directive
 
@@ -4320,6 +4322,8 @@ This diagnostic is enabled by default.
 |  
  
|++|
 |  
  ||:diagtext:`Objective-C protocols`   
||
 |  
  
|++|
+|  
  ||:diagtext:`variables with static or thread storage 
duration`||
+|  
  
|++|
 |  
  ||:diagtext:`functions and global variables`  
||
 |  
  
|++|
 |  
  ||:diagtext:`structs, unions, and typedefs`   
||
@@ -4608,6 +4612,14 @@ This diagnostic is enabled by default.
 |:warning:`warning:` |nbsp| :diagtext:`'#pragma init\_seg' is only supported 
when targeting a Microsoft environment`|
 
+---+
 
++--+--+
+|:warning:`warning:` |nbsp| :placeholder:`A` |nbsp| :diagtext:`is not a 
recognized 
builtin`|++|
+|  
||  
  ||
+|  

|++|
+|  
||:diagtext:`; consider including  to access non-builtin 
intrinsics`||
+|  

|++|
++--+--+
+
 
+-+
 |:warning:`warning:` |nbsp| :diagtext:`unknown action for '#pragma` |nbsp| 
:placeholder:`A`:diagtext:`' - ignored`|
 
+-+
@@ -7446,131 +7458,37 @@ This diagnostic is enabled by default.
 
 -Wpedantic
 --
-Also controls 

r281432 - [sanitizer-coverage] add yet another flavour of coverage instrumentation: trace-pc-guard. The intent is to eventually replace all of {bool coverage, 8bit-counters, trace-pc} with just this o

2016-09-13 Thread Kostya Serebryany via cfe-commits
Author: kcc
Date: Tue Sep 13 20:39:49 2016
New Revision: 281432

URL: http://llvm.org/viewvc/llvm-project?rev=281432=rev
Log:
[sanitizer-coverage] add yet another flavour of coverage instrumentation: 
trace-pc-guard. The intent is to eventually replace all of {bool coverage, 
8bit-counters, trace-pc} with just this one. Clang part

Modified:
cfe/trunk/docs/SanitizerCoverage.rst
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/fsanitize-coverage.c

Modified: cfe/trunk/docs/SanitizerCoverage.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/SanitizerCoverage.rst?rev=281432=281431=281432=diff
==
--- cfe/trunk/docs/SanitizerCoverage.rst (original)
+++ cfe/trunk/docs/SanitizerCoverage.rst Tue Sep 13 20:39:49 2016
@@ -321,6 +321,32 @@ by the user. So, these flags do not requ
 This mechanism is used for fuzzing the Linux kernel 
(https://github.com/google/syzkaller)
 and can be used with `AFL `__.
 
+Tracing PCs with guards
+===
+Another *experimental* feature that tries to combine `trace-pc`,
+`8bit-counters` and boolean coverage
+
+With ``-fsanitize-coverage=trace-pc-guard`` the compiler will insert the 
following code
+on every edge:
+
+.. code-block:: none
+
+   if (guard_variable != 0xff)
+ __sanitizer_cov_trace_pc_guard(_variable)
+
+Every edge will have its own 1-byte `guard_variable`.
+All such guard variables will reside in a dedicated section
+(i.e. they essentially form an array).
+
+The compler will also insert a module constructor that will call
+
+.. code-block:: c++
+
+   // The guard section is the address range [start, stop).
+   __sanitizer_cov_trace_pc_guard_init(void *start, void *stop);
+
+The functions `__sanitizer_cov_trace_pc_guard[_init]` should be defined by the 
user.
+
 Tracing data flow
 =
 

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=281432=281431=281432=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Sep 13 20:39:49 2016
@@ -289,6 +289,9 @@ def fsanitize_coverage_8bit_counters
 def fsanitize_coverage_trace_pc
 : Flag<["-"], "fsanitize-coverage-trace-pc">,
   HelpText<"Enable PC tracing in sanitizer coverage">;
+def fsanitize_coverage_trace_pc_guard
+: Flag<["-"], "fsanitize-coverage-trace-pc-guard">,
+  HelpText<"Enable PC tracing with guard in sanitizer coverage">;
 def fprofile_instrument_EQ : Joined<["-"], "fprofile-instrument=">,
 HelpText<"Enable PGO instrumentation. The accepted value is clang, llvm, "
  "or none">;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=281432=281431=281432=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Sep 13 20:39:49 2016
@@ -160,6 +160,8 @@ CODEGENOPT(SanitizeCoverage8bitCounters,
///< in sanitizer coverage.
 CODEGENOPT(SanitizeCoverageTracePC, 1, 0) ///< Enable PC tracing
   ///< in sanitizer coverage.
+CODEGENOPT(SanitizeCoverageTracePCGuard, 1, 0) ///< Enable PC tracing with 
guard
+   ///< in sanitizer coverage.
 CODEGENOPT(SanitizeStats , 1, 0) ///< Collect statistics for sanitizers.
 CODEGENOPT(SimplifyLibCalls  , 1, 1) ///< Set when -fbuiltin is enabled.
 CODEGENOPT(SoftFloat , 1, 0) ///< -soft-float.

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=281432=281431=281432=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Sep 13 20:39:49 2016
@@ -180,6 +180,7 @@ static void addSanitizerCoveragePass(con
   Opts.TraceGep = CGOpts.SanitizeCoverageTraceGep;
   Opts.Use8bitCounters = CGOpts.SanitizeCoverage8bitCounters;
   Opts.TracePC = CGOpts.SanitizeCoverageTracePC;
+  Opts.TracePCGuard = CGOpts.SanitizeCoverageTracePCGuard;
   PM.add(createSanitizerCoverageModulePass(Opts));
 }
 

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=281432=281431=281432=diff

Re: [PATCH] D23820: Do not warn about format strings that are indexed string literals.

2016-09-13 Thread Meike Baumgärtner via cfe-commits
meikeb marked an inline comment as done.


Comment at: lib/Sema/SemaChecking.cpp:3864-3867
@@ +3863,6 @@
+ResOffset = Offset.sadd_ov(Addend, Ov);
+  else {
+assert(AddendIsRight && BinOpKind == BO_Sub &&
+   "operator must be add or sub with addend on the right");
+ResOffset = Offset.ssub_ov(Addend, Ov);
+  }

This is way better. Thank you.


https://reviews.llvm.org/D23820



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


Re: [PATCH] D23820: Do not warn about format strings that are indexed string literals.

2016-09-13 Thread Meike Baumgärtner via cfe-commits
meikeb marked 2 inline comments as done.
meikeb added a comment.

https://reviews.llvm.org/D23820



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


Re: [PATCH] D23820: Do not warn about format strings that are indexed string literals.

2016-09-13 Thread Meike Baumgärtner via cfe-commits
meikeb updated this revision to Diff 71284.
meikeb added a comment.

Try to improve offset sum helper function name and fix style issues.


https://reviews.llvm.org/D23820

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/format-strings.c

Index: test/Sema/format-strings.c
===
--- test/Sema/format-strings.c
+++ test/Sema/format-strings.c
@@ -652,3 +652,38 @@
   // expected-note@-1{{treat the string as an argument to avoid this}}
 }
 #pragma GCC diagnostic warning "-Wformat-nonliteral"
+
+void test_char_pointer_arithmetic(int b) {
+  const char s1[] = "string";
+  const char s2[] = "%s string";
+
+  printf(s1 - 1);  // expected-warning {{format string is not a string literal (potentially insecure)}}
+  // expected-note@-1{{treat the string as an argument to avoid this}}
+
+  printf(s1 + 2);  // no-warning
+  printf(s2 + 2);  // no-warning
+
+  const char s3[] = "%s string";
+  printf((s3 + 2) - 2);  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + s2); // no-warning
+  printf(6 + s2 - 2); // no-warning
+  printf(2 + (b ? s1 : s2));  // no-warning
+
+  const char s5[] = "string %s";
+  printf(2 + (b ? s2 : s5));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + (b ? s2 : s5), "");  // no-warning
+  printf(2 + (b ? s1 : s2 - 2), "");  // no-warning
+
+  const char s6[] = "%s string";
+  printf(2 + (b ? s1 : s6 - 2));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(1 ? s2 + 2 : s2);  // no-warning
+  printf(0 ? s2 : s2 + 2);  // no-warning
+  printf(2 + s2 + 5 * 3 - 16, "");  // expected-warning{{data argument not used}}
+
+  const char s7[] = "%s string %s %s";
+  printf(s7 + 3, "");  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -3839,7 +3839,95 @@
 };
 } // end anonymous namespace
 
-static void CheckFormatString(Sema , const StringLiteral *FExpr,
+static void sumOffsets(llvm::APSInt , llvm::APSInt Addend,
+ BinaryOperatorKind BinOpKind,
+ bool AddendIsRight) {
+  unsigned BitWidth = Offset.getBitWidth();
+  unsigned AddendBitWidth = Addend.getBitWidth();
+  // There might be negative interim results.
+  if (Addend.isUnsigned()) {
+Addend = Addend.zext(++AddendBitWidth);
+Addend.setIsSigned(true);
+  }
+  // Adjust the bit width of the APSInts.
+  if (AddendBitWidth > BitWidth) {
+Offset = Offset.sext(AddendBitWidth);
+BitWidth = AddendBitWidth;
+  } else if (BitWidth > AddendBitWidth) {
+Addend = Addend.sext(BitWidth);
+  }
+
+  bool Ov = false;
+  llvm::APSInt ResOffset = Offset;
+  if (BinOpKind == BO_Add)
+ResOffset = Offset.sadd_ov(Addend, Ov);
+  else if (AddendIsRight && BinOpKind == BO_Sub)
+ResOffset = Offset.ssub_ov(Addend, Ov);
+  else
+assert(AddendIsRight && BinOpKind == BO_Sub &&
+   "operator must be add or sub with addend on the right");
+
+  // We add an offset to a pointer here so we should support an offset as big as
+  // possible.
+  if (Ov) {
+assert(BitWidth <= UINT_MAX / 2 && "index (intermediate) result too big");
+Offset.sext(2 * BitWidth);
+sumOffsets(Offset, Addend, BinOpKind, AddendIsRight);
+return;
+  }
+
+  Offset = ResOffset;
+}
+
+namespace {
+// This is a wrapper class around StringLiteral to support offsetted string
+// literals as format strings. It takes the offset into account when returning
+// the string and its length or the source locations to display notes correctly.
+class FormatStringLiteral {
+  const StringLiteral *FExpr;
+  int64_t Offset;
+
+ public:
+  FormatStringLiteral(const StringLiteral *fexpr, int64_t Offset = 0)
+  : FExpr(fexpr), Offset(Offset) {}
+
+  StringRef getString() const {
+return FExpr->getString().drop_front(Offset);
+  }
+
+  unsigned getByteLength() const {
+return FExpr->getByteLength() - getCharByteWidth() * Offset;
+  }
+  unsigned getLength() const { return FExpr->getLength() - Offset; }
+  unsigned getCharByteWidth() const { return FExpr->getCharByteWidth(); }
+
+  StringLiteral::StringKind getKind() const { return FExpr->getKind(); }
+
+  QualType getType() const { return FExpr->getType(); }
+
+  bool isAscii() const { return FExpr->isAscii(); }
+  bool isWide() const { return FExpr->isWide(); }
+  bool isUTF8() const { return FExpr->isUTF8(); }
+  bool isUTF16() const { return FExpr->isUTF16(); }
+  bool isUTF32() const { return FExpr->isUTF32(); }
+  bool isPascal() const { return FExpr->isPascal(); }
+
+  SourceLocation 

r281430 - Follow-up to r281367: Compare uuids case-insensitively.

2016-09-13 Thread Nico Weber via cfe-commits
Author: nico
Date: Tue Sep 13 20:16:54 2016
New Revision: 281430

URL: http://llvm.org/viewvc/llvm-project?rev=281430=rev
Log:
Follow-up to r281367: Compare uuids case-insensitively.

Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/SemaCXX/ms-uuid.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=281430=281429=281430=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Sep 13 20:16:54 2016
@@ -4607,7 +4607,7 @@ static void handleObjCPreciseLifetimeAtt
 UuidAttr *Sema::mergeUuidAttr(Decl *D, SourceRange Range,
   unsigned AttrSpellingListIndex, StringRef Uuid) {
   if (const auto *UA = D->getAttr()) {
-if (UA->getGuid() == Uuid)
+if (UA->getGuid().equals_lower(Uuid))
   return nullptr;
 Diag(UA->getLocation(), diag::err_mismatched_uuid);
 Diag(Range.getBegin(), diag::note_previous_uuid);

Modified: cfe/trunk/test/SemaCXX/ms-uuid.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms-uuid.cpp?rev=281430=281429=281430=diff
==
--- cfe/trunk/test/SemaCXX/ms-uuid.cpp (original)
+++ cfe/trunk/test/SemaCXX/ms-uuid.cpp Tue Sep 13 20:16:54 2016
@@ -29,7 +29,8 @@ namespace {
 
 // Both cl and clang-cl accept this:
 class __declspec(uuid("00A0---C000-0049")) C1;
-class __declspec(uuid("00A0---C000-0049")) C1;
+class __declspec(uuid("00a0---c000-0049")) C1;
+class __declspec(uuid("{00a0---C000-0049}")) C1;
 class __declspec(uuid("00A0---C000-0049")) C1 {};
 
 // Both cl and clang-cl error out on this:


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


Re: [PATCH] D23820: Do not warn about format strings that are indexed string literals.

2016-09-13 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/Sema/SemaChecking.cpp:3864-3867
@@ +3863,6 @@
+ResOffset = Offset.sadd_ov(Addend, Ov);
+  else if (AddendIsRight && BinOpKind == BO_Sub)
+ResOffset = Offset.ssub_ov(Addend, Ov);
+  else
+assert(AddendIsRight && BinOpKind == BO_Sub &&
+   "operator must be add or sub with addend on the right");

The suggestion was to remove the condition in the `else if` and put the 
assertion inside its body, rather than duplicating it here:

  if (BinOpKind == BO_Add)
// handle add
  else {
assert(it's a subtract);
// handle sub
  }


https://reviews.llvm.org/D23820



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


Re: r281351 - Add a class ObjCProtocolQualifiers to wrap APIs for ObjC protocol list.

2016-09-13 Thread Artem Belevich via cfe-commits
Thanks for the quick fix. ASAN is happy now.

--Artem

On Tue, Sep 13, 2016 at 3:09 PM, Manman  wrote:

> I checked in r281404. Hopefully it will fix the issue.
>
> Let me know if it does not.
>
> Thanks,
> Manman
>
> On Sep 13, 2016, at 3:03 PM, Artem Belevich via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Manman,
>
> FYI, It appears that some of your ObjC commits today trigger asan error.
> Sanitizer bots are broken by PR30341, so they don't report the issue yet.
>
> --Artem
>
> $ llvm/tools/clang/clang -cc1 -internal-isystem 
> llvm/tools/clang/staging/include
> -nostdsysteminc -fblocks -fsyntax-only -Wnullable-to-nonnull-conversion
> llvm/tools/clang/test/SemaObjC/parameterized_classes_subst.m -verify
> =
> ==223101==ERROR: AddressSanitizer: use-after-poison on address
> 0x62191288 at pc 0x01a02b3f bp 0x7f2996f0 sp 0x7f2996e8
> WRITE of size 4 at 0x62191288 thread T0
> #0 0x1a02b3e in clang::ObjCTypeParamTypeLoc::
> setProtocolRAngleLoc(clang::SourceLocation) third_party/llvm/llvm/tools/
> clang/include/clang/AST/TypeLoc.h:737:55
> #1 0x213f86b in 
> clang::Sema::actOnObjCTypeArgsAndProtocolQualifiers(clang::Scope*,
> clang::SourceLocation, clang::OpaquePtr,
> clang::SourceLocation, llvm::ArrayRef >, clang::SourceLocation, clang::SourceLocation,
> llvm::ArrayRef, llvm::ArrayRef,
> clang::SourceLocation) third_party/llvm/llvm/tools/
> clang/lib/Sema/SemaType.cpp:1165:13
> #2 0x2060347 in clang::Parser::parseObjCTypeArgsAndProtocolQu
> alifiers(clang::SourceLocation, clang::OpaquePtr, bool,
> clang::SourceLocation&) third_party/llvm/llvm/tools/
> clang/lib/Parse/ParseObjc.cpp:1878:18
> #3 0x1ffca6f in 
> clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool,
> bool, clang::CXXScopeSpec&, bool) third_party/llvm/llvm/tools/
> clang/lib/Parse/Parser.cpp:1770:13
> #4 0x1ffd4fc in clang::Parser::TryAnnotateTypeOrScopeToken(bool,
> bool) third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:1733:10
> #5 0x20df910 in clang::Parser::isTypeSpecifierQualifier()
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseDecl.cpp:4381:9
> #6 0x205ecf5 in clang::Parser::ParseObjCTypeName(clang::ObjCDeclSpec&,
> clang::Declarator::TheContext, clang::ParsedAttributes*)
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:1274:7
> #7 0x205c8f9 in clang::Parser::ParseObjCMethodDecl(clang::SourceLocation,
> clang::tok::TokenKind, clang::tok::ObjCKeywordKind, bool)
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:1428:22
> #8 0x2058e8b in 
> clang::Parser::ParseObjCInterfaceDeclList(clang::tok::ObjCKeywordKind,
> clang::Decl*) third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:
> 633:11
> #9 0x2053154 in 
> clang::Parser::ParseObjCAtInterfaceDeclaration(clang::SourceLocation,
> clang::ParsedAttributes&) third_party/llvm/llvm/tools/
> clang/lib/Parse/ParseObjc.cpp:388:3
> #10 0x2051fa9 in clang::Parser::ParseObjCAtDirectives()
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:63:18
> #11 0x1ff7871 in clang::Parser::ParseExternalDeclaration(
> clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*)
> third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:757:12
> #12 0x1ff6c61 in clang::Parser::ParseTopLevelDecl(clang::
> OpaquePtr&) third_party/llvm/llvm/tools/
> clang/lib/Parse/Parser.cpp:628:12
> #13 0x1ff016d in clang::ParseAST(clang::Sema&, bool, bool)
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseAST.cpp:147:18
> #14 0x1ab05d3 in clang::FrontendAction::Execute()
> third_party/llvm/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:458:8
> #15 0x184fbd6 in 
> clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
> third_party/llvm/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:871:11
> #16 0x5c6f47 in clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
> third_party/llvm/llvm/tools/clang/lib/FrontendTool/
> ExecuteCompilerInvocation.cpp:249:25
> #17 0x5a114d in cc1_main(llvm::ArrayRef, char const*,
> void*) third_party/llvm/llvm/tools/clang/tools/driver/cc1_main.cpp:183:13
> #18 0x5bb3f6 in ExecuteCC1Tool(llvm::ArrayRef,
> llvm::StringRef) third_party/llvm/llvm/tools/
> clang/tools/driver/driver.cpp:299:12
> #19 0x5ba314 in main third_party/llvm/llvm/tools/
> clang/tools/driver/driver.cpp:380:12
>
> 0x62191288 is located 392 bytes inside of 4096-byte region
> [0x62191100,0x62192100)
> allocated by thread T0 here:
> #0 0x58a52c in __interceptor_malloc third_party/llvm/llvm/
> projects/compiler-rt/lib/asan/asan_malloc_linux.cc:64:3
> #1 0x5a5d0b in llvm::MallocAllocator::Allocate(unsigned long,
> unsigned long) third_party/llvm/llvm/include/
> llvm/Support/Allocator.h:95:12
> #2 0x691b67 in llvm::BumpPtrAllocatorImpl 4096ul, 4096ul>::StartNewSlab() third_party/llvm/llvm/include/
> 

r281427 - Color warnings purple rather than orange, to match actual Clang output.

2016-09-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Sep 13 19:35:56 2016
New Revision: 281427

URL: http://llvm.org/viewvc/llvm-project?rev=281427=rev
Log:
Color warnings purple rather than orange, to match actual Clang output.

Modified:
cfe/trunk/docs/DiagnosticsReference.rst
cfe/trunk/include/clang/Basic/DiagnosticDocs.td

Modified: cfe/trunk/docs/DiagnosticsReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/DiagnosticsReference.rst?rev=281427=281426=281427=diff
==
--- cfe/trunk/docs/DiagnosticsReference.rst (original)
+++ cfe/trunk/docs/DiagnosticsReference.rst Tue Sep 13 19:35:56 2016
@@ -30,7 +30,7 @@
 .warning {
   font-family: monospace;
   font-weight: bold;
-  color: #c70;
+  color: #80a;
 }
 .remark {
   font-family: monospace;

Modified: cfe/trunk/include/clang/Basic/DiagnosticDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDocs.td?rev=281427=281426=281427=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDocs.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDocs.td Tue Sep 13 19:35:56 2016
@@ -40,7 +40,7 @@ def GlobalDocumentation {
 .warning {
   font-family: monospace;
   font-weight: bold;
-  color: #c70;
+  color: #80a;
 }
 .remark {
   font-family: monospace;


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


Re: [PATCH] D24069: Document option '-rtlib' in clang's man page and help info

2016-09-13 Thread Lei Zhang via cfe-commits
zlei added a comment.

In https://reviews.llvm.org/D24069#540804, @Hahnfeld wrote:

> @zlei will you commit the patch or do you want me to do that on your behalf?


I don't have commit access, so please do me a favor :)


https://reviews.llvm.org/D24069



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


Re: [PATCH] D24330: Add some MS aliases for existing intrinsics

2016-09-13 Thread Albert Gutowski via cfe-commits
agutowski updated this revision to Diff 71271.
agutowski added a comment.

Add extern "C" to Intel intrinsics declarations


https://reviews.llvm.org/D24330

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/Builtins.h
  include/clang/Basic/BuiltinsX86.def
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/emmintrin.h
  lib/Headers/ia32intrin.h
  lib/Headers/intrin.h
  lib/Headers/xmmintrin.h
  lib/Sema/SemaDecl.cpp
  test/CodeGen/builtins-x86.c
  test/Headers/x86intrin.cpp
  test/Sema/implicit-intel-builtin-decl.c
  test/Sema/implicit-ms-builtin-decl.c

Index: lib/Headers/ia32intrin.h
===
--- lib/Headers/ia32intrin.h
+++ lib/Headers/ia32intrin.h
@@ -60,12 +60,6 @@
   return __builtin_ia32_rdpmc(__A);
 }
 
-/* __rdtsc */
-static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
-__rdtsc(void) {
-  return __builtin_ia32_rdtsc();
-}
-
 /* __rdtscp */
 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
 __rdtscp(unsigned int *__A) {
Index: lib/Headers/emmintrin.h
===
--- lib/Headers/emmintrin.h
+++ lib/Headers/emmintrin.h
@@ -2447,6 +2447,10 @@
 }
 #endif
 
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 /// \brief The cache line containing __p is flushed and invalidated from all
 ///caches in the coherency domain.
 ///
@@ -2457,11 +2461,7 @@
 /// \param __p
 ///A pointer to the memory location used to identify the cache line to be
 ///flushed.
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_clflush(void const *__p)
-{
-  __builtin_ia32_clflush(__p);
-}
+void _mm_clflush(void const *);
 
 /// \brief Forces strong memory ordering (serialization) between load
 ///instructions preceding this instruction and load instructions following
@@ -2472,11 +2472,7 @@
 ///
 /// This intrinsic corresponds to the \c LFENCE instruction.
 ///
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_lfence(void)
-{
-  __builtin_ia32_lfence();
-}
+void _mm_lfence(void);
 
 /// \brief Forces strong memory ordering (serialization) between load and store
 ///instructions preceding this instruction and load and store instructions
@@ -2487,12 +2483,12 @@
 ///
 /// This intrinsic corresponds to the \c MFENCE instruction.
 ///
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_mfence(void)
-{
-  __builtin_ia32_mfence();
-}
+void _mm_mfence(void);
 
+#if defined(__cplusplus)
+} // extern "C"
+#endif
+
 /// \brief Converts 16-bit signed integers from both 128-bit integer vector
 ///operands into 8-bit signed integers, and packs the results into the
 ///destination. Positive values greater than 0x7F are saturated to 0x7F.
@@ -3213,11 +3209,10 @@
 ///
 /// This intrinsic corresponds to the \c PAUSE instruction.
 ///
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_pause(void)
-{
-  __builtin_ia32_pause();
-}
+#if defined(__cplusplus)
+extern "C"
+#endif
+void _mm_pause(void);
 
 #undef __DEFAULT_FN_ATTRS
 
Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+++ lib/Headers/intrin.h
@@ -463,14 +463,6 @@
   *_Index = 31 - __builtin_clzl(_Mask);
   return 1;
 }
-static __inline__ unsigned short __DEFAULT_FN_ATTRS
-__popcnt16(unsigned short _Value) {
-  return __builtin_popcount((int)_Value);
-}
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
-__popcnt(unsigned int _Value) {
-  return __builtin_popcount(_Value);
-}
 static __inline__ unsigned char __DEFAULT_FN_ATTRS
 _bittest(long const *_BitBase, long _BitPos) {
   return (*_BitBase >> _BitPos) & 1;
@@ -513,11 +505,6 @@
   *_Index = 63 - __builtin_clzll(_Mask);
   return 1;
 }
-static __inline__
-unsigned __int64 __DEFAULT_FN_ATTRS
-__popcnt64(unsigned __int64 _Value) {
-  return __builtin_popcountll(_Value);
-}
 static __inline__ unsigned char __DEFAULT_FN_ATTRS
 _bittest64(__int64 const *_BitBase, __int64 _BitPos) {
   return (*_BitBase >> _BitPos) & 1;
@@ -546,63 +533,63 @@
   __atomic_fetch_or(_BitBase, 1ll << _BitPos, __ATOMIC_SEQ_CST);
   return (_PrevVal >> _BitPos) & 1;
 }
-/**\
-|* Interlocked Exchange Add
-\**/
-static __inline__ __int64 __DEFAULT_FN_ATTRS
-_InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value) {
-	return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST);
-}
-/**\
-|* Interlocked Exchange Sub
-\**/
-static __inline__ __int64 __DEFAULT_FN_ATTRS
-_InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value) {
-	return __atomic_fetch_sub(_Subend, _Value, __ATOMIC_SEQ_CST);
-}

Re: [PATCH] D23820: Do not warn about format strings that are indexed string literals.

2016-09-13 Thread Richard Smith via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

This basically looks fine to me now. I'm not 100% sold on 
`sumUpStringLiteralOffset` being the best name, but I think we have better 
things to worry about, and it's good enough. Just a couple of minor style 
issues then I think this is good to go.



Comment at: lib/Sema/SemaChecking.cpp:3866-3867
@@ +3865,4 @@
+ResOffset = Offset.ssub_ov(Addend, Ov);
+  else
+assert(false && "operator must be add or sub with addend on the right");
+

Rather than `assert(false && XXX);`, use either `llvm_unreachable(XXX)` or 
change the previous case to be:

  else {
assert(AddendIsRight && BinOpKind == BO_Sub &&
   "operator must be ...");


Comment at: lib/Sema/SemaChecking.cpp:4150-4151
@@ +4149,4 @@
+  }
+  FormatStringLiteral FStr =
+  FormatStringLiteral(StrE, Offset.sextOrTrunc(64).getSExtValue());
+  CheckFormatString(S, , E, Args, HasVAListArg, format_idx,

You can write this more simply as

  FormatStringLiteral FStr(StrE, Offset.sextOrTrunc(64).getSExtValue());


https://reviews.llvm.org/D23820



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


Re: [PATCH] D24330: Add some MS aliases for existing intrinsics

2016-09-13 Thread Albert Gutowski via cfe-commits
agutowski reopened this revision.
agutowski added a comment.
This revision is now accepted and ready to land.

xmmintrin.h and emmintrin.h broke compilation when included inside extern "C++" 
block


Repository:
  rL LLVM

https://reviews.llvm.org/D24330



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


r281415 - Missed update from r281412.

2016-09-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Sep 13 18:03:41 2016
New Revision: 281415

URL: http://llvm.org/viewvc/llvm-project?rev=281415=rev
Log:
Missed update from r281412.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=281415=281414=281415=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Sep 13 18:03:41 
2016
@@ -7810,7 +7810,7 @@ def err_invalid_protocol_qualifiers : Er
   "invalid protocol qualifiers on non-ObjC type">;
 def warn_ivar_use_hidden : Warning<
   "local declaration of %0 hides instance variable">,
-   InGroup>;
+   InGroup;
 def warn_direct_initialize_call : Warning<
   "explicit call to +initialize results in duplicate call to +initialize">,
InGroup;


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


Re: r281395 - Try harder to not inline dllimport functions referencing non-dllimport functions

2016-09-13 Thread Hans Wennborg via cfe-commits
r281413 for the constructors.

On Tue, Sep 13, 2016 at 2:58 PM, Hans Wennborg  wrote:
> Good point. Constructors are also a problem, I'll try to fix.
>
> It's not exactly the same issue, because they do show up in the AST,
> but they're referenced with a CXXConstructExpr, and not the
> DeclRefExpr which DLLImportFunctionVisitor is looking for.
>
> There doesn't seem to be any problem with operator= though.
>
> On Tue, Sep 13, 2016 at 2:36 PM, Nico Weber via cfe-commits
>  wrote:
>> Could other implicit functions (operator=, ctors) have similar issues?
>>
>> On Tue, Sep 13, 2016 at 5:08 PM, Hans Wennborg via cfe-commits
>>  wrote:
>>>
>>> Author: hans
>>> Date: Tue Sep 13 16:08:20 2016
>>> New Revision: 281395
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=281395=rev
>>> Log:
>>> Try harder to not inline dllimport functions referencing non-dllimport
>>> functions
>>>
>>> In r246338, code was added to check for this, but it failed to take into
>>> account implicit destructor invocations because those are not reflected
>>> in the AST. This adds a separate check for them.
>>>
>>> Modified:
>>> cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>>> cfe/trunk/test/CodeGenCXX/dllimport-members.cpp
>>> cfe/trunk/test/CodeGenCXX/dllimport.cpp
>>>
>>> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=281395=281394=281395=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
>>> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Sep 13 16:08:20 2016
>>> @@ -1740,8 +1740,17 @@ CodeGenModule::isTriviallyRecursive(cons
>>>return Walker.Result;
>>>  }
>>>
>>> -bool
>>> -CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
>>> +// Check if T is a class type with a destructor that's not dllimport.
>>> +static bool HasNonDllImportDtor(QualType T) {
>>> +  if (const RecordType *RT = dyn_cast(T))
>>> +if (CXXRecordDecl *RD = dyn_cast(RT->getDecl()))
>>> +  if (RD->getDestructor() &&
>>> !RD->getDestructor()->hasAttr())
>>> +return true;
>>> +
>>> +  return false;
>>> +}
>>> +
>>> +bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
>>>if (getFunctionLinkage(GD) !=
>>> llvm::Function::AvailableExternallyLinkage)
>>>  return true;
>>>const auto *F = cast(GD.getDecl());
>>> @@ -1754,6 +1763,18 @@ CodeGenModule::shouldEmitFunction(Global
>>>  Visitor.TraverseFunctionDecl(const_cast(F));
>>>  if (!Visitor.SafeToInline)
>>>return false;
>>> +
>>> +if (const CXXDestructorDecl *Dtor = dyn_cast(F)) {
>>> +  // Implicit destructor invocations aren't captured in the AST, so
>>> the
>>> +  // check above can't see them. Check for them manually here.
>>> +  for (const Decl *Member : Dtor->getParent()->decls())
>>> +if (isa(Member))
>>> +  if (HasNonDllImportDtor(cast(Member)->getType()))
>>> +return false;
>>> +  for (const CXXBaseSpecifier  : Dtor->getParent()->bases())
>>> +if (HasNonDllImportDtor(B.getType()))
>>> +  return false;
>>> +}
>>>}
>>>
>>>// PR9614. Avoid cases where the source code is lying to us. An
>>> available
>>>
>>> Modified: cfe/trunk/test/CodeGenCXX/dllimport-members.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-members.cpp?rev=281395=281394=281395=diff
>>>
>>> ==
>>> --- cfe/trunk/test/CodeGenCXX/dllimport-members.cpp (original)
>>> +++ cfe/trunk/test/CodeGenCXX/dllimport-members.cpp Tue Sep 13 16:08:20
>>> 2016
>>> @@ -44,7 +44,7 @@ void useSpecials() {
>>>  }
>>>
>>>  // Used to force non-trivial special members.
>>> -struct ForceNonTrivial {
>>> +struct __declspec(dllimport) ForceNonTrivial {
>>>ForceNonTrivial();
>>>~ForceNonTrivial();
>>>ForceNonTrivial(const ForceNonTrivial&);
>>>
>>> Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=281395=281394=281395=diff
>>>
>>> ==
>>> --- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
>>> +++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Tue Sep 13 16:08:20 2016
>>> @@ -347,6 +347,13 @@ __declspec(dllimport) inline int *Refere
>>>  // MO1-DAG: define available_externally dllimport i32*
>>> @"\01?ReferencingImportedDelete@@YAPAHXZ"
>>>  USE(ReferencingImportedNew)
>>>  USE(ReferencingImportedDelete)
>>> +struct ClassWithDtor { ~ClassWithDtor() {} };
>>> +struct __declspec(dllimport) ClassWithNonDllImportField { ClassWithDtor
>>> t; };
>>> +struct __declspec(dllimport) ClassWithNonDllImportBase : public
>>> ClassWithDtor { };
>>> +USECLASS(ClassWithNonDllImportField);
>>> 

r281413 - Also don't inline dllimport functions referring to non-dllimport constructors.

2016-09-13 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Tue Sep 13 17:51:42 2016
New Revision: 281413

URL: http://llvm.org/viewvc/llvm-project?rev=281413=rev
Log:
Also don't inline dllimport functions referring to non-dllimport constructors.

The AST walker wasn't visiting CXXConstructExprs before.

This is a follow-up to r281395.

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenCXX/PR26569.cpp
cfe/trunk/test/CodeGenCXX/dllimport.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=281413=281412=281413=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Sep 13 17:51:42 2016
@@ -1693,6 +1693,8 @@ namespace {
   : public RecursiveASTVisitor {
 bool SafeToInline = true;
 
+bool shouldVisitImplicitCode() const { return true; }
+
 bool VisitVarDecl(VarDecl *VD) {
   // A thread-local variable cannot be imported.
   SafeToInline = !VD->getTLSKind();
@@ -1708,6 +1710,10 @@ namespace {
 SafeToInline = !V->hasGlobalStorage() || V->hasAttr();
   return SafeToInline;
 }
+bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+  SafeToInline = E->getConstructor()->hasAttr();
+  return SafeToInline;
+}
 bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
   SafeToInline = E->getOperatorDelete()->hasAttr();
   return SafeToInline;

Modified: cfe/trunk/test/CodeGenCXX/PR26569.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR26569.cpp?rev=281413=281412=281413=diff
==
--- cfe/trunk/test/CodeGenCXX/PR26569.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/PR26569.cpp Tue Sep 13 17:51:42 2016
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-llvm -O1 
-disable-llvm-optzns %s -o - | FileCheck %s
 
-class A {
+class __declspec(dllimport) A {
   virtual void m_fn1();
 };
 template 
@@ -11,10 +11,10 @@ class __declspec(dllexport) C : B {
 
 // CHECK-DAG: @[[VTABLE_C:.*]] = private unnamed_addr constant [2 x i8*] [i8* 
bitcast (%rtti.CompleteObjectLocator* @"\01??_R4C@@6B@" to i8*), i8* bitcast 
(void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)]
 // CHECK-DAG: @[[VTABLE_B:.*]] = private unnamed_addr constant [2 x i8*] [i8* 
bitcast (%rtti.CompleteObjectLocator* @"\01??_R4?$B@H@@6B@" to i8*), i8* 
bitcast (void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)], 
comdat($"\01??_S?$B@H@@6B@")
-// CHECK-DAG: @[[VTABLE_A:.*]] = private unnamed_addr constant [2 x i8*] [i8* 
bitcast (%rtti.CompleteObjectLocator* @"\01??_R4A@@6B@" to i8*), i8* bitcast 
(void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)], comdat($"\01??_7A@@6B@")
+// CHECK-DAG: @[[VTABLE_A:.*]] = private unnamed_addr constant [2 x i8*] [i8* 
bitcast (%rtti.CompleteObjectLocator* @"\01??_R4A@@6B@" to i8*), i8* bitcast 
(void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)], comdat($"\01??_SA@@6B@")
 
 // CHECK-DAG: @"\01??_7C@@6B@" = dllexport unnamed_addr alias i8*, 
getelementptr inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_C]], i32 0, i32 1)
 // CHECK-DAG: @"\01??_S?$B@H@@6B@" = unnamed_addr alias i8*, getelementptr 
inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_B]], i32 0, i32 1)
-// CHECK-DAG: @"\01??_7A@@6B@" = unnamed_addr alias i8*, getelementptr 
inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_A]], i32 0, i32 1)
+// CHECK-DAG: @"\01??_SA@@6B@" = unnamed_addr alias i8*, getelementptr 
inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_A]], i32 0, i32 1)
 
 // CHECK-DAG: @"\01??_8?$B@H@@7B@" = available_externally dllimport 
unnamed_addr constant [2 x i32] [i32 0, i32 4]

Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=281413=281412=281413=diff
==
--- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Tue Sep 13 17:51:42 2016
@@ -354,6 +354,10 @@ USECLASS(ClassWithNonDllImportField);
 USECLASS(ClassWithNonDllImportBase);
 // MO1-DAG: declare dllimport x86_thiscallcc void 
@"\01??1ClassWithNonDllImportBase@@QAE@XZ"(%struct.ClassWithNonDllImportBase*)
 // MO1-DAG: declare dllimport x86_thiscallcc void 
@"\01??1ClassWithNonDllImportField@@QAE@XZ"(%struct.ClassWithNonDllImportField*)
+struct ClassWithCtor { ClassWithCtor() {} };
+struct __declspec(dllimport) ClassWithNonDllImportFieldWithCtor { 
ClassWithCtor t; };
+USECLASS(ClassWithNonDllImportFieldWithCtor);
+// MO1-DAG: declare dllimport x86_thiscallcc 
%struct.ClassWithNonDllImportFieldWithCtor* 
@"\01??0ClassWithNonDllImportFieldWithCtor@@QAE@XZ"(%struct.ClassWithNonDllImportFieldWithCtor*
 returned)
 
 // A dllimport function with a TLS variable must not be available_externally.
 __declspec(dllimport) inline void FunctionWithTLSVar() { static 

r281412 - Warning flag updates:

2016-09-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Sep 13 17:51:09 2016
New Revision: 281412

URL: http://llvm.org/viewvc/llvm-project?rev=281412=rev
Log:
Warning flag updates:
-Wdiv-by-zero may as well be an alias for -Wdivision-by-zero rather than a 
GCC-compatibility no-op.
-Wno-shadow should disable -Wshadow-ivar.
-Weffc++ may as well enable -Wnon-virtual-dtor like it does in GCC.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=281412=281411=281412=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Sep 13 17:51:09 2016
@@ -114,7 +114,8 @@ def Deprecated : DiagGroup<"deprecated",
 def LibLTO : DiagGroup<"liblto">;
 def : DiagGroup<"disabled-optimization">;
 def : DiagGroup<"discard-qual">;
-def : DiagGroup<"div-by-zero">;
+def DivZero : DiagGroup<"division-by-zero">;
+def : DiagGroup<"div-by-zero", [DivZero]>;
 
 def DocumentationHTML : DiagGroup<"documentation-html">;
 def DocumentationUnknownCommand : DiagGroup<"documentation-unknown-command">;
@@ -201,8 +202,6 @@ def CXX14CompatPedantic : DiagGroup<"c++
 def CXX1zCompat : DiagGroup<"c++1z-compat", [DeprecatedRegister,
  DeprecatedIncrementBool]>;
 
-def : DiagGroup<"effc++">;
-def DivZero : DiagGroup<"division-by-zero">;
 def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
 def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;
 def FourByteMultiChar : DiagGroup<"four-char-constants">;
@@ -290,6 +289,7 @@ def NonPODVarargs : DiagGroup<"non-pod-v
 def ClassVarargs : DiagGroup<"class-varargs", [NonPODVarargs]>;
 def : DiagGroup<"nonportable-cfstrings">;
 def NonVirtualDtor : DiagGroup<"non-virtual-dtor">;
+def : DiagGroup<"effc++", [NonVirtualDtor]>;
 def OveralignedType : DiagGroup<"over-aligned">;
 def OldStyleCast : DiagGroup<"old-style-cast">;
 def : DiagGroup<"old-style-definition">;
@@ -348,10 +348,12 @@ def MissingMethodReturnType : DiagGroup<
 def ShadowFieldInConstructorModified : 
DiagGroup<"shadow-field-in-constructor-modified">;
 def ShadowFieldInConstructor : DiagGroup<"shadow-field-in-constructor",
  [ShadowFieldInConstructorModified]>;
+def ShadowIvar : DiagGroup<"shadow-ivar">;
 
 // -Wshadow-all is a catch-all for all shadowing. -Wshadow is just the
 // shadowing that we think is unsafe.
-def Shadow : DiagGroup<"shadow", [ShadowFieldInConstructorModified]>;
+def Shadow : DiagGroup<"shadow", [ShadowFieldInConstructorModified,
+  ShadowIvar]>;
 def ShadowAll : DiagGroup<"shadow-all", [Shadow, ShadowFieldInConstructor]>;
 
 def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
@@ -880,4 +882,4 @@ def UnknownArgument : DiagGroup<"unknown
 
 // A warning group for warnings about code that clang accepts when
 // compiling OpenCL C/C++ but which is not compatible with the SPIR spec.
-def SpirCompat : DiagGroup<"spir-compat">;
\ No newline at end of file
+def SpirCompat : DiagGroup<"spir-compat">;


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


[PATCH] D24526: [Release notes] Mention readability-container-size-empty improvements

2016-09-13 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko created this revision.
Eugene.Zelenko added reviewers: alexfh, omtcyfz.
Eugene.Zelenko added a subscriber: cfe-commits.
Eugene.Zelenko set the repository for this revision to rL LLVM.

Repository:
  rL LLVM

https://reviews.llvm.org/D24526

Files:
  docs/ReleaseNotes.rst

Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -89,6 +89,10 @@
   Warns about the performance overhead arising from concatenating strings using
   the ``operator+``, instead of ``operator+=``.
 
+- `readability-container-size-empty
+  
`_
 check
+  supports arbitrary containers with ``empty()`` and ``size()`` methods.
+
 - New `readability-misplaced-array-index
   
`_
 check
 


Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -89,6 +89,10 @@
   Warns about the performance overhead arising from concatenating strings using
   the ``operator+``, instead of ``operator+=``.
 
+- `readability-container-size-empty
+  `_ check
+  supports arbitrary containers with ``empty()`` and ``size()`` methods.
+
 - New `readability-misplaced-array-index
   `_ check
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r281408 - Fix a FIXME about MSVC 2013 in the diagnostic doc generation code

2016-09-13 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Sep 13 17:22:56 2016
New Revision: 281408

URL: http://llvm.org/viewvc/llvm-project?rev=281408=rev
Log:
Fix a FIXME about MSVC 2013 in the diagnostic doc generation code

Ultimately it boiled down to adding a move constructor.

Modified:
cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp

Modified: cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp?rev=281408=281407=281408=diff
==
--- cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp Tue Sep 13 17:22:56 
2016
@@ -928,13 +928,14 @@ struct DiagText {
 void print(std::vector ) override;
   };
   struct SelectPiece : Piece {
+SelectPiece() {}
+SelectPiece(SelectPiece &) LLVM_NOEXCEPT : Options(std::move(O.Options)) 
{
+}
 std::vector Options;
 void print(std::vector ) override;
   };
 
-  // FIXME: This should be a unique_ptr, but I can't figure out how to get MSVC
-  // to not issue errors on that.
-  std::vector Pieces;
+  std::vector Pieces;
 
   DiagText();
   DiagText(DiagText &) LLVM_NOEXCEPT : Pieces(std::move(O.Pieces)) {}
@@ -943,7 +944,7 @@ struct DiagText {
   DiagText(StringRef Kind, StringRef Text);
 
   template void add(P Piece) {
-Pieces.push_back(std::make_shared(std::move(Piece)));
+Pieces.push_back(llvm::make_unique(std::move(Piece)));
   }
   void print(std::vector );
 };
@@ -1040,7 +1041,8 @@ DiagText::DiagText(StringRef Kind, Strin
   Prefix.Role = Kind;
   Prefix.Text = Kind;
   Prefix.Text += ": ";
-  Pieces.insert(Pieces.begin(), 
std::make_shared(std::move(Prefix)));
+  Pieces.insert(Pieces.begin(),
+llvm::make_unique(std::move(Prefix)));
 }
 
 void escapeRST(StringRef Str, std::string ) {


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


Re: [PATCH] D24522: [CUDA] Do not merge CUDA target attributes.

2016-09-13 Thread Artem Belevich via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281406: [CUDA] Do not merge CUDA target attributes. 
(authored by tra).

Changed prior to commit:
  https://reviews.llvm.org/D24522?vs=71244=71249#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24522

Files:
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/SemaCUDA/function-overload.cu
  cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu

Index: cfe/trunk/test/SemaCUDA/function-overload.cu
===
--- cfe/trunk/test/SemaCUDA/function-overload.cu
+++ cfe/trunk/test/SemaCUDA/function-overload.cu
@@ -379,3 +379,14 @@
   HostReturnTy ret3 = host_only_function(1);
   HostReturnTy2 ret4 = host_only_function(1.0f);
 }
+
+// Verify that we allow overloading function templates.
+template  __host__ T template_overload(const T ) { return a; };
+template  __device__ T template_overload(const T ) { return a; };
+
+__host__ void test_host_template_overload() {
+  template_overload(1); // OK. Attribute-based overloading picks __host__ 
variant.
+}
+__device__ void test_device_template_overload() {
+  template_overload(1); // OK. Attribute-based overloading picks __device__ 
variant.
+}
Index: cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu
===
--- cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu
+++ cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu
@@ -0,0 +1,29 @@
+// Verifies correct inheritance of target attributes during template
+// instantiation and specialization.
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device 
-verify %s
+
+#include "Inputs/cuda.h"
+
+// Function must inherit target attributes during instantiation, but not during
+// specialization.
+template  __host__ __device__ T function_template(const T );
+
+// Specialized functions have their own attributes.
+// expected-note@+1 {{candidate function not viable: call to __host__ function 
from __device__ function}}
+template <> __host__ float function_template(const float );
+
+// expected-note@+1 {{candidate function not viable: call to __device__ 
function from __host__ function}}
+template <> __device__ double function_template(const double );
+
+__host__ void hf() {
+  function_template(1.0f); // OK. Specialization is __host__.
+  function_template(2.0); // expected-error {{no matching function for 
call to 'function_template'}}
+  function_template(1);   // OK. Instantiated function template is HD.
+}
+__device__ void df() {
+  function_template(3.0f); // expected-error {{no matching function for 
call to 'function_template'}}
+  function_template(4.0); // OK. Specialization is __device__.
+  function_template(1);   // OK. Instantiated function template is HD.
+}
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -2290,7 +2290,13 @@
 NewAttr = S.mergeAlwaysInlineAttr(D, AA->getRange(),
   (AA->getSpelling()),
   AttrSpellingListIndex);
-  else if (const auto *MA = dyn_cast(Attr))
+  else if (S.getLangOpts().CUDA && isa(D) &&
+   (isa(Attr) || isa(Attr) ||
+isa(Attr))) {
+// CUDA target attributes are part of function signature for
+// overloading purposes and must not be merged.
+return false;
+  } else if (const auto *MA = dyn_cast(Attr))
 NewAttr = S.mergeMinSizeAttr(D, MA->getRange(), AttrSpellingListIndex);
   else if (const auto *OA = dyn_cast(Attr))
 NewAttr = S.mergeOptimizeNoneAttr(D, OA->getRange(), 
AttrSpellingListIndex);


Index: cfe/trunk/test/SemaCUDA/function-overload.cu
===
--- cfe/trunk/test/SemaCUDA/function-overload.cu
+++ cfe/trunk/test/SemaCUDA/function-overload.cu
@@ -379,3 +379,14 @@
   HostReturnTy ret3 = host_only_function(1);
   HostReturnTy2 ret4 = host_only_function(1.0f);
 }
+
+// Verify that we allow overloading function templates.
+template  __host__ T template_overload(const T ) { return a; };
+template  __device__ T template_overload(const T ) { return a; };
+
+__host__ void test_host_template_overload() {
+  template_overload(1); // OK. Attribute-based overloading picks __host__ variant.
+}
+__device__ void test_device_template_overload() {
+  template_overload(1); // OK. Attribute-based overloading picks __device__ variant.
+}
Index: cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu
===
--- cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu
+++ cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu
@@ -0,0 +1,29 @@
+// Verifies correct inheritance of target attributes during template
+// 

r281406 - [CUDA] Do not merge CUDA target attributes.

2016-09-13 Thread Artem Belevich via cfe-commits
Author: tra
Date: Tue Sep 13 17:16:30 2016
New Revision: 281406

URL: http://llvm.org/viewvc/llvm-project?rev=281406=rev
Log:
[CUDA] Do not merge CUDA target attributes.

CUDA target attributes are used for function overloading and must not be merged.

This fixes a bug where attributes were inherited during function template
specialization in CUDA and made it impossible for specialized function
to provide its own target attributes.

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

Added:
cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCUDA/function-overload.cu

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=281406=281405=281406=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep 13 17:16:30 2016
@@ -2290,7 +2290,13 @@ static bool mergeDeclAttribute(Sema ,
 NewAttr = S.mergeAlwaysInlineAttr(D, AA->getRange(),
   (AA->getSpelling()),
   AttrSpellingListIndex);
-  else if (const auto *MA = dyn_cast(Attr))
+  else if (S.getLangOpts().CUDA && isa(D) &&
+   (isa(Attr) || isa(Attr) ||
+isa(Attr))) {
+// CUDA target attributes are part of function signature for
+// overloading purposes and must not be merged.
+return false;
+  } else if (const auto *MA = dyn_cast(Attr))
 NewAttr = S.mergeMinSizeAttr(D, MA->getRange(), AttrSpellingListIndex);
   else if (const auto *OA = dyn_cast(Attr))
 NewAttr = S.mergeOptimizeNoneAttr(D, OA->getRange(), 
AttrSpellingListIndex);

Modified: cfe/trunk/test/SemaCUDA/function-overload.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/function-overload.cu?rev=281406=281405=281406=diff
==
--- cfe/trunk/test/SemaCUDA/function-overload.cu (original)
+++ cfe/trunk/test/SemaCUDA/function-overload.cu Tue Sep 13 17:16:30 2016
@@ -379,3 +379,14 @@ __host__ __device__ void test_host_devic
   HostReturnTy ret3 = host_only_function(1);
   HostReturnTy2 ret4 = host_only_function(1.0f);
 }
+
+// Verify that we allow overloading function templates.
+template  __host__ T template_overload(const T ) { return a; };
+template  __device__ T template_overload(const T ) { return a; };
+
+__host__ void test_host_template_overload() {
+  template_overload(1); // OK. Attribute-based overloading picks __host__ 
variant.
+}
+__device__ void test_device_template_overload() {
+  template_overload(1); // OK. Attribute-based overloading picks __device__ 
variant.
+}

Added: cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu?rev=281406=auto
==
--- cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu (added)
+++ cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu Tue Sep 13 17:16:30 2016
@@ -0,0 +1,29 @@
+// Verifies correct inheritance of target attributes during template
+// instantiation and specialization.
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device 
-verify %s
+
+#include "Inputs/cuda.h"
+
+// Function must inherit target attributes during instantiation, but not during
+// specialization.
+template  __host__ __device__ T function_template(const T );
+
+// Specialized functions have their own attributes.
+// expected-note@+1 {{candidate function not viable: call to __host__ function 
from __device__ function}}
+template <> __host__ float function_template(const float );
+
+// expected-note@+1 {{candidate function not viable: call to __device__ 
function from __host__ function}}
+template <> __device__ double function_template(const double );
+
+__host__ void hf() {
+  function_template(1.0f); // OK. Specialization is __host__.
+  function_template(2.0); // expected-error {{no matching function for 
call to 'function_template'}}
+  function_template(1);   // OK. Instantiated function template is HD.
+}
+__device__ void df() {
+  function_template(3.0f); // expected-error {{no matching function for 
call to 'function_template'}}
+  function_template(4.0); // OK. Specialization is __device__.
+  function_template(1);   // OK. Instantiated function template is HD.
+}


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


r281405 - [CodeGen] Fix an assert in EmitNullConstant.

2016-09-13 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Sep 13 17:13:02 2016
New Revision: 281405

URL: http://llvm.org/viewvc/llvm-project?rev=281405=rev
Log:
[CodeGen] Fix an assert in EmitNullConstant.

r235815 changed CGRecordLowering::accumulateBases to ignore non-virtual
bases of size 0, which prevented adding those non-virtual bases to
CGRecordLayout's NonVirtualBases. This caused clang to assert when
CGRecordLayout::getNonVirtualBaseLLVMFieldNo was called in
EmitNullConstant. This commit fixes the bug by ignoring zero-sized
non-virtual bases in EmitNullConstant.

rdar://problem/28100139

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

Modified:
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/test/CodeGenCXX/empty-classes.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=281405=281404=281405=diff
==
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Tue Sep 13 17:13:02 2016
@@ -1532,7 +1532,8 @@ static llvm::Constant *EmitNullConstant(
   cast(I.getType()->castAs()->getDecl());
 
 // Ignore empty bases.
-if (base->isEmpty())
+if (base->isEmpty() ||
+CGM.getContext().getASTRecordLayout(base).getNonVirtualSize().isZero())
   continue;
 
 unsigned fieldIndex = layout.getNonVirtualBaseLLVMFieldNo(base);

Modified: cfe/trunk/test/CodeGenCXX/empty-classes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/empty-classes.cpp?rev=281405=281404=281405=diff
==
--- cfe/trunk/test/CodeGenCXX/empty-classes.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/empty-classes.cpp Tue Sep 13 17:13:02 2016
@@ -96,3 +96,24 @@ namespace rdar20621065 {
   // Type checked at the top of the file.
   B b;
 };
+
+// This test used to crash when CGRecordLayout::getNonVirtualBaseLLVMFieldNo 
was called.
+namespace record_layout {
+struct X0 {
+  int x[0];
+};
+
+template
+struct X2 : X0 {
+};
+
+template
+struct X3 : X2 {
+  X3() : X2() {}
+};
+
+
+void test0() {
+  X3();
+}
+}


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


Re: [PATCH] D24312: [CodeGen] Fix an assert in EmitNullConstant

2016-09-13 Thread Akira Hatanaka via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281405: [CodeGen] Fix an assert in EmitNullConstant. 
(authored by ahatanak).

Changed prior to commit:
  https://reviews.llvm.org/D24312?vs=70589=71248#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24312

Files:
  cfe/trunk/lib/CodeGen/CGExprConstant.cpp
  cfe/trunk/test/CodeGenCXX/empty-classes.cpp

Index: cfe/trunk/test/CodeGenCXX/empty-classes.cpp
===
--- cfe/trunk/test/CodeGenCXX/empty-classes.cpp
+++ cfe/trunk/test/CodeGenCXX/empty-classes.cpp
@@ -96,3 +96,24 @@
   // Type checked at the top of the file.
   B b;
 };
+
+// This test used to crash when CGRecordLayout::getNonVirtualBaseLLVMFieldNo 
was called.
+namespace record_layout {
+struct X0 {
+  int x[0];
+};
+
+template
+struct X2 : X0 {
+};
+
+template
+struct X3 : X2 {
+  X3() : X2() {}
+};
+
+
+void test0() {
+  X3();
+}
+}
Index: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
===
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp
@@ -1532,7 +1532,8 @@
   cast(I.getType()->castAs()->getDecl());
 
 // Ignore empty bases.
-if (base->isEmpty())
+if (base->isEmpty() ||
+CGM.getContext().getASTRecordLayout(base).getNonVirtualSize().isZero())
   continue;
 
 unsigned fieldIndex = layout.getNonVirtualBaseLLVMFieldNo(base);


Index: cfe/trunk/test/CodeGenCXX/empty-classes.cpp
===
--- cfe/trunk/test/CodeGenCXX/empty-classes.cpp
+++ cfe/trunk/test/CodeGenCXX/empty-classes.cpp
@@ -96,3 +96,24 @@
   // Type checked at the top of the file.
   B b;
 };
+
+// This test used to crash when CGRecordLayout::getNonVirtualBaseLLVMFieldNo was called.
+namespace record_layout {
+struct X0 {
+  int x[0];
+};
+
+template
+struct X2 : X0 {
+};
+
+template
+struct X3 : X2 {
+  X3() : X2() {}
+};
+
+
+void test0() {
+  X3();
+}
+}
Index: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
===
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp
@@ -1532,7 +1532,8 @@
   cast(I.getType()->castAs()->getDecl());
 
 // Ignore empty bases.
-if (base->isEmpty())
+if (base->isEmpty() ||
+CGM.getContext().getASTRecordLayout(base).getNonVirtualSize().isZero())
   continue;
 
 unsigned fieldIndex = layout.getNonVirtualBaseLLVMFieldNo(base);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r281401 - Temporary fix for MS _Interlocked intrinsics

2016-09-13 Thread Albert Gutowski via cfe-commits
Buildbot failure -
http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/323

On Tue, Sep 13, 2016 at 3:05 PM, David Majnemer 
wrote:

> What issue is this addressing?
>
> On Tue, Sep 13, 2016 at 2:51 PM, Albert Gutowski via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: agutowski
>> Date: Tue Sep 13 16:51:37 2016
>> New Revision: 281401
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=281401=rev
>> Log:
>> Temporary fix for MS _Interlocked intrinsics
>>
>> Modified:
>> cfe/trunk/include/clang/Basic/Builtins.def
>> cfe/trunk/lib/CodeGen/CGBuiltin.cpp
>> cfe/trunk/lib/Headers/intrin.h
>> cfe/trunk/test/CodeGen/ms-intrinsics.c
>>
>> Modified: cfe/trunk/include/clang/Basic/Builtins.def
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Basic/Builtins.def?rev=281401=281400=281401=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Basic/Builtins.def (original)
>> +++ cfe/trunk/include/clang/Basic/Builtins.def Tue Sep 13 16:51:37 2016
>> @@ -719,7 +719,6 @@ LANGBUILTIN(__GetExceptionInfo, "v*.", "
>>  LANGBUILTIN(_InterlockedAnd8,   "ccD*c","n", ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedAnd16,  "ssD*s","n", ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedAnd,"LiLiD*Li", "n", ALL_MS_LANGUAGES)
>> -LANGBUILTIN(_InterlockedAnd64,  "LLiLLiD*LLi",  "n", ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedCompareExchange8,   "ccD*cc", "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedCompareExchange16,  "ssD*ss", "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedCompareExchange,"LiLiD*LiLi", "n",
>> ALL_MS_LANGUAGES)
>> @@ -727,31 +726,24 @@ LANGBUILTIN(_InterlockedCompareExchange6
>>  LANGBUILTIN(_InterlockedCompareExchangePointer, "v*v*D*v*v*", "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedDecrement16,"ssD*", "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedDecrement,  "LiLiD*",   "n",
>> ALL_MS_LANGUAGES)
>> -LANGBUILTIN(_InterlockedDecrement64,"LLiLLiD*", "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedExchange,   "LiLiD*Li", "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedExchange8,  "ccD*c","n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedExchange16, "ssD*s","n",
>> ALL_MS_LANGUAGES)
>> -LANGBUILTIN(_InterlockedExchange64, "LLiLLiD*LLi",  "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedExchangeAdd8,   "ccD*c",  "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedExchangeAdd16,  "ssD*s",  "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedExchangeAdd,"LiLiD*Li",   "n",
>> ALL_MS_LANGUAGES)
>> -LANGBUILTIN(_InterlockedExchangeAdd64,  "LLiLLiD*LLi","n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedExchangePointer,"v*v*D*v*",   "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedExchangeSub8,   "ccD*c","n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedExchangeSub16,  "ssD*s","n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedExchangeSub,"LiLiD*Li", "n",
>> ALL_MS_LANGUAGES)
>> -LANGBUILTIN(_InterlockedExchangeSub64,  "LLiLLiD*LLi",  "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedIncrement16,"ssD*", "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedIncrement,  "LiLiD*",   "n",
>> ALL_MS_LANGUAGES)
>> -LANGBUILTIN(_InterlockedIncrement64,"LLiLLiD*", "n",
>> ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedOr8,  "ccD*c","n", ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedOr16, "ssD*s","n", ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedOr,   "LiLiD*Li", "n", ALL_MS_LANGUAGES)
>> -LANGBUILTIN(_InterlockedOr64, "LLiLLiD*LLi",  "n", ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedXor8,  "ccD*c",   "n", ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedXor16, "ssD*s",   "n", ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_InterlockedXor,   "LiLiD*Li","n", ALL_MS_LANGUAGES)
>> -LANGBUILTIN(_InterlockedXor64, "LLiLLiD*LLi", "n", ALL_MS_LANGUAGES)
>>  LANGBUILTIN(__noop,   "i.",  "n", ALL_MS_LANGUAGES)
>>  LANGBUILTIN(__readfsdword,"ULiULi", "n", ALL_MS_LANGUAGES)
>>  LANGBUILTIN(_rotl8,  "UcUcUc","n", ALL_MS_LANGUAGES)
>>
>> Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CG
>> Builtin.cpp?rev=281401=281400=281401=diff
>> 
>> ==
>> --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Sep 13 16:51:37 2016
>> @@ -1963,7 +1963,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(
>>case Builtin::BI_InterlockedExchange8:
>>case Builtin::BI_InterlockedExchange16:
>>case Builtin::BI_InterlockedExchange:
>> -  case Builtin::BI_InterlockedExchange64:
>>case 

Re: [PATCH] D24522: [CUDA] Do not merge CUDA target attributes.

2016-09-13 Thread Artem Belevich via cfe-commits
tra updated this revision to Diff 71244.
tra marked an inline comment as done.
tra added a comment.

Removed REQUIRED lines.


https://reviews.llvm.org/D24522

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaCUDA/function-overload.cu
  test/SemaCUDA/target_attr_inheritance.cu

Index: test/SemaCUDA/target_attr_inheritance.cu
===
--- /dev/null
+++ test/SemaCUDA/target_attr_inheritance.cu
@@ -0,0 +1,29 @@
+// Verifies correct inheritance of target attributes during template
+// instantiation and specialization.
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device 
-verify %s
+
+#include "Inputs/cuda.h"
+
+// Function must inherit target attributes during instantiation, but not during
+// specialization.
+template  __host__ __device__ T function_template(const T );
+
+// Specialized functions have their own attributes.
+// expected-note@+1 {{candidate function not viable: call to __host__ function 
from __device__ function}}
+template <> __host__ float function_template(const float );
+
+// expected-note@+1 {{candidate function not viable: call to __device__ 
function from __host__ function}}
+template <> __device__ double function_template(const double );
+
+__host__ void hf() {
+  function_template(1.0f); // OK. Specialization is __host__.
+  function_template(2.0); // expected-error {{no matching function for 
call to 'function_template'}}
+  function_template(1);   // OK. Instantiated function template is HD.
+}
+__device__ void df() {
+  function_template(3.0f); // expected-error {{no matching function for 
call to 'function_template'}}
+  function_template(4.0); // OK. Specialization is __device__.
+  function_template(1);   // OK. Instantiated function template is HD.
+}
Index: test/SemaCUDA/function-overload.cu
===
--- test/SemaCUDA/function-overload.cu
+++ test/SemaCUDA/function-overload.cu
@@ -379,3 +379,14 @@
   HostReturnTy ret3 = host_only_function(1);
   HostReturnTy2 ret4 = host_only_function(1.0f);
 }
+
+// Verify that we allow overloading function templates.
+template  __host__ T template_overload(const T ) { return a; };
+template  __device__ T template_overload(const T ) { return a; };
+
+__host__ void test_host_template_overload() {
+  template_overload(1); // OK. Attribute-based overloading picks __host__ 
variant.
+}
+__device__ void test_device_template_overload() {
+  template_overload(1); // OK. Attribute-based overloading picks __device__ 
variant.
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2292,7 +2292,13 @@
 NewAttr = S.mergeAlwaysInlineAttr(D, AA->getRange(),
   (AA->getSpelling()),
   AttrSpellingListIndex);
-  else if (const auto *MA = dyn_cast(Attr))
+  else if (S.getLangOpts().CUDA && isa(D) &&
+   (isa(Attr) || isa(Attr) ||
+isa(Attr))) {
+// CUDA target attributes are part of function signature for
+// overloading purposes and must not be merged.
+return false;
+  } else if (const auto *MA = dyn_cast(Attr))
 NewAttr = S.mergeMinSizeAttr(D, MA->getRange(), AttrSpellingListIndex);
   else if (const auto *OA = dyn_cast(Attr))
 NewAttr = S.mergeOptimizeNoneAttr(D, OA->getRange(), 
AttrSpellingListIndex);


Index: test/SemaCUDA/target_attr_inheritance.cu
===
--- /dev/null
+++ test/SemaCUDA/target_attr_inheritance.cu
@@ -0,0 +1,29 @@
+// Verifies correct inheritance of target attributes during template
+// instantiation and specialization.
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device -verify %s
+
+#include "Inputs/cuda.h"
+
+// Function must inherit target attributes during instantiation, but not during
+// specialization.
+template  __host__ __device__ T function_template(const T );
+
+// Specialized functions have their own attributes.
+// expected-note@+1 {{candidate function not viable: call to __host__ function from __device__ function}}
+template <> __host__ float function_template(const float );
+
+// expected-note@+1 {{candidate function not viable: call to __device__ function from __host__ function}}
+template <> __device__ double function_template(const double );
+
+__host__ void hf() {
+  function_template(1.0f); // OK. Specialization is __host__.
+  function_template(2.0); // expected-error {{no matching function for call to 'function_template'}}
+  function_template(1);   // OK. Instantiated function template is HD.
+}
+__device__ void df() {
+  function_template(3.0f); // expected-error {{no matching function for call to 

Re: r281351 - Add a class ObjCProtocolQualifiers to wrap APIs for ObjC protocol list.

2016-09-13 Thread Manman via cfe-commits
I checked in r281404. Hopefully it will fix the issue.

Let me know if it does not.

Thanks,
Manman

> On Sep 13, 2016, at 3:03 PM, Artem Belevich via cfe-commits 
>  wrote:
> 
> Manman,
> 
> FYI, It appears that some of your ObjC commits today trigger asan error.
> Sanitizer bots are broken by PR30341, so they don't report the issue yet.
> 
> --Artem
> 
> $ llvm/tools/clang/clang -cc1 -internal-isystem 
> llvm/tools/clang/staging/include -nostdsysteminc -fblocks -fsyntax-only 
> -Wnullable-to-nonnull-conversion 
> llvm/tools/clang/test/SemaObjC/parameterized_classes_subst.m -verify
> =
> ==223101==ERROR: AddressSanitizer: use-after-poison on address 0x62191288 
> at pc 0x01a02b3f bp 0x7f2996f0 sp 0x7f2996e8
> WRITE of size 4 at 0x62191288 thread T0
> #0 0x1a02b3e in 
> clang::ObjCTypeParamTypeLoc::setProtocolRAngleLoc(clang::SourceLocation) 
> third_party/llvm/llvm/tools/clang/include/clang/AST/TypeLoc.h:737:55
> #1 0x213f86b in 
> clang::Sema::actOnObjCTypeArgsAndProtocolQualifiers(clang::Scope*, 
> clang::SourceLocation, clang::OpaquePtr, 
> clang::SourceLocation, llvm::ArrayRef, 
> clang::SourceLocation, clang::SourceLocation, llvm::ArrayRef, 
> llvm::ArrayRef, clang::SourceLocation) 
> third_party/llvm/llvm/tools/clang/lib/Sema/SemaType.cpp:1165:13
> #2 0x2060347 in 
> clang::Parser::parseObjCTypeArgsAndProtocolQualifiers(clang::SourceLocation, 
> clang::OpaquePtr, bool, clang::SourceLocation&) 
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:1878:18
> #3 0x1ffca6f in 
> clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool, bool, 
> clang::CXXScopeSpec&, bool) 
> third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:1770:13
> #4 0x1ffd4fc in clang::Parser::TryAnnotateTypeOrScopeToken(bool, bool) 
> third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:1733:10
> #5 0x20df910 in clang::Parser::isTypeSpecifierQualifier() 
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseDecl.cpp:4381:9
> #6 0x205ecf5 in clang::Parser::ParseObjCTypeName(clang::ObjCDeclSpec&, 
> clang::Declarator::TheContext, clang::ParsedAttributes*) 
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:1274:7
> #7 0x205c8f9 in clang::Parser::ParseObjCMethodDecl(clang::SourceLocation, 
> clang::tok::TokenKind, clang::tok::ObjCKeywordKind, bool) 
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:1428:22
> #8 0x2058e8b in 
> clang::Parser::ParseObjCInterfaceDeclList(clang::tok::ObjCKeywordKind, 
> clang::Decl*) third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:633:11
> #9 0x2053154 in 
> clang::Parser::ParseObjCAtInterfaceDeclaration(clang::SourceLocation, 
> clang::ParsedAttributes&) 
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:388:3
> #10 0x2051fa9 in clang::Parser::ParseObjCAtDirectives() 
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:63:18
> #11 0x1ff7871 in 
> clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
>  clang::ParsingDeclSpec*) 
> third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:757:12
> #12 0x1ff6c61 in 
> clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&) 
> third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:628:12
> #13 0x1ff016d in clang::ParseAST(clang::Sema&, bool, bool) 
> third_party/llvm/llvm/tools/clang/lib/Parse/ParseAST.cpp:147:18
> #14 0x1ab05d3 in clang::FrontendAction::Execute() 
> third_party/llvm/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:458:8
> #15 0x184fbd6 in 
> clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) 
> third_party/llvm/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:871:11
> #16 0x5c6f47 in 
> clang::ExecuteCompilerInvocation(clang::CompilerInstance*) 
> third_party/llvm/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:249:25
> #17 0x5a114d in cc1_main(llvm::ArrayRef, char const*, void*) 
> third_party/llvm/llvm/tools/clang/tools/driver/cc1_main.cpp:183:13
> #18 0x5bb3f6 in ExecuteCC1Tool(llvm::ArrayRef, 
> llvm::StringRef) 
> third_party/llvm/llvm/tools/clang/tools/driver/driver.cpp:299:12
> #19 0x5ba314 in main 
> third_party/llvm/llvm/tools/clang/tools/driver/driver.cpp:380:12
> 
> 0x62191288 is located 392 bytes inside of 4096-byte region 
> [0x62191100,0x62192100)
> allocated by thread T0 here:
> #0 0x58a52c in __interceptor_malloc 
> third_party/llvm/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:64:3
> #1 0x5a5d0b in llvm::MallocAllocator::Allocate(unsigned long, unsigned 
> long) third_party/llvm/llvm/include/llvm/Support/Allocator.h:95:12
> #2 0x691b67 in llvm::BumpPtrAllocatorImpl 4096ul>::StartNewSlab() 
> third_party/llvm/llvm/include/llvm/Support/Allocator.h:324:31
> #3 0x6916aa in llvm::BumpPtrAllocatorImpl

Re: [PATCH] D24372: [libcxx] Sprinkle constexpr over compressed_pair

2016-09-13 Thread Keno Fischer via cfe-commits
loladiro added inline comments.


Comment at: include/memory:2137
@@ -2132,3 +2136,3 @@
 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)

mclow.lists wrote:
> loladiro wrote:
> > mclow.lists wrote:
> > > Have you tested this on C++11?
> > > I suspect that some of these need to be `_LIBCPP_CONSTEXPR_AFTER_CXX11`
> > Well, as I mentioned there are other problems on C++11, namely forward not 
> > being constexpr (so even the simple constructors below can't be constant 
> > initialized in C++11). I would REALLY like for unique_ptr to be constant 
> > initialized even in C++11 mode. I feel like arguably the standard requires 
> > it by marking the constructor `constexpr`.
> One way to deal with that is to define a call `__forward()` that is the same 
> as `forward()` except that it's constexpr in C++11, and have compressed_pair 
> call that.
> 
I was worried that something in the definition of forward required C++14 
constexpr semantics? Is that not the case. If so this sounds like a good 
solution, and I can update the patch accordingly.


Repository:
  rL LLVM

https://reviews.llvm.org/D24372



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


Re: r281401 - Temporary fix for MS _Interlocked intrinsics

2016-09-13 Thread David Majnemer via cfe-commits
What issue is this addressing?

On Tue, Sep 13, 2016 at 2:51 PM, Albert Gutowski via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: agutowski
> Date: Tue Sep 13 16:51:37 2016
> New Revision: 281401
>
> URL: http://llvm.org/viewvc/llvm-project?rev=281401=rev
> Log:
> Temporary fix for MS _Interlocked intrinsics
>
> Modified:
> cfe/trunk/include/clang/Basic/Builtins.def
> cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> cfe/trunk/lib/Headers/intrin.h
> cfe/trunk/test/CodeGen/ms-intrinsics.c
>
> Modified: cfe/trunk/include/clang/Basic/Builtins.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/Builtins.def?rev=281401=281400=281401=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/Builtins.def (original)
> +++ cfe/trunk/include/clang/Basic/Builtins.def Tue Sep 13 16:51:37 2016
> @@ -719,7 +719,6 @@ LANGBUILTIN(__GetExceptionInfo, "v*.", "
>  LANGBUILTIN(_InterlockedAnd8,   "ccD*c","n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedAnd16,  "ssD*s","n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedAnd,"LiLiD*Li", "n", ALL_MS_LANGUAGES)
> -LANGBUILTIN(_InterlockedAnd64,  "LLiLLiD*LLi",  "n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedCompareExchange8,   "ccD*cc", "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedCompareExchange16,  "ssD*ss", "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedCompareExchange,"LiLiD*LiLi", "n",
> ALL_MS_LANGUAGES)
> @@ -727,31 +726,24 @@ LANGBUILTIN(_InterlockedCompareExchange6
>  LANGBUILTIN(_InterlockedCompareExchangePointer, "v*v*D*v*v*", "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedDecrement16,"ssD*", "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedDecrement,  "LiLiD*",   "n",
> ALL_MS_LANGUAGES)
> -LANGBUILTIN(_InterlockedDecrement64,"LLiLLiD*", "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedExchange,   "LiLiD*Li", "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedExchange8,  "ccD*c","n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedExchange16, "ssD*s","n",
> ALL_MS_LANGUAGES)
> -LANGBUILTIN(_InterlockedExchange64, "LLiLLiD*LLi",  "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedExchangeAdd8,   "ccD*c",  "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedExchangeAdd16,  "ssD*s",  "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedExchangeAdd,"LiLiD*Li",   "n",
> ALL_MS_LANGUAGES)
> -LANGBUILTIN(_InterlockedExchangeAdd64,  "LLiLLiD*LLi","n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedExchangePointer,"v*v*D*v*",   "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedExchangeSub8,   "ccD*c","n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedExchangeSub16,  "ssD*s","n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedExchangeSub,"LiLiD*Li", "n",
> ALL_MS_LANGUAGES)
> -LANGBUILTIN(_InterlockedExchangeSub64,  "LLiLLiD*LLi",  "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedIncrement16,"ssD*", "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedIncrement,  "LiLiD*",   "n",
> ALL_MS_LANGUAGES)
> -LANGBUILTIN(_InterlockedIncrement64,"LLiLLiD*", "n",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedOr8,  "ccD*c","n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedOr16, "ssD*s","n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedOr,   "LiLiD*Li", "n", ALL_MS_LANGUAGES)
> -LANGBUILTIN(_InterlockedOr64, "LLiLLiD*LLi",  "n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedXor8,  "ccD*c",   "n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedXor16, "ssD*s",   "n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(_InterlockedXor,   "LiLiD*Li","n", ALL_MS_LANGUAGES)
> -LANGBUILTIN(_InterlockedXor64, "LLiLLiD*LLi", "n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(__noop,   "i.",  "n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(__readfsdword,"ULiULi", "n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(_rotl8,  "UcUcUc","n", ALL_MS_LANGUAGES)
>
> Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/
> CGBuiltin.cpp?rev=281401=281400=281401=diff
> 
> ==
> --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Sep 13 16:51:37 2016
> @@ -1963,7 +1963,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(
>case Builtin::BI_InterlockedExchange8:
>case Builtin::BI_InterlockedExchange16:
>case Builtin::BI_InterlockedExchange:
> -  case Builtin::BI_InterlockedExchange64:
>case Builtin::BI_InterlockedExchangePointer:
>  return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E);
>case Builtin::BI_InterlockedCompareExchangePointer: {
> @@ -2007,8 +2006,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(
>return 

r281404 - ObjectiveC Generics: follow-up commit to r281355.

2016-09-13 Thread Manman Ren via cfe-commits
Author: mren
Date: Tue Sep 13 16:57:28 2016
New Revision: 281404

URL: http://llvm.org/viewvc/llvm-project?rev=281404=rev
Log:
ObjectiveC Generics: follow-up commit to r281355.

Correct getExtraLocalDataSize for ObjCTypeParamTypeLoc.

rdar://24619481
rdar://25060179

Modified:
cfe/trunk/include/clang/AST/TypeLoc.h

Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=281404=281403=281404=diff
==
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Tue Sep 13 16:57:28 2016
@@ -763,7 +763,9 @@ public:
 
   unsigned getExtraLocalDataSize() const {
 if (!this->getNumProtocols()) return 0;
-return this->getNumProtocols() * sizeof(SourceLocation) ;
+// When there are protocol qualifers, we have LAngleLoc and RAngleLoc
+// as well.
+return (this->getNumProtocols() + 2) * sizeof(SourceLocation) ;
   }
   unsigned getExtraLocalDataAlignment() const {
 return llvm::alignOf();


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


Re: [PATCH] D24372: [libcxx] Sprinkle constexpr over compressed_pair

2016-09-13 Thread Marshall Clow via cfe-commits
mclow.lists added inline comments.


Comment at: include/memory:2137
@@ -2132,3 +2136,3 @@
 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)

loladiro wrote:
> mclow.lists wrote:
> > Have you tested this on C++11?
> > I suspect that some of these need to be `_LIBCPP_CONSTEXPR_AFTER_CXX11`
> Well, as I mentioned there are other problems on C++11, namely forward not 
> being constexpr (so even the simple constructors below can't be constant 
> initialized in C++11). I would REALLY like for unique_ptr to be constant 
> initialized even in C++11 mode. I feel like arguably the standard requires it 
> by marking the constructor `constexpr`.
One way to deal with that is to define a call `__forward()` that is the same as 
`forward()` except that it's constexpr in C++11, and have compressed_pair call 
that.



Repository:
  rL LLVM

https://reviews.llvm.org/D24372



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


Re: r281351 - Add a class ObjCProtocolQualifiers to wrap APIs for ObjC protocol list.

2016-09-13 Thread Artem Belevich via cfe-commits
Manman,

FYI, It appears that some of your ObjC commits today trigger asan error.
Sanitizer bots are broken by PR30341, so they don't report the issue yet.

--Artem

$ llvm/tools/clang/clang -cc1 -internal-isystem
llvm/tools/clang/staging/include -nostdsysteminc -fblocks -fsyntax-only
-Wnullable-to-nonnull-conversion
llvm/tools/clang/test/SemaObjC/parameterized_classes_subst.m -verify
=
==223101==ERROR: AddressSanitizer: use-after-poison on address
0x62191288 at pc 0x01a02b3f bp 0x7f2996f0 sp 0x7f2996e8
WRITE of size 4 at 0x62191288 thread T0
#0 0x1a02b3e in
clang::ObjCTypeParamTypeLoc::setProtocolRAngleLoc(clang::SourceLocation)
third_party/llvm/llvm/tools/clang/include/clang/AST/TypeLoc.h:737:55
#1 0x213f86b in
clang::Sema::actOnObjCTypeArgsAndProtocolQualifiers(clang::Scope*,
clang::SourceLocation, clang::OpaquePtr,
clang::SourceLocation, llvm::ArrayRef,
clang::SourceLocation, clang::SourceLocation, llvm::ArrayRef,
llvm::ArrayRef, clang::SourceLocation)
third_party/llvm/llvm/tools/clang/lib/Sema/SemaType.cpp:1165:13
#2 0x2060347 in
clang::Parser::parseObjCTypeArgsAndProtocolQualifiers(clang::SourceLocation,
clang::OpaquePtr, bool, clang::SourceLocation&)
third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:1878:18
#3 0x1ffca6f in
clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool, bool,
clang::CXXScopeSpec&, bool)
third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:1770:13
#4 0x1ffd4fc in clang::Parser::TryAnnotateTypeOrScopeToken(bool, bool)
third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:1733:10
#5 0x20df910 in clang::Parser::isTypeSpecifierQualifier()
third_party/llvm/llvm/tools/clang/lib/Parse/ParseDecl.cpp:4381:9
#6 0x205ecf5 in clang::Parser::ParseObjCTypeName(clang::ObjCDeclSpec&,
clang::Declarator::TheContext, clang::ParsedAttributes*)
third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:1274:7
#7 0x205c8f9 in
clang::Parser::ParseObjCMethodDecl(clang::SourceLocation,
clang::tok::TokenKind, clang::tok::ObjCKeywordKind, bool)
third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:1428:22
#8 0x2058e8b in
clang::Parser::ParseObjCInterfaceDeclList(clang::tok::ObjCKeywordKind,
clang::Decl*)
third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:633:11
#9 0x2053154 in
clang::Parser::ParseObjCAtInterfaceDeclaration(clang::SourceLocation,
clang::ParsedAttributes&)
third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:388:3
#10 0x2051fa9 in clang::Parser::ParseObjCAtDirectives()
third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:63:18
#11 0x1ff7871 in
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*)
third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:757:12
#12 0x1ff6c61 in
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&)
third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:628:12
#13 0x1ff016d in clang::ParseAST(clang::Sema&, bool, bool)
third_party/llvm/llvm/tools/clang/lib/Parse/ParseAST.cpp:147:18
#14 0x1ab05d3 in clang::FrontendAction::Execute()
third_party/llvm/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:458:8
#15 0x184fbd6 in
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
third_party/llvm/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:871:11
#16 0x5c6f47 in
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
third_party/llvm/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:249:25
#17 0x5a114d in cc1_main(llvm::ArrayRef, char const*,
void*) third_party/llvm/llvm/tools/clang/tools/driver/cc1_main.cpp:183:13
#18 0x5bb3f6 in ExecuteCC1Tool(llvm::ArrayRef,
llvm::StringRef)
third_party/llvm/llvm/tools/clang/tools/driver/driver.cpp:299:12
#19 0x5ba314 in main
third_party/llvm/llvm/tools/clang/tools/driver/driver.cpp:380:12

0x62191288 is located 392 bytes inside of 4096-byte region
[0x62191100,0x62192100)
allocated by thread T0 here:
#0 0x58a52c in __interceptor_malloc
third_party/llvm/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:64:3
#1 0x5a5d0b in llvm::MallocAllocator::Allocate(unsigned long, unsigned
long) third_party/llvm/llvm/include/llvm/Support/Allocator.h:95:12
#2 0x691b67 in llvm::BumpPtrAllocatorImpl::StartNewSlab()
third_party/llvm/llvm/include/llvm/Support/Allocator.h:324:31
#3 0x6916aa in llvm::BumpPtrAllocatorImpl::Allocate(unsigned long, unsigned long)
third_party/llvm/llvm/include/llvm/Support/Allocator.h:249:5
#4 0x6913d1 in clang::ASTContext::Allocate(unsigned long, unsigned int)
const
third_party/llvm/llvm/tools/clang/include/clang/AST/ASTContext.h:588:22
#5 0x3010c16 in clang::ObjCInterfaceDecl::Create(clang::ASTContext
const&, clang::DeclContext*, clang::SourceLocation, clang::IdentifierInfo*,

r281401 - Temporary fix for MS _Interlocked intrinsics

2016-09-13 Thread Albert Gutowski via cfe-commits
Author: agutowski
Date: Tue Sep 13 16:51:37 2016
New Revision: 281401

URL: http://llvm.org/viewvc/llvm-project?rev=281401=rev
Log:
Temporary fix for MS _Interlocked intrinsics

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/intrin.h
cfe/trunk/test/CodeGen/ms-intrinsics.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=281401=281400=281401=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Tue Sep 13 16:51:37 2016
@@ -719,7 +719,6 @@ LANGBUILTIN(__GetExceptionInfo, "v*.", "
 LANGBUILTIN(_InterlockedAnd8,   "ccD*c","n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedAnd16,  "ssD*s","n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedAnd,"LiLiD*Li", "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedAnd64,  "LLiLLiD*LLi",  "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedCompareExchange8,   "ccD*cc", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedCompareExchange16,  "ssD*ss", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedCompareExchange,"LiLiD*LiLi", "n", 
ALL_MS_LANGUAGES)
@@ -727,31 +726,24 @@ LANGBUILTIN(_InterlockedCompareExchange6
 LANGBUILTIN(_InterlockedCompareExchangePointer, "v*v*D*v*v*", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedDecrement16,"ssD*", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedDecrement,  "LiLiD*",   "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedDecrement64,"LLiLLiD*", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchange,   "LiLiD*Li", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchange8,  "ccD*c","n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchange16, "ssD*s","n", 
ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedExchange64, "LLiLLiD*LLi",  "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangeAdd8,   "ccD*c",  "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangeAdd16,  "ssD*s",  "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangeAdd,"LiLiD*Li",   "n", 
ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedExchangeAdd64,  "LLiLLiD*LLi","n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangePointer,"v*v*D*v*",   "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangeSub8,   "ccD*c","n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangeSub16,  "ssD*s","n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangeSub,"LiLiD*Li", "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedExchangeSub64,  "LLiLLiD*LLi",  "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedIncrement16,"ssD*", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedIncrement,  "LiLiD*",   "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedIncrement64,"LLiLLiD*", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedOr8,  "ccD*c","n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedOr16, "ssD*s","n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedOr,   "LiLiD*Li", "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedOr64, "LLiLLiD*LLi",  "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedXor8,  "ccD*c",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedXor16, "ssD*s",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedXor,   "LiLiD*Li","n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedXor64, "LLiLLiD*LLi", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__noop,   "i.",  "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__readfsdword,"ULiULi", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_rotl8,  "UcUcUc","n", ALL_MS_LANGUAGES)

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=281401=281400=281401=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Sep 13 16:51:37 2016
@@ -1963,7 +1963,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   case Builtin::BI_InterlockedExchange8:
   case Builtin::BI_InterlockedExchange16:
   case Builtin::BI_InterlockedExchange:
-  case Builtin::BI_InterlockedExchange64:
   case Builtin::BI_InterlockedExchangePointer:
 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E);
   case Builtin::BI_InterlockedCompareExchangePointer: {
@@ -2007,8 +2006,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   return RValue::get(Builder.CreateExtractValue(CXI, 0));
   }
   case Builtin::BI_InterlockedIncrement16:
-  case Builtin::BI_InterlockedIncrement:
-  case Builtin::BI_InterlockedIncrement64: {
+  case Builtin::BI_InterlockedIncrement: {
 llvm::Type *IntTy = ConvertType(E->getType());
 AtomicRMWInst *RMWI = Builder.CreateAtomicRMW(
   AtomicRMWInst::Add,

Re: r281395 - Try harder to not inline dllimport functions referencing non-dllimport functions

2016-09-13 Thread Hans Wennborg via cfe-commits
Good point. Constructors are also a problem, I'll try to fix.

It's not exactly the same issue, because they do show up in the AST,
but they're referenced with a CXXConstructExpr, and not the
DeclRefExpr which DLLImportFunctionVisitor is looking for.

There doesn't seem to be any problem with operator= though.

On Tue, Sep 13, 2016 at 2:36 PM, Nico Weber via cfe-commits
 wrote:
> Could other implicit functions (operator=, ctors) have similar issues?
>
> On Tue, Sep 13, 2016 at 5:08 PM, Hans Wennborg via cfe-commits
>  wrote:
>>
>> Author: hans
>> Date: Tue Sep 13 16:08:20 2016
>> New Revision: 281395
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=281395=rev
>> Log:
>> Try harder to not inline dllimport functions referencing non-dllimport
>> functions
>>
>> In r246338, code was added to check for this, but it failed to take into
>> account implicit destructor invocations because those are not reflected
>> in the AST. This adds a separate check for them.
>>
>> Modified:
>> cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>> cfe/trunk/test/CodeGenCXX/dllimport-members.cpp
>> cfe/trunk/test/CodeGenCXX/dllimport.cpp
>>
>> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=281395=281394=281395=diff
>>
>> ==
>> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Sep 13 16:08:20 2016
>> @@ -1740,8 +1740,17 @@ CodeGenModule::isTriviallyRecursive(cons
>>return Walker.Result;
>>  }
>>
>> -bool
>> -CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
>> +// Check if T is a class type with a destructor that's not dllimport.
>> +static bool HasNonDllImportDtor(QualType T) {
>> +  if (const RecordType *RT = dyn_cast(T))
>> +if (CXXRecordDecl *RD = dyn_cast(RT->getDecl()))
>> +  if (RD->getDestructor() &&
>> !RD->getDestructor()->hasAttr())
>> +return true;
>> +
>> +  return false;
>> +}
>> +
>> +bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
>>if (getFunctionLinkage(GD) !=
>> llvm::Function::AvailableExternallyLinkage)
>>  return true;
>>const auto *F = cast(GD.getDecl());
>> @@ -1754,6 +1763,18 @@ CodeGenModule::shouldEmitFunction(Global
>>  Visitor.TraverseFunctionDecl(const_cast(F));
>>  if (!Visitor.SafeToInline)
>>return false;
>> +
>> +if (const CXXDestructorDecl *Dtor = dyn_cast(F)) {
>> +  // Implicit destructor invocations aren't captured in the AST, so
>> the
>> +  // check above can't see them. Check for them manually here.
>> +  for (const Decl *Member : Dtor->getParent()->decls())
>> +if (isa(Member))
>> +  if (HasNonDllImportDtor(cast(Member)->getType()))
>> +return false;
>> +  for (const CXXBaseSpecifier  : Dtor->getParent()->bases())
>> +if (HasNonDllImportDtor(B.getType()))
>> +  return false;
>> +}
>>}
>>
>>// PR9614. Avoid cases where the source code is lying to us. An
>> available
>>
>> Modified: cfe/trunk/test/CodeGenCXX/dllimport-members.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-members.cpp?rev=281395=281394=281395=diff
>>
>> ==
>> --- cfe/trunk/test/CodeGenCXX/dllimport-members.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/dllimport-members.cpp Tue Sep 13 16:08:20
>> 2016
>> @@ -44,7 +44,7 @@ void useSpecials() {
>>  }
>>
>>  // Used to force non-trivial special members.
>> -struct ForceNonTrivial {
>> +struct __declspec(dllimport) ForceNonTrivial {
>>ForceNonTrivial();
>>~ForceNonTrivial();
>>ForceNonTrivial(const ForceNonTrivial&);
>>
>> Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=281395=281394=281395=diff
>>
>> ==
>> --- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Tue Sep 13 16:08:20 2016
>> @@ -347,6 +347,13 @@ __declspec(dllimport) inline int *Refere
>>  // MO1-DAG: define available_externally dllimport i32*
>> @"\01?ReferencingImportedDelete@@YAPAHXZ"
>>  USE(ReferencingImportedNew)
>>  USE(ReferencingImportedDelete)
>> +struct ClassWithDtor { ~ClassWithDtor() {} };
>> +struct __declspec(dllimport) ClassWithNonDllImportField { ClassWithDtor
>> t; };
>> +struct __declspec(dllimport) ClassWithNonDllImportBase : public
>> ClassWithDtor { };
>> +USECLASS(ClassWithNonDllImportField);
>> +USECLASS(ClassWithNonDllImportBase);
>> +// MO1-DAG: declare dllimport x86_thiscallcc void
>> @"\01??1ClassWithNonDllImportBase@@QAE@XZ"(%struct.ClassWithNonDllImportBase*)
>> +// MO1-DAG: declare dllimport x86_thiscallcc void
>> 

Re: [PATCH] D24522: [CUDA] Do not merge CUDA target attributes.

2016-09-13 Thread Justin Lebar via cfe-commits
jlebar accepted this revision.
jlebar added a comment.
This revision is now accepted and ready to land.

Yay, this is great.



Comment at: test/SemaCUDA/target_attr_inheritance.cu:4
@@ +3,3 @@
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+

Other reviewers have pointed out to me that we don't usually (ever?) need this. 
 I think these have to do with llvm's ability to generate code for our targets, 
but it's not relevant to clang here.


https://reviews.llvm.org/D24522



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


[PATCH] D24522: [CUDA] Do not merge CUDA target attributes.

2016-09-13 Thread Artem Belevich via cfe-commits
tra created this revision.
tra added a reviewer: jlebar.
tra added a subscriber: cfe-commits.
Herald added a subscriber: jlebar.

CUDA target attributes are used for function overloading and must not be merged.

This fixes a bug where attributes were inherited during function template 
specialization in CUDA and made it impossible for specialized function 
to provide its own target attributes.


https://reviews.llvm.org/D24522

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaCUDA/function-overload.cu
  test/SemaCUDA/target_attr_inheritance.cu

Index: test/SemaCUDA/target_attr_inheritance.cu
===
--- /dev/null
+++ test/SemaCUDA/target_attr_inheritance.cu
@@ -0,0 +1,31 @@
+// Verifies correct inheritance of target attributes during template
+// instantiation and specialization.
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device 
-verify %s
+
+#include "Inputs/cuda.h"
+
+// Function must inherit target attributes during instantiation, but not during
+// specialization.
+template  __host__ __device__ T function_template(const T );
+
+// Specialized functions have their own attributes.
+// expected-note@+1 {{candidate function not viable: call to __host__ function 
from __device__ function}}
+template <> __host__ float function_template(const float );
+
+// expected-note@+1 {{candidate function not viable: call to __device__ 
function from __host__ function}}
+template <> __device__ double function_template(const double );
+
+__host__ void hf() {
+  function_template(1.0f); // OK. Specialization is __host__.
+  function_template(2.0); // expected-error {{no matching function for 
call to 'function_template'}}
+  function_template(1);   // OK. Instantiated function template is HD.
+}
+__device__ void df() {
+  function_template(3.0f); // expected-error {{no matching function for 
call to 'function_template'}}
+  function_template(4.0); // OK. Specialization is __device__.
+  function_template(1);   // OK. Instantiated function template is HD.
+}
Index: test/SemaCUDA/function-overload.cu
===
--- test/SemaCUDA/function-overload.cu
+++ test/SemaCUDA/function-overload.cu
@@ -379,3 +379,14 @@
   HostReturnTy ret3 = host_only_function(1);
   HostReturnTy2 ret4 = host_only_function(1.0f);
 }
+
+// Verify that we allow overloading function templates.
+template  __host__ T template_overload(const T ) { return a; };
+template  __device__ T template_overload(const T ) { return a; };
+
+__host__ void test_host_template_overload() {
+  template_overload(1); // OK. Attribute-based overloading picks __host__ 
variant.
+}
+__device__ void test_device_template_overload() {
+  template_overload(1); // OK. Attribute-based overloading picks __device__ 
variant.
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2292,7 +2292,13 @@
 NewAttr = S.mergeAlwaysInlineAttr(D, AA->getRange(),
   (AA->getSpelling()),
   AttrSpellingListIndex);
-  else if (const auto *MA = dyn_cast(Attr))
+  else if (S.getLangOpts().CUDA && isa(D) &&
+   (isa(Attr) || isa(Attr) ||
+isa(Attr))) {
+// CUDA target attributes are part of function signature for
+// overloading purposes and must not be merged.
+return false;
+  } else if (const auto *MA = dyn_cast(Attr))
 NewAttr = S.mergeMinSizeAttr(D, MA->getRange(), AttrSpellingListIndex);
   else if (const auto *OA = dyn_cast(Attr))
 NewAttr = S.mergeOptimizeNoneAttr(D, OA->getRange(), 
AttrSpellingListIndex);


Index: test/SemaCUDA/target_attr_inheritance.cu
===
--- /dev/null
+++ test/SemaCUDA/target_attr_inheritance.cu
@@ -0,0 +1,31 @@
+// Verifies correct inheritance of target attributes during template
+// instantiation and specialization.
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device -verify %s
+
+#include "Inputs/cuda.h"
+
+// Function must inherit target attributes during instantiation, but not during
+// specialization.
+template  __host__ __device__ T function_template(const T );
+
+// Specialized functions have their own attributes.
+// expected-note@+1 {{candidate function not viable: call to __host__ function from __device__ function}}
+template <> __host__ float function_template(const float );
+
+// expected-note@+1 {{candidate function not viable: call to __device__ function from __host__ function}}
+template <> 

Re: r281395 - Try harder to not inline dllimport functions referencing non-dllimport functions

2016-09-13 Thread Nico Weber via cfe-commits
Could other implicit functions (operator=, ctors) have similar issues?

On Tue, Sep 13, 2016 at 5:08 PM, Hans Wennborg via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: hans
> Date: Tue Sep 13 16:08:20 2016
> New Revision: 281395
>
> URL: http://llvm.org/viewvc/llvm-project?rev=281395=rev
> Log:
> Try harder to not inline dllimport functions referencing non-dllimport
> functions
>
> In r246338, code was added to check for this, but it failed to take into
> account implicit destructor invocations because those are not reflected
> in the AST. This adds a separate check for them.
>
> Modified:
> cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> cfe/trunk/test/CodeGenCXX/dllimport-members.cpp
> cfe/trunk/test/CodeGenCXX/dllimport.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/
> CodeGenModule.cpp?rev=281395=281394=281395=diff
> 
> ==
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Sep 13 16:08:20 2016
> @@ -1740,8 +1740,17 @@ CodeGenModule::isTriviallyRecursive(cons
>return Walker.Result;
>  }
>
> -bool
> -CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
> +// Check if T is a class type with a destructor that's not dllimport.
> +static bool HasNonDllImportDtor(QualType T) {
> +  if (const RecordType *RT = dyn_cast(T))
> +if (CXXRecordDecl *RD = dyn_cast(RT->getDecl()))
> +  if (RD->getDestructor() && !RD->getDestructor()->hasAttr<
> DLLImportAttr>())
> +return true;
> +
> +  return false;
> +}
> +
> +bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
>if (getFunctionLinkage(GD) != llvm::Function::
> AvailableExternallyLinkage)
>  return true;
>const auto *F = cast(GD.getDecl());
> @@ -1754,6 +1763,18 @@ CodeGenModule::shouldEmitFunction(Global
>  Visitor.TraverseFunctionDecl(const_cast(F));
>  if (!Visitor.SafeToInline)
>return false;
> +
> +if (const CXXDestructorDecl *Dtor = dyn_cast(F)) {
> +  // Implicit destructor invocations aren't captured in the AST, so
> the
> +  // check above can't see them. Check for them manually here.
> +  for (const Decl *Member : Dtor->getParent()->decls())
> +if (isa(Member))
> +  if (HasNonDllImportDtor(cast(Member)->getType()))
> +return false;
> +  for (const CXXBaseSpecifier  : Dtor->getParent()->bases())
> +if (HasNonDllImportDtor(B.getType()))
> +  return false;
> +}
>}
>
>// PR9614. Avoid cases where the source code is lying to us. An
> available
>
> Modified: cfe/trunk/test/CodeGenCXX/dllimport-members.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> CodeGenCXX/dllimport-members.cpp?rev=281395=281394=281395=diff
> 
> ==
> --- cfe/trunk/test/CodeGenCXX/dllimport-members.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/dllimport-members.cpp Tue Sep 13 16:08:20
> 2016
> @@ -44,7 +44,7 @@ void useSpecials() {
>  }
>
>  // Used to force non-trivial special members.
> -struct ForceNonTrivial {
> +struct __declspec(dllimport) ForceNonTrivial {
>ForceNonTrivial();
>~ForceNonTrivial();
>ForceNonTrivial(const ForceNonTrivial&);
>
> Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> CodeGenCXX/dllimport.cpp?rev=281395=281394=281395=diff
> 
> ==
> --- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Tue Sep 13 16:08:20 2016
> @@ -347,6 +347,13 @@ __declspec(dllimport) inline int *Refere
>  // MO1-DAG: define available_externally dllimport i32* @"\01?
> ReferencingImportedDelete@@YAPAHXZ"
>  USE(ReferencingImportedNew)
>  USE(ReferencingImportedDelete)
> +struct ClassWithDtor { ~ClassWithDtor() {} };
> +struct __declspec(dllimport) ClassWithNonDllImportField { ClassWithDtor
> t; };
> +struct __declspec(dllimport) ClassWithNonDllImportBase : public
> ClassWithDtor { };
> +USECLASS(ClassWithNonDllImportField);
> +USECLASS(ClassWithNonDllImportBase);
> +// MO1-DAG: declare dllimport x86_thiscallcc void @"\01??
> 1ClassWithNonDllImportBase@@QAE@XZ"(%struct.ClassWithNonDllImportBase*)
> +// MO1-DAG: declare dllimport x86_thiscallcc void @"\01??
> 1ClassWithNonDllImportField@@QAE@XZ"(%struct.ClassWithNonDllImportField*)
>
>  // A dllimport function with a TLS variable must not be
> available_externally.
>  __declspec(dllimport) inline void FunctionWithTLSVar() { static __thread
> int x = 42; }
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list

r281399 - Reverse commit 281375 (breaks building Chromium)

2016-09-13 Thread Albert Gutowski via cfe-commits
Author: agutowski
Date: Tue Sep 13 16:24:51 2016
New Revision: 281399

URL: http://llvm.org/viewvc/llvm-project?rev=281399=rev
Log:
Reverse commit 281375 (breaks building Chromium)

Removed:
cfe/trunk/test/Sema/implicit-intel-builtin-decl.c
cfe/trunk/test/Sema/implicit-ms-builtin-decl.c
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/include/clang/Basic/Builtins.h
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/emmintrin.h
cfe/trunk/lib/Headers/ia32intrin.h
cfe/trunk/lib/Headers/intrin.h
cfe/trunk/lib/Headers/xmmintrin.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGen/builtins-x86.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=281399=281398=281399=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Tue Sep 13 16:24:51 2016
@@ -74,7 +74,6 @@
 //  f -> this is a libc/libm function without the '__builtin_' prefix. It can
 //   be followed by ':headername:' to state which header this function
 //   comes from.
-//  h -> this function requires a specific header or an explicit declaration.
 //  i -> this is a runtime library implemented function without the
 //   '__builtin_' prefix. It will be implemented in compiler-rt or libgcc.
 //  p:N: -> this is a printf-like function whose Nth argument is the format
@@ -709,9 +708,6 @@ BUILTIN(__builtin_rindex, "c*cC*i", "Fn"
 // Microsoft builtins.  These are only active with -fms-extensions.
 LANGBUILTIN(_alloca,  "v*z", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__assume, "vb",  "n", ALL_MS_LANGUAGES)
-LIBBUILTIN(_byteswap_ushort, "UsUs", "fnc", "stdlib.h", ALL_MS_LANGUAGES)
-LIBBUILTIN(_byteswap_ulong,  "ULiULi",   "fnc", "stdlib.h", ALL_MS_LANGUAGES)
-LIBBUILTIN(_byteswap_uint64, "ULLiULLi", "fnc", "stdlib.h", ALL_MS_LANGUAGES)
 LANGBUILTIN(__debugbreak, "v",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__exception_code, "ULi", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_exception_code,  "ULi", "n", ALL_MS_LANGUAGES)
@@ -757,9 +753,6 @@ LANGBUILTIN(_InterlockedXor16, "ssD*s",
 LANGBUILTIN(_InterlockedXor,   "LiLiD*Li","n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedXor64, "LLiLLiD*LLi", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__noop,   "i.",  "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(__popcnt16, "UsUs", "nc", ALL_MS_LANGUAGES)
-LANGBUILTIN(__popcnt,   "UiUi", "nc", ALL_MS_LANGUAGES)
-LANGBUILTIN(__popcnt64, "ULLiULLi", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__readfsdword,"ULiULi", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_rotl8,  "UcUcUc","n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_rotl16, "UsUsUc","n", ALL_MS_LANGUAGES)

Modified: cfe/trunk/include/clang/Basic/Builtins.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.h?rev=281399=281398=281399=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.h (original)
+++ cfe/trunk/include/clang/Basic/Builtins.h Tue Sep 13 16:24:51 2016
@@ -139,13 +139,6 @@ public:
 return strchr(getRecord(ID).Attributes, 'f') != nullptr;
   }
 
-  // \brief Returns true if this builtin requires appropriate header in other
-  // compilers. In Clang it will work even without including it, but we can 
emit
-  // a warning about missing header.
-  bool isHeaderDependentFunction(unsigned ID) const {
-return strchr(getRecord(ID).Attributes, 'h') != nullptr;
-  }
-
   /// \brief Determines whether this builtin is a predefined compiler-rt/libgcc
   /// function, such as "__clear_cache", where we know the signature a
   /// priori.

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=281399=281398=281399=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Tue Sep 13 16:24:51 2016
@@ -23,10 +23,6 @@
 #   define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS)
 #endif
 
-#if defined(BUILTIN) && !defined(TARGET_HEADER_BUILTIN)
-#  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) 
BUILTIN(ID, TYPE, ATTRS)
-#endif
-
 // FIXME: Are these nothrow/const?
 
 // Miscellaneous builtin for checking x86 cpu features.
@@ -305,9 +301,7 @@ TARGET_BUILTIN(__builtin_ia32_pabsw128,
 TARGET_BUILTIN(__builtin_ia32_pabsd128, "V4iV4i", "", "ssse3")
 
 TARGET_BUILTIN(__builtin_ia32_ldmxcsr, "vUi", "", "sse")
-TARGET_HEADER_BUILTIN(_mm_setcsr, "vUi", "h","xmmintrin.h", ALL_LANGUAGES, 
"sse")
 TARGET_BUILTIN(__builtin_ia32_stmxcsr, "Ui", "", "sse")

Re: r281375 - Add some MS aliases for existing intrinsics

2016-09-13 Thread Nico Weber via cfe-commits
This breaks building Chromium,
https://build.chromium.org/p/chromium.fyi/builders/ClangToTWin64%28dbg%29/builds/7125/steps/compile/logs/stdio

FAILED: obj/components/webcrypto/webcrypto/aes_gcm.obj
../../third_party/llvm-build/Release+Asserts/bin/clang-cl.exe /nologo
/showIncludes /FC @obj/components/webcrypto/webcrypto/aes_gcm.obj.rsp /c
../../components/webcrypto/algorithms/aes_gcm.cc
/Foobj/components/webcrypto/webcrypto/aes_gcm.obj
/Fd"obj/components/webcrypto/webcrypto_cc.pdb"
In file included from ../../components/webcrypto/algorithms/aes_gcm.cc:5:
In file included from
../../third_party/boringssl/src/include\openssl/evp.h:60:
In file included from
../../third_party/boringssl/src/include\openssl/base.h:313:
In file included from
C:\b\depot_tools\win_toolchain\vs_files\d5dc33b15d1b2c086f2f6632e2fd15882f80dbd3\win_sdk\bin\..\..\VC\include\memory:6:
In file included from
C:\b\depot_tools\win_toolchain\vs_files\d5dc33b15d1b2c086f2f6632e2fd15882f80dbd3\win_sdk\bin\..\..\VC\include\xmemory:6:
In file included from
C:\b\depot_tools\win_toolchain\vs_files\d5dc33b15d1b2c086f2f6632e2fd15882f80dbd3\win_sdk\bin\..\..\VC\include\xmemory0:1151:
In file included from
C:\b\c\b\ClangToTWin64_dbg_\src\third_party\llvm-build\Release+Asserts\bin\..\lib\clang\4.0.0\include\intrin.h:34:
In file included from
C:\b\c\b\ClangToTWin64_dbg_\src\third_party\llvm-build\Release+Asserts\bin\..\lib\clang\4.0.0\include\x86intrin.h:29:
In file included from
C:\b\c\b\ClangToTWin64_dbg_\src\third_party\llvm-build\Release+Asserts\bin\..\lib\clang\4.0.0\include\immintrin.h:32:
C:\b\c\b\ClangToTWin64_dbg_\src\third_party\llvm-build\Release+Asserts\lib\clang\4.0.0\include\xmmintrin.h(2097,6):
 error: declaration of '_mm_sfence' has a different language linkage
void _mm_sfence(void);
 ^
C:\b\c\b\ClangToTWin64_dbg_\src\third_party\llvm-build\Release+Asserts\lib\clang\4.0.0\include\xmmintrin.h(2097,6):
 note: previous implicit declaration is here
C:\b\c\b\ClangToTWin64_dbg_\src\third_party\llvm-build\Release+Asserts\lib\clang\4.0.0\include\xmmintrin.h(2407,14):
 error: declaration of '_mm_getcsr' has a different language linkage
unsigned int _mm_getcsr(void);
 ^

It looks like just including memory like in
https://cs.chromium.org/chromium/src/third_party/boringssl/src/include/openssl/base.h?type=cs=third_party/boringssl/src/include/openssl/base.h=package:chromium=313
is enough to repro, so this looks like it probably breaks all users of
clang-cl. Please revert.

On Tue, Sep 13, 2016 at 3:26 PM, Albert Gutowski via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: agutowski
> Date: Tue Sep 13 14:26:42 2016
> New Revision: 281375
>
> URL: http://llvm.org/viewvc/llvm-project?rev=281375=rev
> Log:
> Add some MS aliases for existing intrinsics
>
> Reviewers: thakis, compnerd, majnemer, rsmith, rnk
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D24330
>
> Added:
> cfe/trunk/test/Sema/implicit-intel-builtin-decl.c
> cfe/trunk/test/Sema/implicit-ms-builtin-decl.c
> Modified:
> cfe/trunk/include/clang/Basic/Builtins.def
> cfe/trunk/include/clang/Basic/Builtins.h
> cfe/trunk/include/clang/Basic/BuiltinsX86.def
> cfe/trunk/lib/Basic/Targets.cpp
> cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> cfe/trunk/lib/Headers/emmintrin.h
> cfe/trunk/lib/Headers/ia32intrin.h
> cfe/trunk/lib/Headers/intrin.h
> cfe/trunk/lib/Headers/xmmintrin.h
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/CodeGen/builtins-x86.c
>
> Modified: cfe/trunk/include/clang/Basic/Builtins.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/Builtins.def?rev=281375=281374=281375=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/Builtins.def (original)
> +++ cfe/trunk/include/clang/Basic/Builtins.def Tue Sep 13 14:26:42 2016
> @@ -74,6 +74,7 @@
>  //  f -> this is a libc/libm function without the '__builtin_' prefix. It
> can
>  //   be followed by ':headername:' to state which header this function
>  //   comes from.
> +//  h -> this function requires a specific header or an explicit
> declaration.
>  //  i -> this is a runtime library implemented function without the
>  //   '__builtin_' prefix. It will be implemented in compiler-rt or
> libgcc.
>  //  p:N: -> this is a printf-like function whose Nth argument is the
> format
> @@ -708,6 +709,9 @@ BUILTIN(__builtin_rindex, "c*cC*i", "Fn"
>  // Microsoft builtins.  These are only active with -fms-extensions.
>  LANGBUILTIN(_alloca,  "v*z", "n", ALL_MS_LANGUAGES)
>  LANGBUILTIN(__assume, "vb",  "n", ALL_MS_LANGUAGES)
> +LIBBUILTIN(_byteswap_ushort, "UsUs", "fnc", "stdlib.h",
> ALL_MS_LANGUAGES)
> +LIBBUILTIN(_byteswap_ulong,  "ULiULi",   "fnc", "stdlib.h",
> ALL_MS_LANGUAGES)
> +LIBBUILTIN(_byteswap_uint64, "ULLiULLi", "fnc", "stdlib.h",
> ALL_MS_LANGUAGES)
>  LANGBUILTIN(__debugbreak, "v",   "n", 

r281395 - Try harder to not inline dllimport functions referencing non-dllimport functions

2016-09-13 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Tue Sep 13 16:08:20 2016
New Revision: 281395

URL: http://llvm.org/viewvc/llvm-project?rev=281395=rev
Log:
Try harder to not inline dllimport functions referencing non-dllimport functions

In r246338, code was added to check for this, but it failed to take into
account implicit destructor invocations because those are not reflected
in the AST. This adds a separate check for them.

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenCXX/dllimport-members.cpp
cfe/trunk/test/CodeGenCXX/dllimport.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=281395=281394=281395=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Sep 13 16:08:20 2016
@@ -1740,8 +1740,17 @@ CodeGenModule::isTriviallyRecursive(cons
   return Walker.Result;
 }
 
-bool
-CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
+// Check if T is a class type with a destructor that's not dllimport.
+static bool HasNonDllImportDtor(QualType T) {
+  if (const RecordType *RT = dyn_cast(T))
+if (CXXRecordDecl *RD = dyn_cast(RT->getDecl()))
+  if (RD->getDestructor() && 
!RD->getDestructor()->hasAttr())
+return true;
+
+  return false;
+}
+
+bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
   if (getFunctionLinkage(GD) != llvm::Function::AvailableExternallyLinkage)
 return true;
   const auto *F = cast(GD.getDecl());
@@ -1754,6 +1763,18 @@ CodeGenModule::shouldEmitFunction(Global
 Visitor.TraverseFunctionDecl(const_cast(F));
 if (!Visitor.SafeToInline)
   return false;
+
+if (const CXXDestructorDecl *Dtor = dyn_cast(F)) {
+  // Implicit destructor invocations aren't captured in the AST, so the
+  // check above can't see them. Check for them manually here.
+  for (const Decl *Member : Dtor->getParent()->decls())
+if (isa(Member))
+  if (HasNonDllImportDtor(cast(Member)->getType()))
+return false;
+  for (const CXXBaseSpecifier  : Dtor->getParent()->bases())
+if (HasNonDllImportDtor(B.getType()))
+  return false;
+}
   }
 
   // PR9614. Avoid cases where the source code is lying to us. An available

Modified: cfe/trunk/test/CodeGenCXX/dllimport-members.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-members.cpp?rev=281395=281394=281395=diff
==
--- cfe/trunk/test/CodeGenCXX/dllimport-members.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport-members.cpp Tue Sep 13 16:08:20 2016
@@ -44,7 +44,7 @@ void useSpecials() {
 }
 
 // Used to force non-trivial special members.
-struct ForceNonTrivial {
+struct __declspec(dllimport) ForceNonTrivial {
   ForceNonTrivial();
   ~ForceNonTrivial();
   ForceNonTrivial(const ForceNonTrivial&);

Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=281395=281394=281395=diff
==
--- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Tue Sep 13 16:08:20 2016
@@ -347,6 +347,13 @@ __declspec(dllimport) inline int *Refere
 // MO1-DAG: define available_externally dllimport i32* 
@"\01?ReferencingImportedDelete@@YAPAHXZ"
 USE(ReferencingImportedNew)
 USE(ReferencingImportedDelete)
+struct ClassWithDtor { ~ClassWithDtor() {} };
+struct __declspec(dllimport) ClassWithNonDllImportField { ClassWithDtor t; };
+struct __declspec(dllimport) ClassWithNonDllImportBase : public ClassWithDtor 
{ };
+USECLASS(ClassWithNonDllImportField);
+USECLASS(ClassWithNonDllImportBase);
+// MO1-DAG: declare dllimport x86_thiscallcc void 
@"\01??1ClassWithNonDllImportBase@@QAE@XZ"(%struct.ClassWithNonDllImportBase*)
+// MO1-DAG: declare dllimport x86_thiscallcc void 
@"\01??1ClassWithNonDllImportField@@QAE@XZ"(%struct.ClassWithNonDllImportField*)
 
 // A dllimport function with a TLS variable must not be available_externally.
 __declspec(dllimport) inline void FunctionWithTLSVar() { static __thread int x 
= 42; }


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


Re: [PATCH] D24508: PR28752: Do not instantiate var decls which are not visible.

2016-09-13 Thread Richard Smith via cfe-commits
rsmith added a comment.

I expect this patch to cause problems if the two definitions of the variable 
template come from different modules, because at deserialization time we don't 
merge the definitions together sensibly (it looks like we end up with a 
redeclaration chain with multiple declarations, multiple of which believe they 
are "the" defintiion).



Comment at: lib/Sema/SemaTemplate.cpp:470
@@ -470,1 +469,3 @@
+  assert(isa(Instantiation) || isa(Instantiation)
+ || isa(Instantiation));
 

`||` on the previous line, please.


Comment at: lib/Sema/SemaTemplate.cpp:472
@@ -470,3 +471,3 @@
 
-  if (PatternDef && (isa(PatternDef)
- || !cast(PatternDef)->isBeingDefined())) {
+  bool isEntityBeingDefined = false;
+  if (const TagDecl *TD = dyn_cast_or_null(PatternDef))

Variable names should start with a capital letter.


Comment at: lib/Sema/SemaTemplate.cpp:478
@@ -473,3 +477,3 @@
 NamedDecl *SuggestedDef = nullptr;
 if (!hasVisibleDefinition(const_cast(PatternDef), 
,
   /*OnlyNeedComplete*/false)) {

We'll need to extend `hasVisibleDefinition` to handle merged `VarDecl`s to 
support this. (The `ASTReader` doesn't currently merge together `VarDecl` 
definitions in a reasonable way.)


Comment at: lib/Sema/SemaTemplate.cpp:509
@@ -504,3 +508,3 @@
 << 1 << Instantiation->getDeclName() << 
Instantiation->getDeclContext();
-} else {
+} else if (isa(Instantiation)) {
   Diag(PointOfInstantiation,

`else if` doesn't make sense here -- we either need to produce a diagnostic on 
all paths through here, or suppress the notes if we didn't produce a diagnostic.


Comment at: lib/Sema/SemaTemplate.cpp:529
@@ +528,3 @@
+  Note = diag::note_template_decl_here;
+} else if (isa(Instantiation)) {
+  if (isa(Instantiation)) {

Likewise here.


Repository:
  rL LLVM

https://reviews.llvm.org/D24508



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


Re: r281277 - [Sema] Fix PR30346: relax __builtin_object_size checks.

2016-09-13 Thread Joerg Sonnenberger via cfe-commits
On Tue, Sep 13, 2016 at 12:51:52PM -0700, Richard Smith wrote:
> On Tue, Sep 13, 2016 at 10:44 AM, Joerg Sonnenberger via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> 
> > IMO this should be restricted to code that explicitly disables C/C++
> > aliasing rules.
> 
> 
> Do you mean -fno-strict-aliasing or -fno-struct-path-tbaa or something else
> here? (I think we're not doing anyone any favours by making _FORTIFY_SOURCE
> say that a pattern is OK in cases when LLVM will in fact optimize on the
> assumption that it's UB, but I don't recall how aggressive
> -fstruct-path-tbaa is for trailing array members.)

The former immediately, the latter potentially as well. I can't think of
many use cases for this kind of idiom that don't involve type prunning
and socket code is notoriously bad in that regard by necessity.

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


Re: [PATCH] D16533: Bug 20796 - GCC's -Wstrict-prototypes warning not implemented in Clang

2016-09-13 Thread Bruno Cardoso Lopes via cfe-commits
bruno added a subscriber: bruno.
bruno added a comment.

Hi Paul,

I'm interested in this patch. Do you have any plans to wrap it up?


https://reviews.llvm.org/D16533



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


Re: r281277 - [Sema] Fix PR30346: relax __builtin_object_size checks.

2016-09-13 Thread George Burgess IV via cfe-commits
Yeah, this patch didn't give me the warm fuzzies, either.

AFAICT, our only other options are having some sort of struct whitelist
(either hard-coded, or given as a flag), or telling people to turn
_FORTIFY_SOURCE down if they have code that looks like this. Given that
this is apparently common in the world of BSD, I'm unsure how many projects
this would impact if we chose "turn _FORTIFY_SOURCE down." So, this
solution seemed like the least bad of the above.

If people feel differently or have other ideas, I'm happy to add
restrictions/try a different approach. :)

On Tue, Sep 13, 2016 at 12:51 PM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Tue, Sep 13, 2016 at 10:44 AM, Joerg Sonnenberger via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> On Mon, Sep 12, 2016 at 11:50:36PM -, George Burgess IV via
>> cfe-commits wrote:
>> > Author: gbiv
>> > Date: Mon Sep 12 18:50:35 2016
>> > New Revision: 281277
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=281277=rev
>> > Log:
>> > [Sema] Fix PR30346: relax __builtin_object_size checks.
>> >
>> > This patch makes us act more conservatively when trying to determine
>> > the objectsize for an array at the end of an object. This is in
>> > response to code like the following:
>> >
>> > ```
>> > struct sockaddr {
>> >   /* snip */
>> >   char sa_data[14];
>> > };
>> >
>> > void foo(const char *s) {
>> >   size_t slen = strlen(s) + 1;
>> >   size_t added_len = slen <= 14 ? 0 : slen - 14;
>> >   struct sockaddr *sa = malloc(sizeof(struct sockaddr) + added_len);
>> >   strcpy(sa->sa_data, s);
>> >   // ...
>> > }
>> > ```
>> >
>> > `__builtin_object_size(sa->sa_data, 1)` would return 14, when there
>> > could be more than 14 bytes at `sa->sa_data`.
>> >
>> > Code like this is apparently not uncommon. FreeBSD's manual even
>> > explicitly mentions this pattern:
>> > https://www.freebsd.org/doc/en/books/developers-handbook/soc
>> kets-essential-functions.html
>> > (section 7.5.1.1.2).
>> >
>> > In light of this, we now just give up on any array at the end of an
>> > object if we can't find the object's initial allocation.
>> >
>> > I lack numbers for how much more conservative we actually become as a
>> > result of this change, so I chose the fix that would make us as
>> > compatible with GCC as possible. If we want to be more aggressive, I'm
>> > happy to consider some kind of whitelist or something instead.
>>
>> IMO this should be restricted to code that explicitly disables C/C++
>> aliasing rules.
>
>
> Do you mean -fno-strict-aliasing or -fno-struct-path-tbaa or something
> else here? (I think we're not doing anyone any favours by making
> _FORTIFY_SOURCE say that a pattern is OK in cases when LLVM will in fact
> optimize on the assumption that it's UB, but I don't recall how aggressive
> -fstruct-path-tbaa is for trailing array members.)
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23902: Minor cleanup of PTHWriter

2016-09-13 Thread Alexander Shaposhnikov via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281385: Remove excessive padding from PTHWriter (authored by 
alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D23902?vs=69311=71229#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23902

Files:
  cfe/trunk/lib/Frontend/CacheTokens.cpp

Index: cfe/trunk/lib/Frontend/CacheTokens.cpp
===
--- cfe/trunk/lib/Frontend/CacheTokens.cpp
+++ cfe/trunk/lib/Frontend/CacheTokens.cpp
@@ -182,14 +182,14 @@
   typedef llvm::DenseMap IDMap;
   typedef llvm::StringMap CachedStrsTy;
 
-  IDMap IM;
   raw_pwrite_stream 
   Preprocessor& PP;
-  uint32_t idcount;
+  IDMap IM;
+  std::vector StrEntries;
   PTHMap PM;
   CachedStrsTy CachedStrs;
+  uint32_t idcount;
   Offset CurStrOffset;
-  std::vector StrEntries;
 
    Get the persistent id for the given IdentifierInfo*.
   uint32_t ResolveID(const IdentifierInfo* II);


Index: cfe/trunk/lib/Frontend/CacheTokens.cpp
===
--- cfe/trunk/lib/Frontend/CacheTokens.cpp
+++ cfe/trunk/lib/Frontend/CacheTokens.cpp
@@ -182,14 +182,14 @@
   typedef llvm::DenseMap IDMap;
   typedef llvm::StringMap CachedStrsTy;
 
-  IDMap IM;
   raw_pwrite_stream 
   Preprocessor& PP;
-  uint32_t idcount;
+  IDMap IM;
+  std::vector StrEntries;
   PTHMap PM;
   CachedStrsTy CachedStrs;
+  uint32_t idcount;
   Offset CurStrOffset;
-  std::vector StrEntries;
 
    Get the persistent id for the given IdentifierInfo*.
   uint32_t ResolveID(const IdentifierInfo* II);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r281385 - Remove excessive padding from PTHWriter

2016-09-13 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Tue Sep 13 15:17:57 2016
New Revision: 281385

URL: http://llvm.org/viewvc/llvm-project?rev=281385=rev
Log:
Remove excessive padding from PTHWriter

The class PTHWriter is in lib/Frontend/CacheTokens.cpp 
inside the anonymous namespace.
This diff changes the order of fields an removes excessive padding.
Test plan: make -j8 check-clang

Differential revision: https://reviews.llvm.org/D23902

Modified:
cfe/trunk/lib/Frontend/CacheTokens.cpp

Modified: cfe/trunk/lib/Frontend/CacheTokens.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CacheTokens.cpp?rev=281385=281384=281385=diff
==
--- cfe/trunk/lib/Frontend/CacheTokens.cpp (original)
+++ cfe/trunk/lib/Frontend/CacheTokens.cpp Tue Sep 13 15:17:57 2016
@@ -182,14 +182,14 @@ class PTHWriter {
   typedef llvm::DenseMap IDMap;
   typedef llvm::StringMap CachedStrsTy;
 
-  IDMap IM;
   raw_pwrite_stream 
   Preprocessor& PP;
-  uint32_t idcount;
+  IDMap IM;
+  std::vector StrEntries;
   PTHMap PM;
   CachedStrsTy CachedStrs;
+  uint32_t idcount;
   Offset CurStrOffset;
-  std::vector StrEntries;
 
    Get the persistent id for the given IdentifierInfo*.
   uint32_t ResolveID(const IdentifierInfo* II);


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


Re: [PATCH] D23852: [SemaObjC] Fix crash while parsing type arguments and protocols

2016-09-13 Thread Bruno Cardoso Lopes via cfe-commits
bruno closed this revision.
bruno added a comment.

Thanks Doug!

Committed r281383


https://reviews.llvm.org/D23852



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


r281383 - [SemaObjC] Be more strict while parsing type arguments and protocols

2016-09-13 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Tue Sep 13 15:04:35 2016
New Revision: 281383

URL: http://llvm.org/viewvc/llvm-project?rev=281383=rev
Log:
[SemaObjC] Be more strict while parsing type arguments and protocols

Fix a crash-on-invalid.

When parsing type arguments and protocols,
parseObjCTypeArgsOrProtocolQualifiers() calls ParseTypeName(), which tries to
find matching tokens for '[', '(', etc whenever they appear among potential
type names. If unmatched, ParseTypeName() yields a tok::eof token stream. This
leads to crashes since the parsing at this point is not expected to go beyond
the param list closing '>'.

Fix that by properly handling tok::eof in
parseObjCTypeArgsOrProtocolQualifiers() callers.

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

rdar://problem/25063557

Added:
cfe/trunk/test/SemaObjC/crash-on-type-args-protocols.m
Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/Parser.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=281383=281382=281383=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Sep 13 15:04:35 2016
@@ -5877,7 +5877,8 @@ bool Parser::isFunctionDeclaratorIdentif
  // To handle this, we check to see if the token after the first
  // identifier is a "," or ")".  Only then do we parse it as an
  // identifier list.
- && (NextToken().is(tok::comma) || NextToken().is(tok::r_paren));
+ && (!Tok.is(tok::eof) &&
+ (NextToken().is(tok::comma) || NextToken().is(tok::r_paren)));
 }
 
 /// ParseFunctionDeclaratorIdentifierList - While parsing a function declarator

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=281383=281382=281383=diff
==
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Sep 13 15:04:35 2016
@@ -344,9 +344,11 @@ Decl *Parser::ParseObjCAtInterfaceDeclar
   protocols, protocolLocs, EndProtoLoc,
   /*consumeLastToken=*/true,
   /*warnOnIncompleteProtocols=*/true);
+  if (Tok.is(tok::eof))
+return nullptr;
 }
   }
-  
+
   // Next, we need to check for any protocol references.
   if (LAngleLoc.isValid()) {
 if (!ProtocolIdents.empty()) {
@@ -1814,6 +1816,8 @@ void Parser::parseObjCTypeArgsAndProtoco
 protocolRAngleLoc,
 consumeLastToken,
 /*warnOnIncompleteProtocols=*/false);
+  if (Tok.is(tok::eof)) // Nothing else to do here...
+return;
 
   // An Objective-C object pointer followed by type arguments
   // can then be followed again by a set of protocol references, e.g.,
@@ -1862,6 +1866,9 @@ TypeResult Parser::parseObjCTypeArgsAndP
  protocols, protocolLocs,
  protocolRAngleLoc, consumeLastToken);
 
+  if (Tok.is(tok::eof))
+return true; // Invalid type result.
+
   // Compute the location of the last token.
   if (consumeLastToken)
 endLoc = PrevTokLocation;

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=281383=281382=281383=diff
==
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Tue Sep 13 15:04:35 2016
@@ -1539,6 +1539,8 @@ Parser::TryAnnotateName(bool IsAddressOf
NewEndLoc);
   if (NewType.isUsable())
 Ty = NewType.get();
+  else if (Tok.is(tok::eof)) // Nothing to do here, bail out...
+return ANK_Error;
 }
 
 Tok.setKind(tok::annot_typename);
@@ -1770,6 +1772,8 @@ bool Parser::TryAnnotateTypeOrScopeToken
NewEndLoc);
 if (NewType.isUsable())
   Ty = NewType.get();
+else if (Tok.is(tok::eof)) // Nothing to do here, bail out...
+  return false;
   }
 
   // This is a typename. Replace the current token in-place with an

Added: cfe/trunk/test/SemaObjC/crash-on-type-args-protocols.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/crash-on-type-args-protocols.m?rev=281383=auto
==
--- cfe/trunk/test/SemaObjC/crash-on-type-args-protocols.m (added)
+++ cfe/trunk/test/SemaObjC/crash-on-type-args-protocols.m Tue Sep 13 15:04:35 
2016
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -DFIRST -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DSECOND -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DTHIRD 

Re: [PATCH] D24426: DebugInfo: Pass non-zero alignment to DIBuilder only if aligment was forced

2016-09-13 Thread Victor Leschuk via cfe-commits
vleschuk added inline comments.


Comment at: lib/CodeGen/CGDebugInfo.cpp:608
@@ -608,2 +607,3 @@
 
   uint64_t Size = CGM.getContext().getTypeSize(Ty);
+  uint64_t Align = 0;

rnk wrote:
> IMO this is what we should be doing everywhere, rather than manually checking 
> AlignedAttr:
>   TypeInfo TI = CGM.getContext().getTypeInfo(Ty);
>   uint64_t Size = TI.Width;
>   uint64_t Align = TI.AlignIsRequired ? TI.Align : 0;
> 
> This saves a hash lookup, and handles some corner cases. AlignIsRequired is 
> already supposed to capture whether the alignment was changed.
Will check if this works in all cases. I think it's worth putting this snippet 
into helper function within anon namespace.


https://reviews.llvm.org/D24426



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


Re: [PATCH] D24153: Add bunch of _Interlocked builtins

2016-09-13 Thread Albert Gutowski via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281378: Add bunch of _Interlocked builtins (authored by 
agutowski).

Changed prior to commit:
  https://reviews.llvm.org/D24153?vs=70572=71223#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24153

Files:
  cfe/trunk/include/clang/Basic/Builtins.def
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/Headers/intrin.h
  cfe/trunk/test/CodeGen/ms-intrinsics.c
  cfe/trunk/test/CodeGen/pr27892.c

Index: cfe/trunk/include/clang/Basic/Builtins.def
===
--- cfe/trunk/include/clang/Basic/Builtins.def
+++ cfe/trunk/include/clang/Basic/Builtins.def
@@ -720,13 +720,42 @@
 LANGBUILTIN(__abnormal_termination, "i", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_abnormal_termination,  "i", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__GetExceptionInfo, "v*.", "ntu", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedCompareExchange, "LiLiD*LiLi", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedAnd8,   "ccD*c","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedAnd16,  "ssD*s","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedAnd,"LiLiD*Li", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedAnd64,  "LLiLLiD*LLi",  "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedCompareExchange8,   "ccD*cc", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedCompareExchange16,  "ssD*ss", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedCompareExchange,"LiLiD*LiLi", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedCompareExchange64,  "LLiLLiD*LLiLLi", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedCompareExchangePointer, "v*v*D*v*v*", "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedDecrement,   "LiLiD*", "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedExchangeAdd, "LiLiD*Li",   "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedExchange,"LiLiD*Li",   "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedExchangePointer, "v*v*D*v*",   "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedIncrement,   "LiLiD*", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedDecrement16,"ssD*", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedDecrement,  "LiLiD*",   "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedDecrement64,"LLiLLiD*", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchange,   "LiLiD*Li", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchange8,  "ccD*c","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchange16, "ssD*s","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchange64, "LLiLLiD*LLi",  "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchangeAdd8,   "ccD*c",  "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchangeAdd16,  "ssD*s",  "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchangeAdd,"LiLiD*Li",   "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchangeAdd64,  "LLiLLiD*LLi","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchangePointer,"v*v*D*v*",   "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchangeSub8,   "ccD*c","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchangeSub16,  "ssD*s","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchangeSub,"LiLiD*Li", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchangeSub64,  "LLiLLiD*LLi",  "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedIncrement16,"ssD*", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedIncrement,  "LiLiD*",   "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedIncrement64,"LLiLLiD*", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedOr8,  "ccD*c","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedOr16, "ssD*s","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedOr,   "LiLiD*Li", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedOr64, "LLiLLiD*LLi",  "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedXor8,  "ccD*c",   "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedXor16, "ssD*s",   "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedXor,   "LiLiD*Li","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedXor64, "LLiLLiD*LLi", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__noop,   "i.",  "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__popcnt16, "UsUs", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__popcnt,   "UiUi", "nc", ALL_MS_LANGUAGES)
Index: cfe/trunk/test/CodeGen/pr27892.c
===
--- cfe/trunk/test/CodeGen/pr27892.c
+++ cfe/trunk/test/CodeGen/pr27892.c
@@ -7,7 +7,7 @@
 // CHECK:   %[[p_addr:.*]] = alloca i64*, align 8
 // CHECK:   store i64* %p, i64** %[[p_addr]], align 8
 // CHECK:   %[[p_load:.*]] = load i64*, i64** %[[p_addr]], align 8
-// CHECK:   %[[atomic_add:.*]] = atomicrmw volatile add i64* %[[p_load]], i64 1 seq_cst
+// CHECK:   %[[atomic_add:.*]] = atomicrmw add i64* %[[p_load]], i64 1 seq_cst
 // CHECK:   %[[res:.*]] = add 

Re: r281277 - [Sema] Fix PR30346: relax __builtin_object_size checks.

2016-09-13 Thread Richard Smith via cfe-commits
On Tue, Sep 13, 2016 at 10:44 AM, Joerg Sonnenberger via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Mon, Sep 12, 2016 at 11:50:36PM -, George Burgess IV via
> cfe-commits wrote:
> > Author: gbiv
> > Date: Mon Sep 12 18:50:35 2016
> > New Revision: 281277
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=281277=rev
> > Log:
> > [Sema] Fix PR30346: relax __builtin_object_size checks.
> >
> > This patch makes us act more conservatively when trying to determine
> > the objectsize for an array at the end of an object. This is in
> > response to code like the following:
> >
> > ```
> > struct sockaddr {
> >   /* snip */
> >   char sa_data[14];
> > };
> >
> > void foo(const char *s) {
> >   size_t slen = strlen(s) + 1;
> >   size_t added_len = slen <= 14 ? 0 : slen - 14;
> >   struct sockaddr *sa = malloc(sizeof(struct sockaddr) + added_len);
> >   strcpy(sa->sa_data, s);
> >   // ...
> > }
> > ```
> >
> > `__builtin_object_size(sa->sa_data, 1)` would return 14, when there
> > could be more than 14 bytes at `sa->sa_data`.
> >
> > Code like this is apparently not uncommon. FreeBSD's manual even
> > explicitly mentions this pattern:
> > https://www.freebsd.org/doc/en/books/developers-handbook/
> sockets-essential-functions.html
> > (section 7.5.1.1.2).
> >
> > In light of this, we now just give up on any array at the end of an
> > object if we can't find the object's initial allocation.
> >
> > I lack numbers for how much more conservative we actually become as a
> > result of this change, so I chose the fix that would make us as
> > compatible with GCC as possible. If we want to be more aggressive, I'm
> > happy to consider some kind of whitelist or something instead.
>
> IMO this should be restricted to code that explicitly disables C/C++
> aliasing rules.


Do you mean -fno-strict-aliasing or -fno-struct-path-tbaa or something else
here? (I think we're not doing anyone any favours by making _FORTIFY_SOURCE
say that a pattern is OK in cases when LLVM will in fact optimize on the
assumption that it's UB, but I don't recall how aggressive
-fstruct-path-tbaa is for trailing array members.)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24426: DebugInfo: Pass non-zero alignment to DIBuilder only if aligment was forced

2016-09-13 Thread Victor Leschuk via cfe-commits
vleschuk added inline comments.


Comment at: lib/CodeGen/CGDebugInfo.cpp:3691
@@ -3635,1 +3690,3 @@
+  if (D->hasAttr())
+AlignInBits = D->getMaxAlignment();
   StringRef DeclName, LinkageName;

probinson wrote:
> dblaikie wrote:
> > is max alignment the right thing here? Should it be min alignment?
> > (is alignment in bits the desired thing across all of this too? It looked 
> > like in the backend patch there was some division by CHAR_BITS, etc?)
> I should think bits is the right choice here; seems more the province of the 
> backend to convert it into the appropriate addressable units (commonly but 
> not universally chars).
> is max alignment the right thing here? Should it be min alignment?

The DWARF document says: 

> This constant describes the actual alignment used by the compiler (if there 
> are multiple specified by the user, or if the user specified an alignment the 
> compiler couldn't satisfy, then only the strictest alignment will be added 
> through a DW_AT_alignment).

So I think max alignment is right choice here.


https://reviews.llvm.org/D24426



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


Re: [PATCH] D24330: Add some MS aliases for existing intrinsics

2016-09-13 Thread Albert Gutowski via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281375: Add some MS aliases for existing intrinsics 
(authored by agutowski).

Changed prior to commit:
  https://reviews.llvm.org/D24330?vs=71213=71220#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24330

Files:
  cfe/trunk/include/clang/Basic/Builtins.def
  cfe/trunk/include/clang/Basic/Builtins.h
  cfe/trunk/include/clang/Basic/BuiltinsX86.def
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/Headers/emmintrin.h
  cfe/trunk/lib/Headers/ia32intrin.h
  cfe/trunk/lib/Headers/intrin.h
  cfe/trunk/lib/Headers/xmmintrin.h
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/CodeGen/builtins-x86.c
  cfe/trunk/test/Sema/implicit-intel-builtin-decl.c
  cfe/trunk/test/Sema/implicit-ms-builtin-decl.c

Index: cfe/trunk/include/clang/Basic/BuiltinsX86.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def
@@ -23,6 +23,10 @@
 #   define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS)
 #endif
 
+#if defined(BUILTIN) && !defined(TARGET_HEADER_BUILTIN)
+#  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) BUILTIN(ID, TYPE, ATTRS)
+#endif
+
 // FIXME: Are these nothrow/const?
 
 // Miscellaneous builtin for checking x86 cpu features.
@@ -301,15 +305,18 @@
 TARGET_BUILTIN(__builtin_ia32_pabsd128, "V4iV4i", "", "ssse3")
 
 TARGET_BUILTIN(__builtin_ia32_ldmxcsr, "vUi", "", "sse")
+TARGET_HEADER_BUILTIN(_mm_setcsr, "vUi", "h","xmmintrin.h", ALL_LANGUAGES, "sse")
 TARGET_BUILTIN(__builtin_ia32_stmxcsr, "Ui", "", "sse")
+TARGET_HEADER_BUILTIN(_mm_getcsr, "Ui", "h", "xmmintrin.h", ALL_LANGUAGES, "sse")
 TARGET_BUILTIN(__builtin_ia32_cvtss2si, "iV4f", "", "sse")
 TARGET_BUILTIN(__builtin_ia32_cvttss2si, "iV4f", "", "sse")
 TARGET_BUILTIN(__builtin_ia32_cvtss2si64, "LLiV4f", "", "sse")
 TARGET_BUILTIN(__builtin_ia32_cvttss2si64, "LLiV4f", "", "sse")
 TARGET_BUILTIN(__builtin_ia32_storehps, "vV2i*V4f", "", "sse")
 TARGET_BUILTIN(__builtin_ia32_storelps, "vV2i*V4f", "", "sse")
 TARGET_BUILTIN(__builtin_ia32_movmskps, "iV4f", "", "sse")
 TARGET_BUILTIN(__builtin_ia32_sfence, "v", "", "sse")
+TARGET_HEADER_BUILTIN(_mm_sfence, "v", "h", "xmmintrin.h", ALL_LANGUAGES, "sse")
 TARGET_BUILTIN(__builtin_ia32_rcpps, "V4fV4f", "", "sse")
 TARGET_BUILTIN(__builtin_ia32_rcpss, "V4fV4f", "", "sse")
 TARGET_BUILTIN(__builtin_ia32_rsqrtps, "V4fV4f", "", "sse")
@@ -337,9 +344,13 @@
 TARGET_BUILTIN(__builtin_ia32_cvtps2dq, "V4iV4f", "", "sse2")
 TARGET_BUILTIN(__builtin_ia32_cvttps2dq, "V4iV4f", "", "sse2")
 TARGET_BUILTIN(__builtin_ia32_clflush, "vvC*", "", "sse2")
+TARGET_HEADER_BUILTIN(_mm_clflush, "vvC*", "h", "emmintrin.h", ALL_LANGUAGES, "sse2")
 TARGET_BUILTIN(__builtin_ia32_lfence, "v", "", "sse2")
+TARGET_HEADER_BUILTIN(_mm_lfence, "v", "h", "emmintrin.h", ALL_LANGUAGES, "sse2")
 TARGET_BUILTIN(__builtin_ia32_mfence, "v", "", "sse2")
+TARGET_HEADER_BUILTIN(_mm_mfence, "v", "h", "emmintrin.h", ALL_LANGUAGES, "sse2")
 TARGET_BUILTIN(__builtin_ia32_pause, "v", "", "sse2")
+TARGET_HEADER_BUILTIN(_mm_pause, "v", "h", "emmintrin.h", ALL_LANGUAGES, "sse2")
 TARGET_BUILTIN(__builtin_ia32_pmuludq128, "V2LLiV4iV4i", "", "sse2")
 TARGET_BUILTIN(__builtin_ia32_psraw128, "V8sV8sV8s", "", "sse2")
 TARGET_BUILTIN(__builtin_ia32_psrad128, "V4iV4iV4i", "", "sse2")
@@ -894,6 +905,7 @@
 
 BUILTIN(__builtin_ia32_rdpmc, "ULLii", "")
 BUILTIN(__builtin_ia32_rdtsc, "ULLi", "")
+BUILTIN(__rdtsc, "ULLi", "")
 BUILTIN(__builtin_ia32_rdtscp, "ULLiUi*", "")
 // PKU
 TARGET_BUILTIN(__builtin_ia32_rdpkru, "Ui", "", "pku")
@@ -2059,3 +2071,4 @@
 
 #undef BUILTIN
 #undef TARGET_BUILTIN
+#undef TARGET_HEADER_BUILTIN
Index: cfe/trunk/include/clang/Basic/Builtins.h
===
--- cfe/trunk/include/clang/Basic/Builtins.h
+++ cfe/trunk/include/clang/Basic/Builtins.h
@@ -139,6 +139,13 @@
 return strchr(getRecord(ID).Attributes, 'f') != nullptr;
   }
 
+  // \brief Returns true if this builtin requires appropriate header in other
+  // compilers. In Clang it will work even without including it, but we can emit
+  // a warning about missing header.
+  bool isHeaderDependentFunction(unsigned ID) const {
+return strchr(getRecord(ID).Attributes, 'h') != nullptr;
+  }
+
   /// \brief Determines whether this builtin is a predefined compiler-rt/libgcc
   /// function, such as "__clear_cache", where we know the signature a
   /// priori.
Index: cfe/trunk/include/clang/Basic/Builtins.def
===
--- cfe/trunk/include/clang/Basic/Builtins.def
+++ cfe/trunk/include/clang/Basic/Builtins.def
@@ -74,6 +74,7 @@
 //  f -> this is a libc/libm function without the '__builtin_' prefix. It can
 //   be followed by ':headername:' to state which header this function
 //   comes 

r281375 - Add some MS aliases for existing intrinsics

2016-09-13 Thread Albert Gutowski via cfe-commits
Author: agutowski
Date: Tue Sep 13 14:26:42 2016
New Revision: 281375

URL: http://llvm.org/viewvc/llvm-project?rev=281375=rev
Log:
Add some MS aliases for existing intrinsics

Reviewers: thakis, compnerd, majnemer, rsmith, rnk

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/Sema/implicit-intel-builtin-decl.c
cfe/trunk/test/Sema/implicit-ms-builtin-decl.c
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/include/clang/Basic/Builtins.h
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/emmintrin.h
cfe/trunk/lib/Headers/ia32intrin.h
cfe/trunk/lib/Headers/intrin.h
cfe/trunk/lib/Headers/xmmintrin.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGen/builtins-x86.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=281375=281374=281375=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Tue Sep 13 14:26:42 2016
@@ -74,6 +74,7 @@
 //  f -> this is a libc/libm function without the '__builtin_' prefix. It can
 //   be followed by ':headername:' to state which header this function
 //   comes from.
+//  h -> this function requires a specific header or an explicit declaration.
 //  i -> this is a runtime library implemented function without the
 //   '__builtin_' prefix. It will be implemented in compiler-rt or libgcc.
 //  p:N: -> this is a printf-like function whose Nth argument is the format
@@ -708,6 +709,9 @@ BUILTIN(__builtin_rindex, "c*cC*i", "Fn"
 // Microsoft builtins.  These are only active with -fms-extensions.
 LANGBUILTIN(_alloca,  "v*z", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__assume, "vb",  "n", ALL_MS_LANGUAGES)
+LIBBUILTIN(_byteswap_ushort, "UsUs", "fnc", "stdlib.h", ALL_MS_LANGUAGES)
+LIBBUILTIN(_byteswap_ulong,  "ULiULi",   "fnc", "stdlib.h", ALL_MS_LANGUAGES)
+LIBBUILTIN(_byteswap_uint64, "ULLiULLi", "fnc", "stdlib.h", ALL_MS_LANGUAGES)
 LANGBUILTIN(__debugbreak, "v",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__exception_code, "ULi", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_exception_code,  "ULi", "n", ALL_MS_LANGUAGES)
@@ -724,6 +728,9 @@ LANGBUILTIN(_InterlockedExchange,
 LANGBUILTIN(_InterlockedExchangePointer, "v*v*D*v*",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedIncrement,   "LiLiD*", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__noop,   "i.",  "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(__popcnt16, "UsUs", "nc", ALL_MS_LANGUAGES)
+LANGBUILTIN(__popcnt,   "UiUi", "nc", ALL_MS_LANGUAGES)
+LANGBUILTIN(__popcnt64, "ULLiULLi", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__readfsdword,"ULiULi", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_rotl8,  "UcUcUc","n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_rotl16, "UsUsUc","n", ALL_MS_LANGUAGES)

Modified: cfe/trunk/include/clang/Basic/Builtins.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.h?rev=281375=281374=281375=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.h (original)
+++ cfe/trunk/include/clang/Basic/Builtins.h Tue Sep 13 14:26:42 2016
@@ -139,6 +139,13 @@ public:
 return strchr(getRecord(ID).Attributes, 'f') != nullptr;
   }
 
+  // \brief Returns true if this builtin requires appropriate header in other
+  // compilers. In Clang it will work even without including it, but we can 
emit
+  // a warning about missing header.
+  bool isHeaderDependentFunction(unsigned ID) const {
+return strchr(getRecord(ID).Attributes, 'h') != nullptr;
+  }
+
   /// \brief Determines whether this builtin is a predefined compiler-rt/libgcc
   /// function, such as "__clear_cache", where we know the signature a
   /// priori.

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=281375=281374=281375=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Tue Sep 13 14:26:42 2016
@@ -23,6 +23,10 @@
 #   define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS)
 #endif
 
+#if defined(BUILTIN) && !defined(TARGET_HEADER_BUILTIN)
+#  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) 
BUILTIN(ID, TYPE, ATTRS)
+#endif
+
 // FIXME: Are these nothrow/const?
 
 // Miscellaneous builtin for checking x86 cpu features.
@@ -301,7 +305,9 @@ TARGET_BUILTIN(__builtin_ia32_pabsw128,
 TARGET_BUILTIN(__builtin_ia32_pabsd128, "V4iV4i", "", "ssse3")
 
 TARGET_BUILTIN(__builtin_ia32_ldmxcsr, "vUi", "", "sse")

Re: [PATCH] D24484: [analyzer] Fix ExprEngine::VisitMemberExpr

2016-09-13 Thread Alexander Shaposhnikov via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281373: [analyzer] Fix ExprEngine::VisitMemberExpr (authored 
by alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D24484?vs=71082=71218#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24484

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
  cfe/trunk/test/Analysis/array-struct.c

Index: cfe/trunk/test/Analysis/array-struct.c
===
--- cfe/trunk/test/Analysis/array-struct.c
+++ cfe/trunk/test/Analysis/array-struct.c
@@ -135,6 +135,17 @@
 
 void bar(int*);
 
+struct s3 gets3() {
+  struct s3 s;
+  return s;
+}
+
+void accessArrayFieldNoCrash() {
+  bar(gets3().a);
+  bar((gets3().a));
+  bar(((gets3().a)));  
+}
+
 // Test if the array is correctly invalidated.
 void f15() {
   int a[10];
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2044,7 +2044,7 @@
 if (!M->isGLValue()) {
   assert(M->getType()->isArrayType());
   const ImplicitCastExpr *PE =
-dyn_cast((*I)->getParentMap().getParent(M));
+
dyn_cast((*I)->getParentMap().getParentIgnoreParens(M));
   if (!PE || PE->getCastKind() != CK_ArrayToPointerDecay) {
 llvm_unreachable("should always be wrapped in 
ArrayToPointerDecay");
   }


Index: cfe/trunk/test/Analysis/array-struct.c
===
--- cfe/trunk/test/Analysis/array-struct.c
+++ cfe/trunk/test/Analysis/array-struct.c
@@ -135,6 +135,17 @@
 
 void bar(int*);
 
+struct s3 gets3() {
+  struct s3 s;
+  return s;
+}
+
+void accessArrayFieldNoCrash() {
+  bar(gets3().a);
+  bar((gets3().a));
+  bar(((gets3().a)));  
+}
+
 // Test if the array is correctly invalidated.
 void f15() {
   int a[10];
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2044,7 +2044,7 @@
 if (!M->isGLValue()) {
   assert(M->getType()->isArrayType());
   const ImplicitCastExpr *PE =
-dyn_cast((*I)->getParentMap().getParent(M));
+dyn_cast((*I)->getParentMap().getParentIgnoreParens(M));
   if (!PE || PE->getCastKind() != CK_ArrayToPointerDecay) {
 llvm_unreachable("should always be wrapped in ArrayToPointerDecay");
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r281373 - [analyzer] Fix ExprEngine::VisitMemberExpr

2016-09-13 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Tue Sep 13 14:17:20 2016
New Revision: 281373

URL: http://llvm.org/viewvc/llvm-project?rev=281373=rev
Log:
[analyzer] Fix ExprEngine::VisitMemberExpr

AST may contain intermediate ParenExpr nodes
between MemberExpr and ArrayToPointerDecay.
This diff adjusts the check in ExprEngine::VisitMemberExpr accordingly.
Test plan: make -j8 check-clang-analysis

Differential revision: https://reviews.llvm.org/D24484

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/array-struct.c

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=281373=281372=281373=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Tue Sep 13 14:17:20 2016
@@ -2044,7 +2044,7 @@ void ExprEngine::VisitMemberExpr(const M
 if (!M->isGLValue()) {
   assert(M->getType()->isArrayType());
   const ImplicitCastExpr *PE =
-dyn_cast((*I)->getParentMap().getParent(M));
+
dyn_cast((*I)->getParentMap().getParentIgnoreParens(M));
   if (!PE || PE->getCastKind() != CK_ArrayToPointerDecay) {
 llvm_unreachable("should always be wrapped in 
ArrayToPointerDecay");
   }

Modified: cfe/trunk/test/Analysis/array-struct.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/array-struct.c?rev=281373=281372=281373=diff
==
--- cfe/trunk/test/Analysis/array-struct.c (original)
+++ cfe/trunk/test/Analysis/array-struct.c Tue Sep 13 14:17:20 2016
@@ -135,6 +135,17 @@ void f14() {
 
 void bar(int*);
 
+struct s3 gets3() {
+  struct s3 s;
+  return s;
+}
+
+void accessArrayFieldNoCrash() {
+  bar(gets3().a);
+  bar((gets3().a));
+  bar(((gets3().a)));  
+}
+
 // Test if the array is correctly invalidated.
 void f15() {
   int a[10];


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


Re: [PATCH] D24488: Simplify Clang's version number configuration in CMake.

2016-09-13 Thread Richard Smith via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D24488



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


Re: [PATCH] D24469: [clang-cl] Diagnose duplicate uuids.

2016-09-13 Thread Nico Weber via cfe-commits
thakis closed this revision.
thakis added a comment.

r281367, thanks!


https://reviews.llvm.org/D24469



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


r281367 - [clang-cl] Diagnose duplicate uuids.

2016-09-13 Thread Nico Weber via cfe-commits
Author: nico
Date: Tue Sep 13 13:55:26 2016
New Revision: 281367

URL: http://llvm.org/viewvc/llvm-project?rev=281367=rev
Log:
[clang-cl] Diagnose duplicate uuids.

This mostly behaves cl.exe's behavior, even though clang-cl is stricter in some
corner cases and more lenient in others (see the included test).

To make the uuid declared previously here diagnostic work correctly, tweak
stripTypeAttributesOffDeclSpec() to keep attributes in the right order.

https://reviews.llvm.org/D24469

Added:
cfe/trunk/test/SemaCXX/ms-uuid.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/AttributeList.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=281367=281366=281367=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Sep 13 13:55:26 
2016
@@ -2255,6 +2255,8 @@ def err_attribute_only_once_per_paramete
   "%0 attribute can only be applied once per parameter">;
 def err_attribute_uuid_malformed_guid : Error<
   "uuid attribute contains a malformed GUID">;
+def err_mismatched_uuid : Error<"uuid does not match previous declaration">;
+def note_previous_uuid : Note<"previous uuid specified here">;
 def warn_attribute_pointers_only : Warning<
   "%0 attribute only applies to%select{| constant}1 pointer arguments">,
   InGroup;

Modified: cfe/trunk/include/clang/Sema/AttributeList.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=281367=281366=281367=diff
==
--- cfe/trunk/include/clang/Sema/AttributeList.h (original)
+++ cfe/trunk/include/clang/Sema/AttributeList.h Tue Sep 13 13:55:26 2016
@@ -748,6 +748,19 @@ public:
 list = newList;
   }
 
+  void addAllAtEnd(AttributeList *newList) {
+if (!list) {
+  list = newList;
+  return;
+}
+
+AttributeList *lastInList = list;
+while (AttributeList *next = lastInList->getNext())
+  lastInList = next;
+
+lastInList->setNext(newList);
+  }
+
   void set(AttributeList *newList) {
 list = newList;
   }

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=281367=281366=281367=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Sep 13 13:55:26 2016
@@ -2208,6 +2208,8 @@ public:
   VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range,
   VisibilityAttr::VisibilityType Vis,
   unsigned AttrSpellingListIndex);
+  UuidAttr *mergeUuidAttr(Decl *D, SourceRange Range,
+  unsigned AttrSpellingListIndex, StringRef Uuid);
   DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range,
 unsigned AttrSpellingListIndex);
   DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=281367=281366=281367=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Sep 13 13:55:26 2016
@@ -1439,6 +1439,8 @@ void Parser::stripTypeAttributesOffDeclS
   ParsedAttributes  = DS.getAttributes();
   AttributeList *AL = PA.getList();
   AttributeList *Prev = nullptr;
+  AttributeList *TypeAttrHead = nullptr;
+  AttributeList *TypeAttrTail = nullptr;
   while (AL) {
 AttributeList *Next = AL->getNext();
 
@@ -1446,8 +1448,12 @@ void Parser::stripTypeAttributesOffDeclS
  AL->isDeclspecAttribute()) ||
 AL->isMicrosoftAttribute()) {
   // Stitch the attribute into the tag's attribute list.
-  AL->setNext(nullptr);
-  Attrs.add(AL);
+  if (TypeAttrTail)
+TypeAttrTail->setNext(AL);
+  else
+TypeAttrHead = AL;
+  TypeAttrTail = AL;
+  TypeAttrTail->setNext(nullptr);
 
   // Remove the attribute from the variable's attribute list.
   if (Prev) {
@@ -1465,6 +1471,12 @@ void Parser::stripTypeAttributesOffDeclS
 
 AL = Next;
   }
+
+  // Find end of type attributes Attrs and add NewTypeAttributes in the same
+  // order they were in originally.  (Remember, in AttributeList things earlier
+  // in source order are later in the list, since new attributes are added to
+  // the front of the list.)
+  Attrs.addAllAtEnd(TypeAttrHead);
 }
 
 

[PATCH] D24518: Correct assert text in DeclGroup::getSingleDecl()

2016-09-13 Thread Ben Taylor via cfe-commits
brtaylor92 created this revision.
brtaylor92 added reviewers: alexfh, craig.topper.
brtaylor92 added a subscriber: cfe-commits.

Assert text for getSingleDecl() is inaccurate. Appears to have been copy pasted 
from getDeclGroup()

https://reviews.llvm.org/D24518

Files:
  include/clang/AST/DeclGroup.h

Index: include/clang/AST/DeclGroup.h
===
--- include/clang/AST/DeclGroup.h
+++ include/clang/AST/DeclGroup.h
@@ -84,7 +84,7 @@
   bool isDeclGroup() const { return getKind() == DeclGroupKind; }
 
   Decl *getSingleDecl() {
-assert(isSingleDecl() && "Isn't a declgroup");
+assert(isSingleDecl() && "Isn't a single decl");
 return D;
   }
   const Decl *getSingleDecl() const {


Index: include/clang/AST/DeclGroup.h
===
--- include/clang/AST/DeclGroup.h
+++ include/clang/AST/DeclGroup.h
@@ -84,7 +84,7 @@
   bool isDeclGroup() const { return getKind() == DeclGroupKind; }
 
   Decl *getSingleDecl() {
-assert(isSingleDecl() && "Isn't a declgroup");
+assert(isSingleDecl() && "Isn't a single decl");
 return D;
   }
   const Decl *getSingleDecl() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24330: Add some MS aliases for existing intrinsics

2016-09-13 Thread Albert Gutowski via cfe-commits
agutowski updated this revision to Diff 71213.
agutowski added a comment.

Merge C and C++ tests


https://reviews.llvm.org/D24330

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/Builtins.h
  include/clang/Basic/BuiltinsX86.def
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/emmintrin.h
  lib/Headers/ia32intrin.h
  lib/Headers/intrin.h
  lib/Headers/xmmintrin.h
  lib/Sema/SemaDecl.cpp
  test/CodeGen/builtins-x86.c
  test/Sema/implicit-intel-builtin-decl.c
  test/Sema/implicit-ms-builtin-decl.c

Index: lib/Headers/ia32intrin.h
===
--- lib/Headers/ia32intrin.h
+++ lib/Headers/ia32intrin.h
@@ -60,12 +60,6 @@
   return __builtin_ia32_rdpmc(__A);
 }
 
-/* __rdtsc */
-static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
-__rdtsc(void) {
-  return __builtin_ia32_rdtsc();
-}
-
 /* __rdtscp */
 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
 __rdtscp(unsigned int *__A) {
Index: lib/Headers/emmintrin.h
===
--- lib/Headers/emmintrin.h
+++ lib/Headers/emmintrin.h
@@ -2457,11 +2457,7 @@
 /// \param __p
 ///A pointer to the memory location used to identify the cache line to be
 ///flushed.
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_clflush(void const *__p)
-{
-  __builtin_ia32_clflush(__p);
-}
+void _mm_clflush(void const *);
 
 /// \brief Forces strong memory ordering (serialization) between load
 ///instructions preceding this instruction and load instructions following
@@ -2472,11 +2468,7 @@
 ///
 /// This intrinsic corresponds to the \c LFENCE instruction.
 ///
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_lfence(void)
-{
-  __builtin_ia32_lfence();
-}
+void _mm_lfence(void);
 
 /// \brief Forces strong memory ordering (serialization) between load and store
 ///instructions preceding this instruction and load and store instructions
@@ -2487,11 +2479,7 @@
 ///
 /// This intrinsic corresponds to the \c MFENCE instruction.
 ///
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_mfence(void)
-{
-  __builtin_ia32_mfence();
-}
+void _mm_mfence(void);
 
 /// \brief Converts 16-bit signed integers from both 128-bit integer vector
 ///operands into 8-bit signed integers, and packs the results into the
@@ -3213,11 +3201,7 @@
 ///
 /// This intrinsic corresponds to the \c PAUSE instruction.
 ///
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_pause(void)
-{
-  __builtin_ia32_pause();
-}
+void _mm_pause(void);
 
 #undef __DEFAULT_FN_ATTRS
 
Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+++ lib/Headers/intrin.h
@@ -518,14 +518,6 @@
   *_Index = 31 - __builtin_clzl(_Mask);
   return 1;
 }
-static __inline__ unsigned short __DEFAULT_FN_ATTRS
-__popcnt16(unsigned short _Value) {
-  return __builtin_popcount((int)_Value);
-}
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
-__popcnt(unsigned int _Value) {
-  return __builtin_popcount(_Value);
-}
 static __inline__ unsigned char __DEFAULT_FN_ATTRS
 _bittest(long const *_BitBase, long _BitPos) {
   return (*_BitBase >> _BitPos) & 1;
@@ -568,11 +560,6 @@
   *_Index = 63 - __builtin_clzll(_Mask);
   return 1;
 }
-static __inline__
-unsigned __int64 __DEFAULT_FN_ATTRS
-__popcnt64(unsigned __int64 _Value) {
-  return __builtin_popcountll(_Value);
-}
 static __inline__ unsigned char __DEFAULT_FN_ATTRS
 _bittest64(__int64 const *_BitBase, __int64 _BitPos) {
   return (*_BitBase >> _BitPos) & 1;
Index: lib/Headers/xmmintrin.h
===
--- lib/Headers/xmmintrin.h
+++ lib/Headers/xmmintrin.h
@@ -2094,11 +2094,7 @@
 ///
 /// This intrinsic corresponds to the \c SFENCE instruction.
 ///
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_sfence(void)
-{
-  __builtin_ia32_sfence();
-}
+void _mm_sfence(void);
 
 /// \brief Extracts 16-bit element from a 64-bit vector of [4 x i16] and
 ///returns it, as specified by the immediate integer operand.
@@ -2408,11 +2404,7 @@
 ///
 /// \returns A 32-bit unsigned integer containing the contents of the MXCSR
 ///register.
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
-_mm_getcsr(void)
-{
-  return __builtin_ia32_stmxcsr();
-}
+unsigned int _mm_getcsr(void);
 
 /// \brief Sets the MXCSR register with the 32-bit unsigned integer value. There
 ///are several groups of macros associated with this intrinsic, including:
@@ -2450,11 +2442,7 @@
 ///
 /// \param __i
 ///A 32-bit unsigned integer value to be written to the MXCSR register.
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_setcsr(unsigned int __i)
-{
-  __builtin_ia32_ldmxcsr(__i);
-}
+void _mm_setcsr(unsigned int);
 
 /// \brief Selects 4 float values from the 128-bit operands of [4 x float], as
 ///specified by the immediate value operand.
Index: lib/CodeGen/CGBuiltin.cpp

Re: [PATCH] D24330: Add some MS aliases for existing intrinsics

2016-09-13 Thread Reid Kleckner via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm after merging the test back.



Comment at: test/Sema/implicit-intel-builtin-decl.c:4
@@ +3,3 @@
+void f() {
+  (void)_mm_getcsr(); // expected-warning{{implicitly declaring library 
function '_mm_getcsr'}} \
+  // expected-note{{include the header  or explicitly provide a 
declaration for '_mm_getcsr'}}

agutowski wrote:
> rnk wrote:
> > Can you add a C++ test? I think you'll get "undeclared identifier 
> > '_mm_getcsr'" instead of this helpful diagnostic.
> This diagnostic works also in C++, although that's not the case with 
> _byteswap functions - if they are LIBBUILTINs, the C++ diagnostic doesn't 
> work, and LANGBUILTINs doesn't have header dependencies. I can create another 
> thing like TARGET_HEADER_BUILTIN, but I don't know if that's a good idea.
OK, it seems fine as is.

Given that there are no diagnostic differences, I would suggest copy-pasting 
the RUN line at the top of this file and adding `-x c++` to avoid duplicating 
the whole test.


https://reviews.llvm.org/D24330



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


Re: [PATCH] D24330: Add some MS aliases for existing intrinsics

2016-09-13 Thread Albert Gutowski via cfe-commits
agutowski updated this revision to Diff 71212.
agutowski added a comment.

Add test for implicitly declared intel intrinsic diagnostic in C++


https://reviews.llvm.org/D24330

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/Builtins.h
  include/clang/Basic/BuiltinsX86.def
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/emmintrin.h
  lib/Headers/ia32intrin.h
  lib/Headers/intrin.h
  lib/Headers/xmmintrin.h
  lib/Sema/SemaDecl.cpp
  test/CodeGen/builtins-x86.c
  test/Sema/implicit-intel-builtin-decl.c
  test/Sema/implicit-intel-builtin-decl.cpp
  test/Sema/implicit-ms-builtin-decl.c

Index: lib/Headers/ia32intrin.h
===
--- lib/Headers/ia32intrin.h
+++ lib/Headers/ia32intrin.h
@@ -60,12 +60,6 @@
   return __builtin_ia32_rdpmc(__A);
 }
 
-/* __rdtsc */
-static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
-__rdtsc(void) {
-  return __builtin_ia32_rdtsc();
-}
-
 /* __rdtscp */
 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
 __rdtscp(unsigned int *__A) {
Index: lib/Headers/emmintrin.h
===
--- lib/Headers/emmintrin.h
+++ lib/Headers/emmintrin.h
@@ -2457,11 +2457,7 @@
 /// \param __p
 ///A pointer to the memory location used to identify the cache line to be
 ///flushed.
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_clflush(void const *__p)
-{
-  __builtin_ia32_clflush(__p);
-}
+void _mm_clflush(void const *);
 
 /// \brief Forces strong memory ordering (serialization) between load
 ///instructions preceding this instruction and load instructions following
@@ -2472,11 +2468,7 @@
 ///
 /// This intrinsic corresponds to the \c LFENCE instruction.
 ///
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_lfence(void)
-{
-  __builtin_ia32_lfence();
-}
+void _mm_lfence(void);
 
 /// \brief Forces strong memory ordering (serialization) between load and store
 ///instructions preceding this instruction and load and store instructions
@@ -2487,11 +2479,7 @@
 ///
 /// This intrinsic corresponds to the \c MFENCE instruction.
 ///
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_mfence(void)
-{
-  __builtin_ia32_mfence();
-}
+void _mm_mfence(void);
 
 /// \brief Converts 16-bit signed integers from both 128-bit integer vector
 ///operands into 8-bit signed integers, and packs the results into the
@@ -3213,11 +3201,7 @@
 ///
 /// This intrinsic corresponds to the \c PAUSE instruction.
 ///
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_pause(void)
-{
-  __builtin_ia32_pause();
-}
+void _mm_pause(void);
 
 #undef __DEFAULT_FN_ATTRS
 
Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+++ lib/Headers/intrin.h
@@ -518,14 +518,6 @@
   *_Index = 31 - __builtin_clzl(_Mask);
   return 1;
 }
-static __inline__ unsigned short __DEFAULT_FN_ATTRS
-__popcnt16(unsigned short _Value) {
-  return __builtin_popcount((int)_Value);
-}
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
-__popcnt(unsigned int _Value) {
-  return __builtin_popcount(_Value);
-}
 static __inline__ unsigned char __DEFAULT_FN_ATTRS
 _bittest(long const *_BitBase, long _BitPos) {
   return (*_BitBase >> _BitPos) & 1;
@@ -568,11 +560,6 @@
   *_Index = 63 - __builtin_clzll(_Mask);
   return 1;
 }
-static __inline__
-unsigned __int64 __DEFAULT_FN_ATTRS
-__popcnt64(unsigned __int64 _Value) {
-  return __builtin_popcountll(_Value);
-}
 static __inline__ unsigned char __DEFAULT_FN_ATTRS
 _bittest64(__int64 const *_BitBase, __int64 _BitPos) {
   return (*_BitBase >> _BitPos) & 1;
Index: lib/Headers/xmmintrin.h
===
--- lib/Headers/xmmintrin.h
+++ lib/Headers/xmmintrin.h
@@ -2094,11 +2094,7 @@
 ///
 /// This intrinsic corresponds to the \c SFENCE instruction.
 ///
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_sfence(void)
-{
-  __builtin_ia32_sfence();
-}
+void _mm_sfence(void);
 
 /// \brief Extracts 16-bit element from a 64-bit vector of [4 x i16] and
 ///returns it, as specified by the immediate integer operand.
@@ -2408,11 +2404,7 @@
 ///
 /// \returns A 32-bit unsigned integer containing the contents of the MXCSR
 ///register.
-static __inline__ unsigned int __DEFAULT_FN_ATTRS
-_mm_getcsr(void)
-{
-  return __builtin_ia32_stmxcsr();
-}
+unsigned int _mm_getcsr(void);
 
 /// \brief Sets the MXCSR register with the 32-bit unsigned integer value. There
 ///are several groups of macros associated with this intrinsic, including:
@@ -2450,11 +2442,7 @@
 ///
 /// \param __i
 ///A 32-bit unsigned integer value to be written to the MXCSR register.
-static __inline__ void __DEFAULT_FN_ATTRS
-_mm_setcsr(unsigned int __i)
-{
-  __builtin_ia32_ldmxcsr(__i);
-}
+void _mm_setcsr(unsigned int);
 
 /// \brief Selects 4 float values from the 128-bit operands of [4 x float], as
 ///specified 

Re: [PATCH] D24372: [libcxx] Sprinkle constexpr over compressed_pair

2016-09-13 Thread Keno Fischer via cfe-commits
loladiro added a comment.

Small bump here. Is it possible to rewrite these without std::forward, so we 
can have the const-initialization behavior on C++11 (or is there are different 
solution?).


Repository:
  rL LLVM

https://reviews.llvm.org/D24372



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


r281363 - Work around a GCC 4.7-specific issue: due to implementing older rules for

2016-09-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Sep 13 13:35:34 2016
New Revision: 281363

URL: http://llvm.org/viewvc/llvm-project?rev=281363=rev
Log:
Work around a GCC 4.7-specific issue: due to implementing older rules for
implicit declarations of move operations, GCC 4.7 would find that SelectPiece
has neither a move constructor nor a copy constructor. The copy constructor was
(correctly) deleted because the class has a member of move-only type, and the
move constructor was (incorrectly, per current C++ rules) not provided because
the class has a copy-only base class (in turn because it explicitly declares a
destructor).

Modified:
cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp

Modified: cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp?rev=281363=281362=281363=diff
==
--- cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp Tue Sep 13 13:35:34 
2016
@@ -910,6 +910,11 @@ namespace {
 /// Diagnostic text, parsed into pieces.
 struct DiagText {
   struct Piece {
+// This type and its derived classes are move-only.
+Piece() = default;
+Piece(Piece &) = default;
+Piece =(Piece &) = default;
+
 virtual void print(std::vector ) = 0;
 virtual ~Piece() {}
   };


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


Re: [PATCH] D24330: Add some MS aliases for existing intrinsics

2016-09-13 Thread Albert Gutowski via cfe-commits
agutowski added inline comments.


Comment at: test/Sema/implicit-intel-builtin-decl.c:4
@@ +3,3 @@
+void f() {
+  (void)_mm_getcsr(); // expected-warning{{implicitly declaring library 
function '_mm_getcsr'}} \
+  // expected-note{{include the header  or explicitly provide a 
declaration for '_mm_getcsr'}}

rnk wrote:
> Can you add a C++ test? I think you'll get "undeclared identifier 
> '_mm_getcsr'" instead of this helpful diagnostic.
This diagnostic works also in C++, although that's not the case with _byteswap 
functions - if they are LIBBUILTINs, the C++ diagnostic doesn't work, and 
LANGBUILTINs doesn't have header dependencies. I can create another thing like 
TARGET_HEADER_BUILTIN, but I don't know if that's a good idea.


https://reviews.llvm.org/D24330



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


Re: r281261 - CodeGen: use some range-based for loops

2016-09-13 Thread Justin Bogner via cfe-commits
Saleem Abdulrasool via cfe-commits  writes:
> Author: compnerd
> Date: Mon Sep 12 16:15:23 2016
> New Revision: 281261
>
> URL: http://llvm.org/viewvc/llvm-project?rev=281261=rev
> Log:
> CodeGen: use some range-based for loops
>
> Use range-based for loops to simplify the logic.  Add an explicit check for
> MachO as the inline asm uses MachO specific directives.
>
> Modified:
> cfe/trunk/lib/CodeGen/CGObjCMac.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=281261=281260=281261=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Mon Sep 12 16:15:23 2016
> @@ -5178,27 +5178,23 @@ void CGObjCMac::FinishModule() {
>// important for correct linker interaction.
>//
>// FIXME: It would be nice if we had an LLVM construct for this.
> -  if (!LazySymbols.empty() || !DefinedSymbols.empty()) {
> +  if ((!LazySymbols.empty() || !DefinedSymbols.empty()) &&
> +  CGM.getTriple().isOSBinFormatMachO()) {
>  SmallString<256> Asm;
>  Asm += CGM.getModule().getModuleInlineAsm();
>  if (!Asm.empty() && Asm.back() != '\n')
>Asm += '\n';
>  
>  llvm::raw_svector_ostream OS(Asm);
> -for (llvm::SetVector::iterator I = 
> DefinedSymbols.begin(),
> -   e = DefinedSymbols.end(); I != e; ++I)
> -  OS << "\t.objc_class_name_" << (*I)->getName() << "=0\n"
> - << "\t.globl .objc_class_name_" << (*I)->getName() << "\n";
> -for (llvm::SetVector::iterator I = LazySymbols.begin(),
> - e = LazySymbols.end(); I != e; ++I) {
> -  OS << "\t.lazy_reference .objc_class_name_" << (*I)->getName() << "\n";
> -}
> +for (const auto  : DefinedSymbols)

Is this a reference to a pointer? Please write this as `const auto *`,
or even just write out the type `const IdentifierInfo *`.

> +  OS << "\t.objc_class_name_" << Sym->getName() << "=0\n"
> + << "\t.globl .objc_class_name_" << Sym->getName() << "\n";
> +for (const auto  : LazySymbols)
> +  OS << "\t.lazy_reference .objc_class_name_" << Sym->getName() << "\n";
> +for (const auto  : DefinedCategoryNames)
> +  OS << "\t.objc_category_name_" << Category << "=0\n"
> + << "\t.globl .objc_category_name_" << Category << "\n";
>  
> -for (size_t i = 0, e = DefinedCategoryNames.size(); i < e; ++i) {
> -  OS << "\t.objc_category_name_" << DefinedCategoryNames[i] << "=0\n"
> - << "\t.globl .objc_category_name_" << DefinedCategoryNames[i] << 
> "\n";
> -}
> -
>  CGM.getModule().setModuleInlineAsm(OS.str());
>}
>  }
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: [PATCH] D24426: DebugInfo: Pass non-zero alignment to DIBuilder only if aligment was forced

2016-09-13 Thread Robinson, Paul via cfe-commits
I hadn't thought Clang wanted to be *quite* so knowledgeable about targets, and 
similarly not so tightly tied to byte-addressable targets.  But if both of 
those things are actually okay, then it's fine to set the alignment value here 
to what would be passed through to DWARF.
--paulr

From: David Blaikie [mailto:dblai...@gmail.com]
Sent: Monday, September 12, 2016 6:11 PM
To: Robinson, Paul; reviews+d24426+public+6ee6274d38fdf...@reviews.llvm.org; 
vlesc...@accesssoftek.com; echri...@gmail.com; apra...@apple.com; 
mehdi.am...@apple.com
Cc: cfe-commits (cfe-commits@lists.llvm.org)
Subject: Re: [PATCH] D24426: DebugInfo: Pass non-zero alignment to DIBuilder 
only if aligment was forced


On Mon, Sep 12, 2016 at 6:01 PM Robinson, Paul 
> wrote:
The text in the committee draft is different (e.g., the exhortation about 
non-default alignment is gone), with an example to the effect that a value of 8 
means the entity's address is a multiple of 8 (not 2^8).  So, alignment is 
conceived in terms of address bits, whatever those represent (not always bytes).
Not sure I quite follow. OK, so in an octet addressable world (which LLVM is - 
there have been some attempts to support non-octet addressing, but I don't 
think any have been near to successful) then DW_AT_alignment is byte alignment 
(1 means there are no zero bits in the address, 2 means there's 1 trailing zero 
bit in the address, etc).
If Clang is being infested with more target knowledge, okay, but that means 
tolerating the weirder targets in these cases.  Dividing by CHAR_BITS makes an 
assumption that isn't necessarily correct.
Clang has the knowledge already - it knows the alignment of the types its 
allocating, etc. So I'm not sure what infestation you're referring to.

I've sort of lost track of what we're discussing here.

Essentially what I'm suggesting is that Clang should put whatever number is 
going to go in the DWARF, into the metadata. I don't believe the LLVM backends 
have greater knowledge than the frontend does in this domain - have I missed 
something there, are there examples where that could/would be true?

- David

--paulr
P.S. The committee is hoping to get a draft out for public comment Real Soon 
Now.
Looking forward to it :)

From: cfe-commits 
[mailto:cfe-commits-boun...@lists.llvm.org]
 On Behalf Of David Blaikie via cfe-commits
Sent: Monday, September 12, 2016 5:12 PM
To: 
reviews+d24426+public+6ee6274d38fdf...@reviews.llvm.org;
 vlesc...@accesssoftek.com; 
echri...@gmail.com; 
apra...@apple.com; 
mehdi.am...@apple.com
Cc: cfe-commits@lists.llvm.org
Subject: Re: [PATCH] D24426: DebugInfo: Pass non-zero alignment to DIBuilder 
only if aligment was forced


On Mon, Sep 12, 2016 at 5:00 PM Paul Robinson 
> wrote:
probinson added a subscriber: probinson.


Comment at: lib/CodeGen/CGDebugInfo.cpp:3691
@@ -3635,1 +3690,3 @@
+  if (D->hasAttr())
+AlignInBits = D->getMaxAlignment();
   StringRef DeclName, LinkageName;

dblaikie wrote:
> is max alignment the right thing here? Should it be min alignment?
> (is alignment in bits the desired thing across all of this too? It looked 
> like in the backend patch there was some division by CHAR_BITS, etc?)
I should think bits is the right choice here; seems more the province of the 
backend to convert it into the appropriate addressable units (commonly but not 
universally chars).

The alternative thinking is that we've a generally sense we want to make more 
of this type information opaque to LLVM - so I'm somewhat inclined to make the 
frontend do the work of choosing what to emit and the backend just being as 
simple as possible.

Hmm, seems like the DWARF spec details I can find: 
http://www.dwarfstd.org/ShowIssue.php?issue=140528.1 don't really specify what 
the value of DW_AT_alignment is, it's sort of assumed, by the looks of it? I'm 
assuming it's bytes, the same as the byte_size attribute.





https://reviews.llvm.org/D24426

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


[PATCH] D24516: [Driver][Diagnostics] Make 'show option names' default for driver warnings

2016-09-13 Thread Bruno Cardoso Lopes via cfe-commits
bruno created this revision.
bruno added a reviewer: rsmith.
bruno added a subscriber: cfe-commits.

Currently, driver level warnings do not show option names (e.g. warning: 
complain about foo [-Woption-name]) in a diagnostic unless 
-fdiagnostics-show-option is explictly specified. OTOH, the driver by default 
turn this option on for CC1. Change the logic to show option names by default 
in the driver as well.

https://reviews.llvm.org/D24516

Files:
  include/clang/Frontend/CompilerInvocation.h
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/show-option-names.c

Index: test/Driver/show-option-names.c
===
--- /dev/null
+++ test/Driver/show-option-names.c
@@ -0,0 +1,4 @@
+// RUN: %clang -c -target i386-apple-darwin10 -isysroot /FOO %s 2>&1 | 
FileCheck --check-prefix=CHECK-SHOW-OPTION-NAMES %s
+// CHECK-SHOW-OPTION-NAMES: warning: no such sysroot directory: 
'{{([A-Za-z]:.*)?}}/FOO' [-Wmissing-sysroot]
+// RUN: %clang -c -target i386-apple-darwin10 -fno-diagnostics-show-option 
-isysroot /FOO %s 2>&1 | FileCheck --check-prefix=CHECK-NO-SHOW-OPTION-NAMES %s
+// CHECK-NO-SHOW-OPTION-NAMES-NOT: warning: no such sysroot directory: 
'{{([A-Za-z]:.*)?}}/FOO' [-Wmissing-sysroot]
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -941,7 +941,7 @@
 
 bool clang::ParseDiagnosticArgs(DiagnosticOptions , ArgList ,
 DiagnosticsEngine *Diags,
-bool DefaultDiagColor) {
+bool DefaultDiagColor, bool DefaultShowOpt) {
   using namespace options;
   bool Success = true;
 
@@ -961,7 +961,8 @@
   Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info);
   Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location);
   Opts.AbsolutePath = Args.hasArg(OPT_fdiagnostics_absolute_paths);
-  Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option);
+  Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option) ||
+  (DefaultShowOpt && !Args.hasArg(OPT_fno_diagnostics_show_option));
 
   llvm::sys::Process::UseANSIEscapeCodes(Args.hasArg(OPT_fansi_escape_codes));
 
@@ -2373,8 +2374,9 @@
   Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
   Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
   ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args);
-  Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, ,
- false /*DefaultDiagColor*/);
+  Success &=
+  ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, ,
+  false /*DefaultDiagColor*/, false 
/*DefaultShowOpt*/);
   ParseCommentArgs(LangOpts.CommentOpts, Args);
   ParseFileSystemArgs(Res.getFileSystemOpts(), Args);
   // FIXME: We shouldn't have to pass the DashX option around here
Index: include/clang/Frontend/CompilerInvocation.h
===
--- include/clang/Frontend/CompilerInvocation.h
+++ include/clang/Frontend/CompilerInvocation.h
@@ -48,7 +48,8 @@
 /// report the error(s).
 bool ParseDiagnosticArgs(DiagnosticOptions , llvm::opt::ArgList ,
  DiagnosticsEngine *Diags = nullptr,
- bool DefaultDiagColor = true);
+ bool DefaultDiagColor = true,
+ bool DefaultShowOpt = true);
 
 class CompilerInvocationBase : public RefCountedBase {
   void operator=(const CompilerInvocationBase &) = delete;


Index: test/Driver/show-option-names.c
===
--- /dev/null
+++ test/Driver/show-option-names.c
@@ -0,0 +1,4 @@
+// RUN: %clang -c -target i386-apple-darwin10 -isysroot /FOO %s 2>&1 | FileCheck --check-prefix=CHECK-SHOW-OPTION-NAMES %s
+// CHECK-SHOW-OPTION-NAMES: warning: no such sysroot directory: '{{([A-Za-z]:.*)?}}/FOO' [-Wmissing-sysroot]
+// RUN: %clang -c -target i386-apple-darwin10 -fno-diagnostics-show-option -isysroot /FOO %s 2>&1 | FileCheck --check-prefix=CHECK-NO-SHOW-OPTION-NAMES %s
+// CHECK-NO-SHOW-OPTION-NAMES-NOT: warning: no such sysroot directory: '{{([A-Za-z]:.*)?}}/FOO' [-Wmissing-sysroot]
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -941,7 +941,7 @@
 
 bool clang::ParseDiagnosticArgs(DiagnosticOptions , ArgList ,
 DiagnosticsEngine *Diags,
-bool DefaultDiagColor) {
+bool DefaultDiagColor, bool DefaultShowOpt) {
   using namespace options;
   bool Success = true;
 
@@ -961,7 +961,8 @@
   Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info);
   Opts.ShowLocation = 

Re: [PATCH] D24484: [analyzer] Fix ExprEngine::VisitMemberExpr

2016-09-13 Thread Alexander Shaposhnikov via cfe-commits
alexshap added a comment.

Thx,
I do.


Repository:
  rL LLVM

https://reviews.llvm.org/D24484



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


Re: [PATCH] D24484: [analyzer] Fix ExprEngine::VisitMemberExpr

2016-09-13 Thread Anna Zaks via cfe-commits
zaks.anna accepted this revision.
zaks.anna added a comment.
This revision is now accepted and ready to land.

Thanks!

Do you have commit access?


Repository:
  rL LLVM

https://reviews.llvm.org/D24484



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


Re: [PATCH] D23080: ObjC: Use a new type for ObjC type parameter (patch 3 out of 3)

2016-09-13 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281358: ObjectiveC Generics: Start using ObjCTypeParamType. 
(authored by mren).

Changed prior to commit:
  https://reviews.llvm.org/D23080?vs=69765=71205#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23080

Files:
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/AST/DeclObjC.cpp
  cfe/trunk/lib/AST/Type.cpp
  cfe/trunk/lib/Sema/SemaDeclObjC.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  cfe/trunk/test/SemaObjC/kindof.m
  cfe/trunk/test/SemaObjC/parameterized_classes_subst.m

Index: cfe/trunk/test/SemaObjC/parameterized_classes_subst.m
===
--- cfe/trunk/test/SemaObjC/parameterized_classes_subst.m
+++ cfe/trunk/test/SemaObjC/parameterized_classes_subst.m
@@ -426,3 +426,36 @@
 // warning about likely protocol/class name typos.
 // --
 typedef NSArray ArrayOfNSObjectWarning; // expected-warning{{parameterized class 'NSArray' already conforms to the protocols listed; did you forget a '*'?}}
+
+// rdar://25060179
+@interface MyMutableDictionary : NSObject
+- (void)setObject:(ObjectType)obj forKeyedSubscript:(KeyType )key; // expected-note{{passing argument to parameter 'obj' here}} \
+// expected-note{{passing argument to parameter 'key' here}}
+@end
+
+void bar(MyMutableDictionary *stringsByString,
+ NSNumber *n1, NSNumber *n2) {
+  // We warn here when the key types do not match.
+  stringsByString[n1] = n2; // expected-warning{{incompatible pointer types sending 'NSNumber *' to parameter of type 'NSString *'}} \
+// expected-warning{{incompatible pointer types sending 'NSNumber *' to parameter of type 'NSString *'}}
+}
+
+@interface MyTest : NSObject 
+- (V)test:(K)key;
+- (V)test2:(K)key; // expected-note{{previous definition is here}}
+- (void)mapUsingBlock:(id (^)(V))block;
+- (void)mapUsingBlock2:(id (^)(V))block; // expected-note{{previous definition is here}}
+@end
+
+@implementation MyTest
+- (id)test:(id)key {
+  return key;
+}
+- (int)test2:(id)key{ // expected-warning{{conflicting return type in implementation}}
+  return 0;
+}
+- (void)mapUsingBlock:(id (^)(id))block {
+}
+- (void)mapUsingBlock2:(id)block { // expected-warning{{conflicting parameter types in implementation}}
+}
+@end
Index: cfe/trunk/test/SemaObjC/kindof.m
===
--- cfe/trunk/test/SemaObjC/kindof.m
+++ cfe/trunk/test/SemaObjC/kindof.m
@@ -385,7 +385,7 @@
 @end
 
 @interface NSGeneric : NSObject
-- (void)test:(__kindof ObjectType)T;
+- (void)test:(__kindof ObjectType)T; // expected-note{{passing argument to parameter 'T' here}}
 - (void)mapUsingBlock:(id (^)(__kindof ObjectType))block;
 @end
 @implementation NSGeneric
@@ -395,6 +395,14 @@
 }
 @end
 
+void testGeneric(NSGeneric *generic) {
+  NSObject *NSObject_obj;
+  // Assign from NSObject_obj to __kindof NSString*.
+  [generic test:NSObject_obj]; // expected-warning{{incompatible pointer types sending 'NSObject *' to parameter of type '__kindof NSString *'}}
+  NSString *NSString_str;
+  [generic test:NSString_str];
+}
+
 // Check that clang doesn't crash when a type parameter is illegal.
 @interface Array1 : NSObject
 @end
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
@@ -626,7 +626,7 @@
   : public RecursiveASTVisitor {
   public:
 IsObjCTypeParamDependentTypeVisitor() : Result(false) {}
-bool VisitTypedefType(const TypedefType *Type) {
+bool VisitObjCTypeParamType(const ObjCTypeParamType *Type) {
   if (isa(Type->getDecl())) {
 Result = true;
 return false;
Index: cfe/trunk/lib/AST/Type.cpp
===
--- cfe/trunk/lib/AST/Type.cpp
+++ cfe/trunk/lib/AST/Type.cpp
@@ -1081,13 +1081,24 @@
 
 // Replace an Objective-C type parameter reference with the corresponding
 // type argument.
-if (const auto *typedefTy = dyn_cast(splitType.Ty)) {
-  if (auto *typeParam = dyn_cast(typedefTy->getDecl())) {
+if (const auto *OTPTy = dyn_cast(splitType.Ty)) {
+  if (auto *typeParam = dyn_cast(OTPTy->getDecl())) {
 // If we have type arguments, use them.
 if (!typeArgs.empty()) {
-  // FIXME: Introduce SubstObjCTypeParamType ?
   QualType argType = typeArgs[typeParam->getIndex()];
-  return ctx.getQualifiedType(argType, splitType.Quals);
+  if (OTPTy->qual_empty())
+return ctx.getQualifiedType(argType, splitType.Quals);
+
+  // Apply protocol lists if 

r281358 - ObjectiveC Generics: Start using ObjCTypeParamType.

2016-09-13 Thread Manman Ren via cfe-commits
Author: mren
Date: Tue Sep 13 12:41:05 2016
New Revision: 281358

URL: http://llvm.org/viewvc/llvm-project?rev=281358=rev
Log:
ObjectiveC Generics: Start using ObjCTypeParamType.

For ObjC type parameter, we used to have TypedefType that is canonicalized to
id or the bound type. We can't represent "T " and thus will lose
the type information in the following example:
@interface MyMutableDictionary : NSObject
- (void)setObject:(ObjectType)obj forKeyedSubscript:(KeyType )key;
@end
MyMutableDictionary *stringsByString;
NSNumber *n1, *n2;
stringsByString[n1] = n2;
--> no warning on type mismatch of the key.

To fix the problem, we introduce a new type ObjCTypeParamType that supports
a list of protocol qualifiers.

We create ObjCTypeParamType for ObjCTypeParamDecl when we create
ObjCTypeParamDecl. We also substitute ObjCTypeParamType instead of TypedefType
on an ObjCTypeParamDecl.

rdar://24619481
rdar://25060179

Differential Revision: http://reviews.llvm.org/D23080

Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
cfe/trunk/test/SemaObjC/kindof.m
cfe/trunk/test/SemaObjC/parameterized_classes_subst.m

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=281358=281357=281358=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Sep 13 12:41:05 2016
@@ -3883,6 +3883,11 @@ ASTContext::applyObjCProtocolQualifiers(
   bool allowOnPointerType) const {
   hasError = false;
 
+  if (const ObjCTypeParamType *objT =
+  dyn_cast(type.getTypePtr())) {
+return getObjCTypeParamType(objT->getDecl(), protocols);
+  }
+
   // Apply protocol qualifiers to ObjCObjectPointerType.
   if (allowOnPointerType) {
 if (const ObjCObjectPointerType *objPtr =

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=281358=281357=281358=diff
==
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Tue Sep 13 12:41:05 2016
@@ -1320,8 +1320,12 @@ ObjCTypeParamDecl *ObjCTypeParamDecl::Cr
  IdentifierInfo *name,
  SourceLocation colonLoc,
  TypeSourceInfo *boundInfo) {
-  return new (ctx, dc) ObjCTypeParamDecl(ctx, dc, variance, varianceLoc, index,
- nameLoc, name, colonLoc, boundInfo);
+  auto *TPDecl =
+new (ctx, dc) ObjCTypeParamDecl(ctx, dc, variance, varianceLoc, index,
+nameLoc, name, colonLoc, boundInfo);
+  QualType TPType = ctx.getObjCTypeParamType(TPDecl, {});
+  TPDecl->setTypeForDecl(TPType.getTypePtr());
+  return TPDecl;
 }
 
 ObjCTypeParamDecl *ObjCTypeParamDecl::CreateDeserialized(ASTContext ,

Modified: cfe/trunk/lib/AST/Type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=281358=281357=281358=diff
==
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Tue Sep 13 12:41:05 2016
@@ -1081,13 +1081,24 @@ QualType QualType::substObjCTypeArgs(
 
 // Replace an Objective-C type parameter reference with the corresponding
 // type argument.
-if (const auto *typedefTy = dyn_cast(splitType.Ty)) {
-  if (auto *typeParam = dyn_cast(typedefTy->getDecl())) 
{
+if (const auto *OTPTy = dyn_cast(splitType.Ty)) {
+  if (auto *typeParam = dyn_cast(OTPTy->getDecl())) {
 // If we have type arguments, use them.
 if (!typeArgs.empty()) {
-  // FIXME: Introduce SubstObjCTypeParamType ?
   QualType argType = typeArgs[typeParam->getIndex()];
-  return ctx.getQualifiedType(argType, splitType.Quals);
+  if (OTPTy->qual_empty())
+return ctx.getQualifiedType(argType, splitType.Quals);
+
+  // Apply protocol lists if exists.
+  bool hasError;
+  SmallVector protocolsVec;
+  protocolsVec.append(OTPTy->qual_begin(),
+  OTPTy->qual_end());
+  ArrayRef protocolsToApply = protocolsVec;
+  QualType resultTy = ctx.applyObjCProtocolQualifiers(argType,
+  protocolsToApply, hasError, true/*allowOnPointerType*/);
+
+  return ctx.getQualifiedType(resultTy, splitType.Quals);
 }
 
 switch (context) {

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: 

Re: [PATCH] D24512: AMDGPU: Fix target options fp32/64-denormals

2016-09-13 Thread Yaxun Liu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281357: AMDGPU: Fix target options fp32/64-denormals 
(authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D24512?vs=71183=71201#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24512

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl

Index: cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl
===
--- cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl
+++ cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl
@@ -1,13 +1,19 @@
 // RUN: %clang_cc1 -S -cl-denorms-are-zero -o - %s 2>&1
 // RUN: %clang_cc1 -emit-llvm -cl-denorms-are-zero -o - -triple amdgcn--amdhsa 
-target-cpu fiji %s | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn--amdhsa -target-cpu fiji %s 
| FileCheck %s --check-prefix=CHECK-DENORM
+// RUN: %clang_cc1 -emit-llvm -target-feature +fp32-denormals -target-feature 
-fp64-denormals -cl-denorms-are-zero -o - -triple amdgcn--amdhsa -target-cpu 
fiji %s | FileCheck --check-prefix=CHECK-FEATURE %s
 
 // For non-amdgcn targets, this test just checks that the -cl-denorms-are-zero 
argument is accepted
 // by clang.  This option is currently a no-op, which is allowed by the
 // OpenCL specification.
 
+// For amdgcn target cpu fiji, fp32 should be flushed since fiji does not 
support fp32 denormals, unless +fp32-denormals is
+// explicitly set. amdgcn target always do not flush fp64 denormals.
+
 // CHECK-DENORM-LABEL: define void @f()
-// CHECK-DENORM: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp32-denormals,+fp64-denormals{{[^"]*}}"
+// CHECK-DENORM: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp64-denormals,{{[^"]*}}-fp32-denormals{{[^"]*}}"
 // CHECK-LABEL: define void @f()
-// CHECK-NOT: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp32-denormals,+fp64-denormals{{[^"]*}}"
+// CHECK: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp64-denormals,{{[^"]*}}-fp32-denormals{{[^"]*}}"
+// CHECK-FEATURE-LABEL: define void @f()
+// CHECK-FEATURE: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp32-denormals,{{[^"]*}}-fp64-denormals{{[^"]*}}"
 void f() {}
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -1965,7 +1965,7 @@
   bool hasFP64:1;
   bool hasFMAF:1;
   bool hasLDEXPF:1;
-  bool hasDenormSupport:1;
+  bool hasFullSpeedFP32Denorms:1;
 
   static bool isAMDGCN(const llvm::Triple ) {
 return TT.getArch() == llvm::Triple::amdgcn;
@@ -1978,14 +1978,12 @@
   hasFP64(false),
   hasFMAF(false),
   hasLDEXPF(false),
-  hasDenormSupport(false){
+  hasFullSpeedFP32Denorms(false){
 if (getTriple().getArch() == llvm::Triple::amdgcn) {
   hasFP64 = true;
   hasFMAF = true;
   hasLDEXPF = true;
 }
-if (Opts.CPU == "fiji")
-  hasDenormSupport = true;
 
 resetDataLayout(getTriple().getArch() == llvm::Triple::amdgcn ?
 DataLayoutStringSI : DataLayoutStringR600);
@@ -2040,8 +2038,6 @@
 
   void adjustTargetOptions(const CodeGenOptions ,
TargetOptions ) const override {
-if (!hasDenormSupport)
-  return;
 bool hasFP32Denormals = false;
 bool hasFP64Denormals = false;
 for (auto  : TargetOpts.FeaturesAsWritten) {
@@ -2051,11 +2047,11 @@
 hasFP64Denormals = true;
 }
 if (!hasFP32Denormals)
-  TargetOpts.Features.push_back((Twine(CGOpts.FlushDenorm ? '-' : '+') +
- Twine("fp32-denormals")).str());
+  TargetOpts.Features.push_back((Twine(hasFullSpeedFP32Denorms &&
+  !CGOpts.FlushDenorm ? '+' : '-') + Twine("fp32-denormals")).str());
+// Always do not flush fp64 denorms.
 if (!hasFP64Denormals && hasFP64)
-  TargetOpts.Features.push_back((Twine(CGOpts.FlushDenorm ? '-' : '+') +
- Twine("fp64-denormals")).str());
+  TargetOpts.Features.push_back("+fp64-denormals");
   }
 
   ArrayRef getTargetBuiltins() const override {


Index: cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl
===
--- cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl
+++ cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl
@@ -1,13 +1,19 @@
 // RUN: %clang_cc1 -S -cl-denorms-are-zero -o - %s 2>&1
 // RUN: %clang_cc1 -emit-llvm -cl-denorms-are-zero -o - -triple amdgcn--amdhsa -target-cpu fiji %s | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn--amdhsa -target-cpu fiji %s | FileCheck %s --check-prefix=CHECK-DENORM
+// RUN: %clang_cc1 -emit-llvm -target-feature +fp32-denormals -target-feature -fp64-denormals -cl-denorms-are-zero -o - -triple amdgcn--amdhsa -target-cpu fiji %s | 

r281357 - AMDGPU: Fix target options fp32/64-denormals

2016-09-13 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Tue Sep 13 12:37:09 2016
New Revision: 281357

URL: http://llvm.org/viewvc/llvm-project?rev=281357=rev
Log:
AMDGPU: Fix target options fp32/64-denormals

Fix target options for fp32/64-denormals so that

+fp64-denormals is set if fp64 is supported
-fp32-denormals if fp32 denormals is not supported, or -cl-denorms-are-zero is 
set
+fp32-denormals if fp32 denormals is supported and -cl-denorms-are-zero is not 
set

If target feature fp32/64-denormals is explicitly set, they will override 
default options and options deduced from -cl-denorms-are-zero.

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

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=281357=281356=281357=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Sep 13 12:37:09 2016
@@ -1965,7 +1965,7 @@ class AMDGPUTargetInfo final : public Ta
   bool hasFP64:1;
   bool hasFMAF:1;
   bool hasLDEXPF:1;
-  bool hasDenormSupport:1;
+  bool hasFullSpeedFP32Denorms:1;
 
   static bool isAMDGCN(const llvm::Triple ) {
 return TT.getArch() == llvm::Triple::amdgcn;
@@ -1978,14 +1978,12 @@ public:
   hasFP64(false),
   hasFMAF(false),
   hasLDEXPF(false),
-  hasDenormSupport(false){
+  hasFullSpeedFP32Denorms(false){
 if (getTriple().getArch() == llvm::Triple::amdgcn) {
   hasFP64 = true;
   hasFMAF = true;
   hasLDEXPF = true;
 }
-if (Opts.CPU == "fiji")
-  hasDenormSupport = true;
 
 resetDataLayout(getTriple().getArch() == llvm::Triple::amdgcn ?
 DataLayoutStringSI : DataLayoutStringR600);
@@ -2040,8 +2038,6 @@ public:
 
   void adjustTargetOptions(const CodeGenOptions ,
TargetOptions ) const override {
-if (!hasDenormSupport)
-  return;
 bool hasFP32Denormals = false;
 bool hasFP64Denormals = false;
 for (auto  : TargetOpts.FeaturesAsWritten) {
@@ -2051,11 +2047,11 @@ public:
 hasFP64Denormals = true;
 }
 if (!hasFP32Denormals)
-  TargetOpts.Features.push_back((Twine(CGOpts.FlushDenorm ? '-' : '+') +
- Twine("fp32-denormals")).str());
+  TargetOpts.Features.push_back((Twine(hasFullSpeedFP32Denorms &&
+  !CGOpts.FlushDenorm ? '+' : '-') + Twine("fp32-denormals")).str());
+// Always do not flush fp64 denorms.
 if (!hasFP64Denormals && hasFP64)
-  TargetOpts.Features.push_back((Twine(CGOpts.FlushDenorm ? '-' : '+') +
- Twine("fp64-denormals")).str());
+  TargetOpts.Features.push_back("+fp64-denormals");
   }
 
   ArrayRef getTargetBuiltins() const override {

Modified: cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl?rev=281357=281356=281357=diff
==
--- cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/denorms-are-zero.cl Tue Sep 13 12:37:09 2016
@@ -1,13 +1,19 @@
 // RUN: %clang_cc1 -S -cl-denorms-are-zero -o - %s 2>&1
 // RUN: %clang_cc1 -emit-llvm -cl-denorms-are-zero -o - -triple amdgcn--amdhsa 
-target-cpu fiji %s | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn--amdhsa -target-cpu fiji %s 
| FileCheck %s --check-prefix=CHECK-DENORM
+// RUN: %clang_cc1 -emit-llvm -target-feature +fp32-denormals -target-feature 
-fp64-denormals -cl-denorms-are-zero -o - -triple amdgcn--amdhsa -target-cpu 
fiji %s | FileCheck --check-prefix=CHECK-FEATURE %s
 
 // For non-amdgcn targets, this test just checks that the -cl-denorms-are-zero 
argument is accepted
 // by clang.  This option is currently a no-op, which is allowed by the
 // OpenCL specification.
 
+// For amdgcn target cpu fiji, fp32 should be flushed since fiji does not 
support fp32 denormals, unless +fp32-denormals is
+// explicitly set. amdgcn target always do not flush fp64 denormals.
+
 // CHECK-DENORM-LABEL: define void @f()
-// CHECK-DENORM: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp32-denormals,+fp64-denormals{{[^"]*}}"
+// CHECK-DENORM: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp64-denormals,{{[^"]*}}-fp32-denormals{{[^"]*}}"
 // CHECK-LABEL: define void @f()
-// CHECK-NOT: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp32-denormals,+fp64-denormals{{[^"]*}}"
+// CHECK: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp64-denormals,{{[^"]*}}-fp32-denormals{{[^"]*}}"
+// CHECK-FEATURE-LABEL: define void @f()
+// CHECK-FEATURE: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp32-denormals,{{[^"]*}}-fp64-denormals{{[^"]*}}"
 

Re: [PATCH] D23820: Do not warn about format strings that are indexed string literals.

2016-09-13 Thread Meike Baumgärtner via cfe-commits
meikeb added a comment.

I explained why I chose the names that you commented on. Feel free to add your 
thoughts if you still think another name would be more fitting.



Comment at: lib/Sema/SemaChecking.cpp:3842
@@ -3841,2 +3841,3 @@
 
-static void CheckFormatString(Sema , const StringLiteral *FExpr,
+static void sumUpStringLiteralOffset(llvm::APSInt , llvm::APSInt Addend,
+ BinaryOperatorKind BinOpKind,

srhines wrote:
> Is "computeStringLiteralOffset" or "calculate..." a better name here?
I thought about that but decided to go with sumUp because compute or calculate 
sounds like this function would do what we actually do what the caller of this 
function does (computing the offset). This is just a nice helper to sum up the 
offset we already have with another piece of offset.


Comment at: lib/Sema/SemaChecking.cpp:3844
@@ +3843,3 @@
+ BinaryOperatorKind BinOpKind,
+ bool AddendIsRight) {
+  unsigned BitWidth = Offset.getBitWidth();

srhines wrote:
> Is "Operand" better than "Addend"? In particular, there is the possibility 
> that we do subtraction of the value instead of addition, so "Addend" makes it 
> a bit confusing. Of course, I then would expect "OperandIsRight" instead of 
> "AddendIsRight" too.
Clang summarizes sub and add as "additive" operands. This is why I think this 
is fitting. Operand is misleading because it includes a lot more operands than 
add and sub imo.


Comment at: lib/Sema/SemaChecking.cpp:3860
@@ +3859,3 @@
+
+  bool Ov = false;
+  llvm::APSInt ResOffset = Offset;

srhines wrote:
> Ov -> Overflow
I named that in compliance with clang naming. E.g. sadd_ov. It is common in 
this file to abbreviate variable names with 1-3 characters.


https://reviews.llvm.org/D23820



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


Re: r281277 - [Sema] Fix PR30346: relax __builtin_object_size checks.

2016-09-13 Thread Joerg Sonnenberger via cfe-commits
On Mon, Sep 12, 2016 at 11:50:36PM -, George Burgess IV via cfe-commits 
wrote:
> Author: gbiv
> Date: Mon Sep 12 18:50:35 2016
> New Revision: 281277
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=281277=rev
> Log:
> [Sema] Fix PR30346: relax __builtin_object_size checks.
> 
> This patch makes us act more conservatively when trying to determine
> the objectsize for an array at the end of an object. This is in
> response to code like the following:
> 
> ```
> struct sockaddr {
>   /* snip */
>   char sa_data[14];
> };
> 
> void foo(const char *s) {
>   size_t slen = strlen(s) + 1;
>   size_t added_len = slen <= 14 ? 0 : slen - 14;
>   struct sockaddr *sa = malloc(sizeof(struct sockaddr) + added_len);
>   strcpy(sa->sa_data, s);
>   // ...
> }
> ```
> 
> `__builtin_object_size(sa->sa_data, 1)` would return 14, when there
> could be more than 14 bytes at `sa->sa_data`.
> 
> Code like this is apparently not uncommon. FreeBSD's manual even
> explicitly mentions this pattern:
> https://www.freebsd.org/doc/en/books/developers-handbook/sockets-essential-functions.html
> (section 7.5.1.1.2).
> 
> In light of this, we now just give up on any array at the end of an
> object if we can't find the object's initial allocation.
> 
> I lack numbers for how much more conservative we actually become as a
> result of this change, so I chose the fix that would make us as
> compatible with GCC as possible. If we want to be more aggressive, I'm
> happy to consider some kind of whitelist or something instead.

IMO this should be restricted to code that explicitly disables C/C++
aliasing rules.

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


Re: [PATCH] D23820: Do not warn about format strings that are indexed string literals.

2016-09-13 Thread Meike Baumgärtner via cfe-commits
meikeb updated this revision to Diff 71199.
meikeb marked 7 inline comments as done.
meikeb added a comment.

Fix typos and add assert to sum up offset helper.


https://reviews.llvm.org/D23820

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/format-strings.c

Index: test/Sema/format-strings.c
===
--- test/Sema/format-strings.c
+++ test/Sema/format-strings.c
@@ -652,3 +652,38 @@
   // expected-note@-1{{treat the string as an argument to avoid this}}
 }
 #pragma GCC diagnostic warning "-Wformat-nonliteral"
+
+void test_char_pointer_arithmetic(int b) {
+  const char s1[] = "string";
+  const char s2[] = "%s string";
+
+  printf(s1 - 1);  // expected-warning {{format string is not a string literal (potentially insecure)}}
+  // expected-note@-1{{treat the string as an argument to avoid this}}
+
+  printf(s1 + 2);  // no-warning
+  printf(s2 + 2);  // no-warning
+
+  const char s3[] = "%s string";
+  printf((s3 + 2) - 2);  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + s2); // no-warning
+  printf(6 + s2 - 2); // no-warning
+  printf(2 + (b ? s1 : s2));  // no-warning
+
+  const char s5[] = "string %s";
+  printf(2 + (b ? s2 : s5));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + (b ? s2 : s5), "");  // no-warning
+  printf(2 + (b ? s1 : s2 - 2), "");  // no-warning
+
+  const char s6[] = "%s string";
+  printf(2 + (b ? s1 : s6 - 2));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(1 ? s2 + 2 : s2);  // no-warning
+  printf(0 ? s2 : s2 + 2);  // no-warning
+  printf(2 + s2 + 5 * 3 - 16, "");  // expected-warning{{data argument not used}}
+
+  const char s7[] = "%s string %s %s";
+  printf(s7 + 3, "");  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -3839,7 +3839,94 @@
 };
 } // end anonymous namespace
 
-static void CheckFormatString(Sema , const StringLiteral *FExpr,
+static void sumUpStringLiteralOffset(llvm::APSInt , llvm::APSInt Addend,
+ BinaryOperatorKind BinOpKind,
+ bool AddendIsRight) {
+  unsigned BitWidth = Offset.getBitWidth();
+  unsigned AddendBitWidth = Addend.getBitWidth();
+  // There might be negative interim results.
+  if (Addend.isUnsigned()) {
+Addend = Addend.zext(++AddendBitWidth);
+Addend.setIsSigned(true);
+  }
+  // Adjust the bit width of the APSInts.
+  if (AddendBitWidth > BitWidth) {
+Offset = Offset.sext(AddendBitWidth);
+BitWidth = AddendBitWidth;
+  } else if (BitWidth > AddendBitWidth) {
+Addend = Addend.sext(BitWidth);
+  }
+
+  bool Ov = false;
+  llvm::APSInt ResOffset = Offset;
+  if (BinOpKind == BO_Add)
+ResOffset = Offset.sadd_ov(Addend, Ov);
+  else if (AddendIsRight && BinOpKind == BO_Sub)
+ResOffset = Offset.ssub_ov(Addend, Ov);
+  else
+assert(false && "operator must be add or sub with addend on the right");
+
+  // We add an offset to a pointer here so we should support an offset as big as
+  // possible.
+  if (Ov) {
+assert(BitWidth <= UINT_MAX / 2 && "index (intermediate) result too big");
+Offset.sext(2 * BitWidth);
+sumUpStringLiteralOffset(Offset, Addend, BinOpKind, AddendIsRight);
+return;
+  }
+
+  Offset = ResOffset;
+}
+
+namespace {
+// This is a wrapper class around StringLiteral to support offsetted string
+// literals as format strings. It takes the offset into account when returning
+// the string and its length or the source locations to display notes correctly.
+class FormatStringLiteral {
+  const StringLiteral *FExpr;
+  int64_t Offset;
+
+ public:
+  FormatStringLiteral(const StringLiteral *fexpr, int64_t Offset = 0)
+  : FExpr(fexpr), Offset(Offset) {}
+
+  StringRef getString() const {
+return FExpr->getString().drop_front(Offset);
+  }
+
+  unsigned getByteLength() const {
+return FExpr->getByteLength() - getCharByteWidth() * Offset;
+  }
+  unsigned getLength() const { return FExpr->getLength() - Offset; }
+  unsigned getCharByteWidth() const { return FExpr->getCharByteWidth(); }
+
+  StringLiteral::StringKind getKind() const { return FExpr->getKind(); }
+
+  QualType getType() const { return FExpr->getType(); }
+
+  bool isAscii() const { return FExpr->isAscii(); }
+  bool isWide() const { return FExpr->isWide(); }
+  bool isUTF8() const { return FExpr->isUTF8(); }
+  bool isUTF16() const { return FExpr->isUTF16(); }
+  bool isUTF32() const { return FExpr->isUTF32(); }
+  bool isPascal() const { return FExpr->isPascal(); }
+
+  

Re: [PATCH] D24448: [atomics] New warning -Watomic-libcall when atomic operation expands to a library call

2016-09-13 Thread Joerg Sonnenberger via cfe-commits
joerg added a comment.

More precisely, this should re-use the logic from __atomic_is_lock_free and not 
reinvent it.


https://reviews.llvm.org/D24448



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


Re: [PATCH] D24448: [atomics] New warning -Watomic-libcall when atomic operation expands to a library call

2016-09-13 Thread Joerg Sonnenberger via cfe-commits
joerg added a subscriber: joerg.
joerg added a comment.

While I agree with the general sentiment, the check doesn't work at all. For 
example, ARMv4 always has to use libcalls. It's not even true that libcalls are 
slow, i.e. on true non-parallel architectures, the libcall can be as simple as 
a restartable atomic sequence and is almost cost free beyond the function call 
overhead.


https://reviews.llvm.org/D24448



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


Re: [PATCH] D23079: ObjC: Use a new type for ObjC type parameter (patch 2 out of 3)

2016-09-13 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281355: ObjectiveC generics: Add ObjCTypeParamType in the 
type system. (authored by mren).

Changed prior to commit:
  https://reviews.llvm.org/D23079?vs=69764=71197#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23079

Files:
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/AST/TypeLoc.h
  cfe/trunk/include/clang/AST/TypeNodes.def
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/include/clang/Serialization/ASTBitCodes.h
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/lib/AST/ItaniumMangle.cpp
  cfe/trunk/lib/AST/Type.cpp
  cfe/trunk/lib/AST/TypeLoc.cpp
  cfe/trunk/lib/AST/TypePrinter.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.h
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/lib/Sema/TreeTransform.h
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/lib/Serialization/ASTWriter.cpp
  cfe/trunk/tools/libclang/CIndex.cpp

Index: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
===
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h
@@ -902,7 +902,9 @@
   /// \brief An AdjustedType record.
   TYPE_ADJUSTED  = 42,
   /// \brief A PipeType record.
-  TYPE_PIPE  = 43
+  TYPE_PIPE  = 43,
+  /// \brief An ObjCTypeParamType record.
+  TYPE_OBJC_TYPE_PARAM   = 44
 };
 
 /// \brief The type IDs for special types constructed by semantic
Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
===
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
@@ -1044,6 +1044,8 @@
 
 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
 
+DEF_TRAVERSE_TYPE(ObjCTypeParamType, {})
+
 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
 
 DEF_TRAVERSE_TYPE(ObjCObjectType, {
@@ -1275,6 +1277,8 @@
 DEF_TRAVERSE_TYPELOC(PackExpansionType,
  { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
 
+DEF_TRAVERSE_TYPELOC(ObjCTypeParamType, {})
+
 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
 
 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -114,6 +114,7 @@
   mutable llvm::FoldingSet DependentTypeOfExprTypes;
   mutable llvm::FoldingSet DependentDecltypeTypes;
   mutable llvm::FoldingSet TemplateTypeParmTypes;
+  mutable llvm::FoldingSet ObjCTypeParamTypes;
   mutable llvm::FoldingSet
 SubstTemplateTypeParmTypes;
   mutable llvm::FoldingSet
@@ -1328,6 +1329,10 @@
  ArrayRef typeArgs,
  ArrayRef protocols,
  bool isKindOf) const;
+
+  QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl,
+ArrayRef protocols,
+QualType Canonical = QualType()) const;
   
   bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl);
   /// QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in
Index: cfe/trunk/include/clang/AST/TypeNodes.def
===
--- cfe/trunk/include/clang/AST/TypeNodes.def
+++ cfe/trunk/include/clang/AST/TypeNodes.def
@@ -101,6 +101,7 @@
 DEPENDENT_TYPE(DependentName, Type)
 DEPENDENT_TYPE(DependentTemplateSpecialization, Type)
 NON_CANONICAL_UNLESS_DEPENDENT_TYPE(PackExpansion, Type)
+NON_CANONICAL_TYPE(ObjCTypeParam, Type)
 TYPE(ObjCObject, Type)
 TYPE(ObjCInterface, ObjCObjectType)
 TYPE(ObjCObjectPointer, Type)
Index: cfe/trunk/include/clang/AST/Type.h
===
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -88,6 +88,7 @@
   class ObjCInterfaceDecl;
   class ObjCProtocolDecl;
   class ObjCMethodDecl;
+  class ObjCTypeParamDecl;
   class UnresolvedUsingTypenameDecl;
   class Expr;
   class Stmt;
@@ -4752,6 +4753,49 @@
   }
 };
 
+/// Represents a type parameter type in Objective C. It can take
+/// a list of protocols.
+class ObjCTypeParamType : public Type,
+  public ObjCProtocolQualifiers,
+  public llvm::FoldingSetNode {
+  friend class ASTContext;
+  friend class ObjCProtocolQualifiers;
+
+  /// The number of protocols stored on this type.
+  unsigned NumProtocols : 6;
+
+  ObjCTypeParamDecl *OTPDecl;
+  /// The protocols are stored after the 

r281355 - ObjectiveC generics: Add ObjCTypeParamType in the type system.

2016-09-13 Thread Manman Ren via cfe-commits
Author: mren
Date: Tue Sep 13 12:25:08 2016
New Revision: 281355

URL: http://llvm.org/viewvc/llvm-project?rev=281355=rev
Log:
ObjectiveC generics: Add ObjCTypeParamType in the type system.

We also need to add ObjCTypeParamTypeLoc. ObjCTypeParamType supports the
representation of "T " where T is a type parameter. Before this,
we use TypedefType to represent the type parameter for ObjC.

ObjCTypeParamType has "ObjCTypeParamDecl *OTPDecl" and it extends from
ObjCProtocolQualifiers. It is a non-canonical type and is canonicalized
to the underlying type with the protocol qualifiers.

rdar://24619481
rdar://25060179

Differential Revision: http://reviews.llvm.org/D23079

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/AST/TypeNodes.def
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=281355=281354=281355=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Sep 13 12:25:08 2016
@@ -114,6 +114,7 @@ class ASTContext : public RefCountedBase
   mutable llvm::FoldingSet DependentTypeOfExprTypes;
   mutable llvm::FoldingSet DependentDecltypeTypes;
   mutable llvm::FoldingSet TemplateTypeParmTypes;
+  mutable llvm::FoldingSet ObjCTypeParamTypes;
   mutable llvm::FoldingSet
 SubstTemplateTypeParmTypes;
   mutable llvm::FoldingSet
@@ -1328,6 +1329,10 @@ public:
  ArrayRef typeArgs,
  ArrayRef protocols,
  bool isKindOf) const;
+
+  QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl,
+ArrayRef protocols,
+QualType Canonical = QualType()) const;
   
   bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl);
   /// QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=281355=281354=281355=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue Sep 13 12:25:08 2016
@@ -1044,6 +1044,8 @@ DEF_TRAVERSE_TYPE(DependentTemplateSpeci
 
 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); 
})
 
+DEF_TRAVERSE_TYPE(ObjCTypeParamType, {})
+
 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
 
 DEF_TRAVERSE_TYPE(ObjCObjectType, {
@@ -1275,6 +1277,8 @@ DEF_TRAVERSE_TYPELOC(DependentTemplateSp
 DEF_TRAVERSE_TYPELOC(PackExpansionType,
  { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
 
+DEF_TRAVERSE_TYPELOC(ObjCTypeParamType, {})
+
 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
 
 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=281355=281354=281355=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Sep 13 12:25:08 2016
@@ -88,6 +88,7 @@ namespace clang {
   class ObjCInterfaceDecl;
   class ObjCProtocolDecl;
   class ObjCMethodDecl;
+  class ObjCTypeParamDecl;
   class UnresolvedUsingTypenameDecl;
   class Expr;
   class Stmt;
@@ -4752,6 +4753,49 @@ public:
   }
 };
 
+/// Represents a type parameter type in Objective C. It can take
+/// a list of protocols.
+class ObjCTypeParamType : public Type,
+  public ObjCProtocolQualifiers,
+  public llvm::FoldingSetNode {
+  friend class ASTContext;
+  friend class ObjCProtocolQualifiers;
+
+  /// The number of protocols stored on this type.
+  unsigned NumProtocols : 6;
+
+  ObjCTypeParamDecl *OTPDecl;
+  /// The protocols are stored after the ObjCTypeParamType node. In the
+  /// canonical type, the list of protocols are 

Re: [PATCH] D24059: NFC: refactor applyObjCProtocolQualifiers from SemaType.cpp to ASTContext so it can be shared.

2016-09-13 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281353: ObjectiveC: Refactor applyObjCProtocolQualifiers. 
(authored by mren).

Changed prior to commit:
  https://reviews.llvm.org/D24059?vs=69766=71194#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24059

Files:
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/Sema/SemaType.cpp

Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -1030,6 +1030,14 @@
   /// replaced.
   QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace) const;
 
+  /// \brief Apply Objective-C protocol qualifiers to the given type.
+  /// \param allowOnPointerType specifies if we can apply protocol
+  /// qualifiers on ObjCObjectPointerType. It can be set to true when
+  /// contructing the canonical type of a Objective-C type parameter.
+  QualType applyObjCProtocolQualifiers(QualType type,
+  ArrayRef protocols, bool ,
+  bool allowOnPointerType = false) const;
+
   /// \brief Return the uniqued reference to the type for an Objective-C
   /// gc-qualified type.
   ///
Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -3871,6 +3871,76 @@
   return QualType(T, 0);
 }
 
+/// Apply Objective-C protocol qualifiers to the given type.
+/// If this is for the canonical type of a type parameter, we can apply
+/// protocol qualifiers on the ObjCObjectPointerType.
+QualType
+ASTContext::applyObjCProtocolQualifiers(QualType type,
+  ArrayRef protocols, bool ,
+  bool allowOnPointerType) const {
+  hasError = false;
+
+  // Apply protocol qualifiers to ObjCObjectPointerType.
+  if (allowOnPointerType) {
+if (const ObjCObjectPointerType *objPtr =
+dyn_cast(type.getTypePtr())) {
+  const ObjCObjectType *objT = objPtr->getObjectType();
+  // Merge protocol lists and construct ObjCObjectType.
+  SmallVector protocolsVec;
+  protocolsVec.append(objT->qual_begin(),
+  objT->qual_end());
+  protocolsVec.append(protocols.begin(), protocols.end());
+  ArrayRef protocols = protocolsVec;
+  type = getObjCObjectType(
+ objT->getBaseType(),
+ objT->getTypeArgsAsWritten(),
+ protocols,
+ objT->isKindOfTypeAsWritten());
+  return getObjCObjectPointerType(type);
+}
+  }
+
+  // Apply protocol qualifiers to ObjCObjectType.
+  if (const ObjCObjectType *objT = dyn_cast(type.getTypePtr())){
+// FIXME: Check for protocols to which the class type is already
+// known to conform.
+
+return getObjCObjectType(objT->getBaseType(),
+ objT->getTypeArgsAsWritten(),
+ protocols,
+ objT->isKindOfTypeAsWritten());
+  }
+
+  // If the canonical type is ObjCObjectType, ...
+  if (type->isObjCObjectType()) {
+// Silently overwrite any existing protocol qualifiers.
+// TODO: determine whether that's the right thing to do.
+
+// FIXME: Check for protocols to which the class type is already
+// known to conform.
+return getObjCObjectType(type, { }, protocols, false);
+  }
+
+  // id
+  if (type->isObjCIdType()) {
+const ObjCObjectPointerType *objPtr = type->castAs();
+type = getObjCObjectType(ObjCBuiltinIdTy, { }, protocols,
+ objPtr->isKindOfType());
+return getObjCObjectPointerType(type);
+  }
+
+  // Class
+  if (type->isObjCClassType()) {
+const ObjCObjectPointerType *objPtr = type->castAs();
+type = getObjCObjectType(ObjCBuiltinClassTy, { }, protocols,
+ objPtr->isKindOfType());
+return getObjCObjectPointerType(type);
+  }
+
+  hasError = true;
+  return type;
+}
+
 /// ObjCObjectAdoptsQTypeProtocols - Checks that protocols in IC's
 /// protocol list adopt all protocols in QT's qualified-id protocol
 /// list.
Index: cfe/trunk/lib/Sema/SemaType.cpp
===
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -1000,57 +1000,6 @@
   return S.Context.getObjCObjectType(type, finalTypeArgs, { }, false);
 }
 
-/// Apply Objective-C protocol qualifiers to the given type.
-static QualType applyObjCProtocolQualifiers(
-  Sema , SourceLocation loc, SourceRange range, QualType type,
-  ArrayRef protocols,
-  const SourceLocation *protocolLocs,
-  bool failOnError = false) {
-  ASTContext  = S.Context;
-  if (const ObjCObjectType *objT = dyn_cast(type.getTypePtr())){
-// FIXME: Check for protocols to which the class type is 

r281353 - ObjectiveC: Refactor applyObjCProtocolQualifiers.

2016-09-13 Thread Manman Ren via cfe-commits
Author: mren
Date: Tue Sep 13 12:03:12 2016
New Revision: 281353

URL: http://llvm.org/viewvc/llvm-project?rev=281353=rev
Log:
ObjectiveC: Refactor applyObjCProtocolQualifiers.

To construct the canonical type of ObjCTypeParamType, we need to apply
qualifiers on ObjCObjectPointerType. The updated applyObjCProtocolQualifiers
handles this case by merging the protocol lists, constructing a new
ObjCObjectType, then a new ObjCObjectPointerType.

rdar://24619481
rdar://25060179

Differential Revision: http://reviews.llvm.org/D24059

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=281353=281352=281353=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Sep 13 12:03:12 2016
@@ -1030,6 +1030,14 @@ public:
   /// replaced.
   QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace) const;
 
+  /// \brief Apply Objective-C protocol qualifiers to the given type.
+  /// \param allowOnPointerType specifies if we can apply protocol
+  /// qualifiers on ObjCObjectPointerType. It can be set to true when
+  /// contructing the canonical type of a Objective-C type parameter.
+  QualType applyObjCProtocolQualifiers(QualType type,
+  ArrayRef protocols, bool ,
+  bool allowOnPointerType = false) const;
+
   /// \brief Return the uniqued reference to the type for an Objective-C
   /// gc-qualified type.
   ///

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=281353=281352=281353=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Sep 13 12:03:12 2016
@@ -3871,6 +3871,76 @@ QualType ASTContext::getObjCObjectType(
   return QualType(T, 0);
 }
 
+/// Apply Objective-C protocol qualifiers to the given type.
+/// If this is for the canonical type of a type parameter, we can apply
+/// protocol qualifiers on the ObjCObjectPointerType.
+QualType
+ASTContext::applyObjCProtocolQualifiers(QualType type,
+  ArrayRef protocols, bool ,
+  bool allowOnPointerType) const {
+  hasError = false;
+
+  // Apply protocol qualifiers to ObjCObjectPointerType.
+  if (allowOnPointerType) {
+if (const ObjCObjectPointerType *objPtr =
+dyn_cast(type.getTypePtr())) {
+  const ObjCObjectType *objT = objPtr->getObjectType();
+  // Merge protocol lists and construct ObjCObjectType.
+  SmallVector protocolsVec;
+  protocolsVec.append(objT->qual_begin(),
+  objT->qual_end());
+  protocolsVec.append(protocols.begin(), protocols.end());
+  ArrayRef protocols = protocolsVec;
+  type = getObjCObjectType(
+ objT->getBaseType(),
+ objT->getTypeArgsAsWritten(),
+ protocols,
+ objT->isKindOfTypeAsWritten());
+  return getObjCObjectPointerType(type);
+}
+  }
+
+  // Apply protocol qualifiers to ObjCObjectType.
+  if (const ObjCObjectType *objT = 
dyn_cast(type.getTypePtr())){
+// FIXME: Check for protocols to which the class type is already
+// known to conform.
+
+return getObjCObjectType(objT->getBaseType(),
+ objT->getTypeArgsAsWritten(),
+ protocols,
+ objT->isKindOfTypeAsWritten());
+  }
+
+  // If the canonical type is ObjCObjectType, ...
+  if (type->isObjCObjectType()) {
+// Silently overwrite any existing protocol qualifiers.
+// TODO: determine whether that's the right thing to do.
+
+// FIXME: Check for protocols to which the class type is already
+// known to conform.
+return getObjCObjectType(type, { }, protocols, false);
+  }
+
+  // id
+  if (type->isObjCIdType()) {
+const ObjCObjectPointerType *objPtr = 
type->castAs();
+type = getObjCObjectType(ObjCBuiltinIdTy, { }, protocols,
+ objPtr->isKindOfType());
+return getObjCObjectPointerType(type);
+  }
+
+  // Class
+  if (type->isObjCClassType()) {
+const ObjCObjectPointerType *objPtr = 
type->castAs();
+type = getObjCObjectType(ObjCBuiltinClassTy, { }, protocols,
+ objPtr->isKindOfType());
+return getObjCObjectPointerType(type);
+  }
+
+  hasError = true;
+  return type;
+}
+
 /// ObjCObjectAdoptsQTypeProtocols - Checks that protocols in IC's
 /// protocol list adopt all protocols in QT's qualified-id protocol
 /// list.

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=281353=281352=281353=diff

[PATCH] D24515: Supports adding insertion around non-insertion replacements.

2016-09-13 Thread Eric Liu via cfe-commits
ioeric created this revision.
ioeric added reviewers: djasper, klimek.
ioeric added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Extend `tooling::Replacements::add()` to support adding order-independent 
replacements.

Two replacements are considered order-independent if one of the following 
conditions is true:
  - They do not overlap. (This is already supported.)
  - One replacement is insertion, and the other is a replacement with
length > 0, and the insertion is adjecent to but not contained in the
other replacement. In this case, the replacement should always change
the original code instead of the inserted text.

https://reviews.llvm.org/D24515

Files:
  include/clang/Tooling/Core/Replacement.h
  lib/Tooling/Core/Replacement.cpp
  unittests/Tooling/RefactoringTest.cpp

Index: unittests/Tooling/RefactoringTest.cpp
===
--- unittests/Tooling/RefactoringTest.cpp
+++ unittests/Tooling/RefactoringTest.cpp
@@ -115,24 +115,26 @@
   llvm::consumeError(std::move(Err));
 }
 
-TEST_F(ReplacementTest, FailAddOverlappingInsertions) {
+TEST_F(ReplacementTest, AddAdjacentInsertionAndReplacement) {
   Replacements Replaces;
   // Test adding an insertion at the offset of an existing replacement.
   auto Err = Replaces.add(Replacement("x.cc", 10, 3, "replace"));
   EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
   Err = Replaces.add(Replacement("x.cc", 10, 0, "insert"));
-  EXPECT_TRUE((bool)Err);
+  EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
+  EXPECT_EQ(Replaces.size(), 2u);
 
   Replaces.clear();
   // Test overlap with an existing insertion.
   Err = Replaces.add(Replacement("x.cc", 10, 0, "insert"));
   EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
   Err = Replaces.add(Replacement("x.cc", 10, 3, "replace"));
-  EXPECT_TRUE((bool)Err);
+  EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
+  EXPECT_EQ(Replaces.size(), 2u);
 }
 
 TEST_F(ReplacementTest, FailAddRegression) {
@@ -157,14 +159,24 @@
   llvm::consumeError(std::move(Err));
 }
 
-TEST_F(ReplacementTest, FailAddInsertAtOffsetOfReplacement) {
+TEST_F(ReplacementTest, InsertAtOffsetOfReplacement) {
   Replacements Replaces;
   auto Err = Replaces.add(Replacement("x.cc", 10, 2, ""));
   EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
   Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
-  EXPECT_TRUE((bool)Err);
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  EXPECT_EQ(Replaces.size(), 2u);
+
+  Replaces.clear();
+  Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 10, 2, ""));
+  EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
+  EXPECT_EQ(Replaces.size(), 2u);
 }
 
 TEST_F(ReplacementTest, FailAddInsertAtOtherInsert) {
@@ -175,6 +187,38 @@
   Err = Replaces.add(Replacement("x.cc", 10, 0, "b"));
   EXPECT_TRUE((bool)Err);
   llvm::consumeError(std::move(Err));
+
+  Replaces.clear();
+  Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
+  EXPECT_TRUE((bool)Err);
+  llvm::consumeError(std::move(Err));
+
+  Replaces.clear();
+  Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 10, 3, ""));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
+  EXPECT_TRUE((bool)Err);
+  llvm::consumeError(std::move(Err));
+}
+
+TEST_F(ReplacementTest, InsertBetweenAdjacentReplacements) {
+  Replacements Replaces;
+  auto Err = Replaces.add(Replacement("x.cc", 10, 5, "a"));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 8, 2, "a"));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 10, 0, "b"));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
 }
 
 TEST_F(ReplacementTest, CanApplyReplacements) {
@@ -189,6 +233,29 @@
   EXPECT_EQ("line1\nreplaced\nother\nline4", Context.getRewrittenText(ID));
 }
 
+// Verifies that replacement/deletion is applied before insertion at the same
+// offset.
+TEST_F(ReplacementTest, InsertAndDelete) {
+  FileID ID = Context.createInMemoryFile("input.cpp",
+ "line1\nline2\nline3\nline4");
+  Replacements Replaces = toReplacements(
+  {Replacement(Context.Sources, Context.getLocation(ID, 2, 1), 6, ""),
+   Replacement(Context.Sources, Context.getLocation(ID, 2, 1), 0,
+   "other\n")});
+  EXPECT_TRUE(applyAllReplacements(Replaces, Context.Rewrite));
+  EXPECT_EQ("line1\nother\nline3\nline4", Context.getRewrittenText(ID));
+}
+
+TEST_F(ReplacementTest, AdjacentReplacements) {
+  FileID ID = 

Re: [PATCH] D24005: [compiler-rt cmake] Support overriding llvm-config query results

2016-09-13 Thread Chris Bieneman via cfe-commits
beanz added a comment.

You cannot rename the variables that start with `LLVM_*`, but the variables 
without the leading `LLVM` can be renamed to whatever makes sense, or left 
as-is. I'm fine with either way.

The variables starting with `LLVM_*` are effectively public interface to the 
build system, and renaming them would be very difficult.


https://reviews.llvm.org/D24005



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


Re: [PATCH] D24512: AMDGPU: Fix target options fp32/64-denormals

2016-09-13 Thread Yaxun Liu via cfe-commits
yaxunl added inline comments.


Comment at: lib/Basic/Targets.cpp:1962
@@ -1961,3 +1961,3 @@
   bool hasLDEXPF:1;
-  bool hasDenormSupport:1;
+  bool hasFP32DenormSupport:1;
 

tstellarAMD wrote:
> I think this name is a little confusing, because the hardware does support  
> fp32 denorms.  I would change this to something like hasFullSpeedFP32Denorms.
I will change that when committing. Thanks.


https://reviews.llvm.org/D24512



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


Re: [PATCH] D24512: AMDGPU: Fix target options fp32/64-denormals

2016-09-13 Thread Tom Stellard via cfe-commits
tstellarAMD accepted this revision.
tstellarAMD added a comment.
This revision is now accepted and ready to land.

Once small comment otherwise. LGTM.



Comment at: lib/Basic/Targets.cpp:1962
@@ -1961,3 +1961,3 @@
   bool hasLDEXPF:1;
-  bool hasDenormSupport:1;
+  bool hasFP32DenormSupport:1;
 

I think this name is a little confusing, because the hardware does support  
fp32 denorms.  I would change this to something like hasFullSpeedFP32Denorms.


https://reviews.llvm.org/D24512



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


Re: [PATCH] D24477: clang-format: [JS] Do not wrap taze: IWYU comments

2016-09-13 Thread Martin Probst via cfe-commits
mprobst marked an inline comment as done.
mprobst added a comment.

https://reviews.llvm.org/D24477



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


r281351 - Add a class ObjCProtocolQualifiers to wrap APIs for ObjC protocol list.

2016-09-13 Thread Manman Ren via cfe-commits
Author: mren
Date: Tue Sep 13 11:45:29 2016
New Revision: 281351

URL: http://llvm.org/viewvc/llvm-project?rev=281351=rev
Log:
Add a class ObjCProtocolQualifiers to wrap APIs for ObjC protocol list.

Now ObjCObjectType extends from ObjCProtocolQualifiers. We save number of
protocols in ObjCProtocolQualifiers.

This is in preparation of adding a new type class ObjCTypeParamType that
can take protocol qualifiers.

rdar://24619481
rdar://25060179

Differential Revision: http://reviews.llvm.org/D23078

Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/Type.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=281351=281350=281351=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Sep 13 11:45:29 2016
@@ -4699,6 +4699,59 @@ public:
   }
 };
 
+/// This class wraps the list of protocol qualifiers. For types that can
+/// take ObjC protocol qualifers, they can subclass this class.
+template 
+class ObjCProtocolQualifiers {
+protected:
+  ObjCProtocolQualifiers() {}
+  ObjCProtocolDecl * const *getProtocolStorage() const {
+return const_cast(this)->getProtocolStorage();
+  }
+
+  ObjCProtocolDecl **getProtocolStorage() {
+return static_cast(this)->getProtocolStorageImpl();
+  }
+  void setNumProtocols(unsigned N) {
+static_cast(this)->setNumProtocolsImpl(N);
+  }
+  void initialize(ArrayRef protocols) {
+setNumProtocols(protocols.size());
+assert(getNumProtocols() == protocols.size() &&
+   "bitfield overflow in protocol count");
+if (!protocols.empty())
+  memcpy(getProtocolStorage(), protocols.data(),
+ protocols.size() * sizeof(ObjCProtocolDecl*));
+  }
+
+public:
+  typedef ObjCProtocolDecl * const *qual_iterator;
+  typedef llvm::iterator_range qual_range;
+
+  qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
+  qual_iterator qual_begin() const { return getProtocolStorage(); }
+  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
+
+  bool qual_empty() const { return getNumProtocols() == 0; }
+
+  /// Return the number of qualifying protocols in this type, or 0 if
+  /// there are none.
+  unsigned getNumProtocols() const {
+return static_cast(this)->getNumProtocolsImpl();
+  }
+
+  /// Fetch a protocol by index.
+  ObjCProtocolDecl *getProtocol(unsigned I) const {
+assert(I < getNumProtocols() && "Out-of-range protocol access");
+return qual_begin()[I];
+  }
+
+  /// Retrieve all of the protocol qualifiers.
+  ArrayRef getProtocols() const {
+return ArrayRef(qual_begin(), getNumProtocols());
+  }
+};
+
 /// Represents a class type in Objective C.
 ///
 /// Every Objective C type is a combination of a base type, a set of
@@ -4727,7 +4780,9 @@ public:
 /// 'id' is an ObjCObjectPointerType whose pointee is an ObjCObjectType
 /// with base BuiltinType::ObjCIdType and protocol list [P].  Eventually
 /// this should get its own sugar class to better represent the source.
-class ObjCObjectType : public Type {
+class ObjCObjectType : public Type,
+   public ObjCProtocolQualifiers {
+  friend class ObjCProtocolQualifiers;
   // ObjCObjectType.NumTypeArgs - the number of type arguments stored
   // after the ObjCObjectPointerType node.
   // ObjCObjectType.NumProtocols - the number of protocols stored
@@ -4747,16 +4802,20 @@ class ObjCObjectType : public Type {
   mutable llvm::PointerIntPair
 CachedSuperClassType;
 
-  ObjCProtocolDecl * const *getProtocolStorage() const {
-return const_cast(this)->getProtocolStorage();
-  }
-
   QualType *getTypeArgStorage();
   const QualType *getTypeArgStorage() const {
 return const_cast(this)->getTypeArgStorage();
   }
 
-  ObjCProtocolDecl **getProtocolStorage();
+  ObjCProtocolDecl **getProtocolStorageImpl();
+  /// Return the number of qualifying protocols in this interface type,
+  /// or 0 if there are none.
+  unsigned getNumProtocolsImpl() const {
+return ObjCObjectTypeBits.NumProtocols;
+  }
+  void setNumProtocolsImpl(unsigned N) {
+ObjCObjectTypeBits.NumProtocols = N;
+  }
 
 protected:
   ObjCObjectType(QualType Canonical, QualType Base,
@@ -4833,30 +4892,6 @@ public:
   ObjCObjectTypeBits.NumTypeArgs);
   }
 
-  typedef ObjCProtocolDecl * const *qual_iterator;
-  typedef llvm::iterator_range qual_range;
-
-  qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
-  qual_iterator qual_begin() const { return getProtocolStorage(); }
-  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
-
-  bool qual_empty() const { return getNumProtocols() == 0; }
-
-  /// Return the number of qualifying protocols in this interface type,
-  /// or 0 if there are none.
-  unsigned 

Re: [PATCH] D24477: clang-format: [JS] Do not wrap taze: IWYU comments

2016-09-13 Thread Daniel Jasper via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Generally looks good.



Comment at: unittests/Format/FormatTestJS.cpp:1433
@@ +1432,3 @@
+TEST_F(FormatTestJS, ImportComments) {
+  verifyFormat("import {x} from 'x';  // from //x:x", 
getGoogleJSStyleWithColumns(25));
+  verifyFormat("// taze: x from 'location'", getGoogleJSStyleWithColumns(10));

Maybe here, too? I don't think many people are familiar with bazel target 
syntax ;).


https://reviews.llvm.org/D24477



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


Re: [PATCH] D24477: clang-format: [JS] Do not wrap taze: IWYU comments

2016-09-13 Thread Martin Probst via cfe-commits
mprobst updated this revision to Diff 71189.
mprobst added a comment.

- update commit msg
- make test case a bit more generic


https://reviews.llvm.org/D24477

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1429,5 +1429,10 @@
"}");
 }
 
+TEST_F(FormatTestJS, ImportComments) {
+  verifyFormat("import {x} from 'x';  // from //x:x", 
getGoogleJSStyleWithColumns(25));
+  verifyFormat("// taze: x from 'location'", getGoogleJSStyleWithColumns(10));
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -613,7 +613,7 @@
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
 GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
 GoogleStyle.BreakBeforeTernaryOperators = false;
-GoogleStyle.CommentPragmas = "@(export|requirecss|return|see|visibility) ";
+GoogleStyle.CommentPragmas = 
"(taze:|@(export|requirecss|return|see|visibility)) ";
 GoogleStyle.MaxEmptyLinesToKeep = 3;
 GoogleStyle.NamespaceIndentation = FormatStyle::NI_All;
 GoogleStyle.SpacesInContainerLiterals = false;


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1429,5 +1429,10 @@
"}");
 }
 
+TEST_F(FormatTestJS, ImportComments) {
+  verifyFormat("import {x} from 'x';  // from //x:x", getGoogleJSStyleWithColumns(25));
+  verifyFormat("// taze: x from 'location'", getGoogleJSStyleWithColumns(10));
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -613,7 +613,7 @@
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
 GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
 GoogleStyle.BreakBeforeTernaryOperators = false;
-GoogleStyle.CommentPragmas = "@(export|requirecss|return|see|visibility) ";
+GoogleStyle.CommentPragmas = "(taze:|@(export|requirecss|return|see|visibility)) ";
 GoogleStyle.MaxEmptyLinesToKeep = 3;
 GoogleStyle.NamespaceIndentation = FormatStyle::NI_All;
 GoogleStyle.SpacesInContainerLiterals = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24513: [AMDGPU] Expose flat work group size, register and wave control attributes

2016-09-13 Thread Konstantin Zhuravlyov via cfe-commits
kzhuravl created this revision.
kzhuravl added reviewers: arsenm, aaron.ballman.
kzhuravl added subscribers: yaxunl, kanarayan, cfe-commits.
Herald added a reviewer: tstellarAMD.
Herald added subscribers: nhaehnle, wdng.

__attribute__((amdgpu_flat_work_group_size(, ))) - request minimum 
and maximum flat work group size
__attribute__((amdgpu_waves_per_eu([, ]))) - request minimum and/or 
maximum waves per execution unit

TODO: need to update docs in AttrDocs.td

https://reviews.llvm.org/D24513

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenOpenCL/amdgpu-attrs.cl
  test/CodeGenOpenCL/amdgpu-num-gpr-attr.cl
  test/SemaCUDA/amdgpu-attrs.cu
  test/SemaCUDA/amdgpu-num-gpr-attr.cu
  test/SemaOpenCL/amdgpu-attrs.cl
  test/SemaOpenCL/amdgpu-num-register-attrs.cl

Index: test/SemaOpenCL/amdgpu-num-register-attrs.cl
===
--- test/SemaOpenCL/amdgpu-num-register-attrs.cl
+++ test/SemaOpenCL/amdgpu-num-register-attrs.cl
@@ -1,40 +0,0 @@
-// RUN: %clang_cc1 -triple r600-- -verify -fsyntax-only %s
-
-typedef __attribute__((amdgpu_num_vgpr(128))) struct FooStruct { // expected-error {{'amdgpu_num_vgpr' attribute only applies to kernel functions}}
-  int x;
-  float y;
-} FooStruct;
-
-
-__attribute__((amdgpu_num_vgpr("ABC"))) kernel void foo2() {} // expected-error {{'amdgpu_num_vgpr' attribute requires an integer constant}}
-__attribute__((amdgpu_num_sgpr("ABC"))) kernel void foo3() {} // expected-error {{'amdgpu_num_sgpr' attribute requires an integer constant}}
-
-
-__attribute__((amdgpu_num_vgpr(40))) void foo4() {} // expected-error {{'amdgpu_num_vgpr' attribute only applies to kernel functions}}
-__attribute__((amdgpu_num_sgpr(64))) void foo5() {} // expected-error {{'amdgpu_num_sgpr' attribute only applies to kernel functions}}
-
-__attribute__((amdgpu_num_vgpr(40))) kernel void foo7() {}
-__attribute__((amdgpu_num_sgpr(64))) kernel void foo8() {}
-__attribute__((amdgpu_num_vgpr(40), amdgpu_num_sgpr(64))) kernel void foo9() {}
-
-// Check 0 VGPR is accepted.
-__attribute__((amdgpu_num_vgpr(0))) kernel void foo10() {}
-
-// Check 0 SGPR is accepted.
-__attribute__((amdgpu_num_sgpr(0))) kernel void foo11() {}
-
-// Check both 0 SGPR and VGPR is accepted.
-__attribute__((amdgpu_num_vgpr(0), amdgpu_num_sgpr(0))) kernel void foo12() {}
-
-// Too large VGPR value.
-__attribute__((amdgpu_num_vgpr(4294967296))) kernel void foo13() {} // expected-error {{integer constant expression evaluates to value 4294967296 that cannot be represented in a 32-bit unsigned integer type}}
-
-__attribute__((amdgpu_num_sgpr(4294967296))) kernel void foo14() {} // expected-error {{integer constant expression evaluates to value 4294967296 that cannot be represented in a 32-bit unsigned integer type}}
-
-__attribute__((amdgpu_num_sgpr(4294967296), amdgpu_num_vgpr(4294967296))) kernel void foo15() {} // expected-error 2 {{integer constant expression evaluates to value 4294967296 that cannot be represented in a 32-bit unsigned integer type}}
-
-
-// Make sure it is accepted with kernel keyword before the attribute.
-kernel __attribute__((amdgpu_num_vgpr(40))) void foo16() {}
-
-kernel __attribute__((amdgpu_num_sgpr(40))) void foo17() {}
Index: test/SemaOpenCL/amdgpu-attrs.cl
===
--- test/SemaOpenCL/amdgpu-attrs.cl
+++ test/SemaOpenCL/amdgpu-attrs.cl
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -triple amdgcn-- -verify -fsyntax-only %s
+
+typedef __attribute__((amdgpu_flat_work_group_size(32, 64))) struct struct_flat_work_group_size_32_64 { // expected-error {{'amdgpu_flat_work_group_size' attribute only applies to kernel functions}}
+  int x;
+  float y;
+} struct_flat_work_group_size_32_64;
+typedef __attribute__((amdgpu_waves_per_eu(2))) struct struct_waves_per_eu_2 { // expected-error {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
+  int x;
+  float y;
+} struct_waves_per_eu_2;
+typedef __attribute__((amdgpu_waves_per_eu(2, 4))) struct struct_waves_per_eu_2_4 { // expected-error {{'amdgpu_waves_per_eu' attribute only applies to kernel functions}}
+  int x;
+  float y;
+} struct_waves_per_eu_2_4;
+typedef __attribute__((amdgpu_num_sgpr(32))) struct struct_num_sgpr_32 { // expected-error {{'amdgpu_num_sgpr' attribute only applies to kernel functions}}
+  int x;
+  float y;
+} struct_num_sgpr_32;
+typedef __attribute__((amdgpu_num_vgpr(64))) struct struct_num_vgpr_64 { // expected-error {{'amdgpu_num_vgpr' attribute only applies to kernel functions}}
+  int x;
+  float y;
+} struct_num_vgpr_64;
+
+__attribute__((amdgpu_flat_work_group_size(32, 64))) void func_flat_work_group_size_32_64() {} // expected-error {{'amdgpu_flat_work_group_size' attribute only applies to kernel functions}}
+__attribute__((amdgpu_waves_per_eu(2))) void func_waves_per_eu_2() {} // 

[PATCH] D24512: AMDGPU: Fix target options fp32/64-denormals

2016-09-13 Thread Yaxun Liu via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tstellarAMD, nhaustov, arsenm.
yaxunl added subscribers: cfe-commits, AMDGPU.
Herald added a subscriber: wdng.

Fix target options for fp32/64-denormals so that

  +fp64-denormals is set if fp64 is supported
  -fp32-denormals if fp32 denormals is not supported, or -cl-denorms-are-zero 
is set
  +fp32-denormals if fp32 denormals is supported and -cl-denorms-are-zero is 
not set


https://reviews.llvm.org/D24512

Files:
  lib/Basic/Targets.cpp
  test/CodeGenOpenCL/denorms-are-zero.cl

Index: test/CodeGenOpenCL/denorms-are-zero.cl
===
--- test/CodeGenOpenCL/denorms-are-zero.cl
+++ test/CodeGenOpenCL/denorms-are-zero.cl
@@ -1,13 +1,19 @@
 // RUN: %clang_cc1 -S -cl-denorms-are-zero -o - %s 2>&1
 // RUN: %clang_cc1 -emit-llvm -cl-denorms-are-zero -o - -triple amdgcn--amdhsa 
-target-cpu fiji %s | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn--amdhsa -target-cpu fiji %s 
| FileCheck %s --check-prefix=CHECK-DENORM
+// RUN: %clang_cc1 -emit-llvm -target-feature +fp32-denormals -target-feature 
-fp64-denormals -cl-denorms-are-zero -o - -triple amdgcn--amdhsa -target-cpu 
fiji %s | FileCheck --check-prefix=CHECK-FEATURE %s
 
 // For non-amdgcn targets, this test just checks that the -cl-denorms-are-zero 
argument is accepted
 // by clang.  This option is currently a no-op, which is allowed by the
 // OpenCL specification.
 
+// For amdgcn target cpu fiji, fp32 should be flushed since fiji does not 
support fp32 denormals, unless +fp32-denormals is
+// explicitly set. amdgcn target always do not flush fp64 denormals.
+
 // CHECK-DENORM-LABEL: define void @f()
-// CHECK-DENORM: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp32-denormals,+fp64-denormals{{[^"]*}}"
+// CHECK-DENORM: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp64-denormals,{{[^"]*}}-fp32-denormals{{[^"]*}}"
 // CHECK-LABEL: define void @f()
-// CHECK-NOT: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp32-denormals,+fp64-denormals{{[^"]*}}"
+// CHECK: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp64-denormals,{{[^"]*}}-fp32-denormals{{[^"]*}}"
+// CHECK-FEATURE-LABEL: define void @f()
+// CHECK-FEATURE: attributes #{{[0-9]*}} = {{{[^}]*}} 
"target-features"="{{[^"]*}}+fp32-denormals,{{[^"]*}}-fp64-denormals{{[^"]*}}"
 void f() {}
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -1959,7 +1959,7 @@
   bool hasFP64:1;
   bool hasFMAF:1;
   bool hasLDEXPF:1;
-  bool hasDenormSupport:1;
+  bool hasFP32DenormSupport:1;
 
   static bool isAMDGCN(const llvm::Triple ) {
 return TT.getArch() == llvm::Triple::amdgcn;
@@ -1972,14 +1972,12 @@
   hasFP64(false),
   hasFMAF(false),
   hasLDEXPF(false),
-  hasDenormSupport(false){
+  hasFP32DenormSupport(false){
 if (getTriple().getArch() == llvm::Triple::amdgcn) {
   hasFP64 = true;
   hasFMAF = true;
   hasLDEXPF = true;
 }
-if (Opts.CPU == "fiji")
-  hasDenormSupport = true;
 
 resetDataLayout(getTriple().getArch() == llvm::Triple::amdgcn ?
 DataLayoutStringSI : DataLayoutStringR600);
@@ -2034,8 +2032,6 @@
 
   void adjustTargetOptions(const CodeGenOptions ,
TargetOptions ) const override {
-if (!hasDenormSupport)
-  return;
 bool hasFP32Denormals = false;
 bool hasFP64Denormals = false;
 for (auto  : TargetOpts.FeaturesAsWritten) {
@@ -2045,11 +2041,11 @@
 hasFP64Denormals = true;
 }
 if (!hasFP32Denormals)
-  TargetOpts.Features.push_back((Twine(CGOpts.FlushDenorm ? '-' : '+') +
- Twine("fp32-denormals")).str());
+  TargetOpts.Features.push_back((Twine(hasFP32DenormSupport &&
+  !CGOpts.FlushDenorm ? '+' : '-') + Twine("fp32-denormals")).str());
+// Always do not flush fp64 denorms.
 if (!hasFP64Denormals && hasFP64)
-  TargetOpts.Features.push_back((Twine(CGOpts.FlushDenorm ? '-' : '+') +
- Twine("fp64-denormals")).str());
+  TargetOpts.Features.push_back("+fp64-denormals");
   }
 
   ArrayRef getTargetBuiltins() const override {


Index: test/CodeGenOpenCL/denorms-are-zero.cl
===
--- test/CodeGenOpenCL/denorms-are-zero.cl
+++ test/CodeGenOpenCL/denorms-are-zero.cl
@@ -1,13 +1,19 @@
 // RUN: %clang_cc1 -S -cl-denorms-are-zero -o - %s 2>&1
 // RUN: %clang_cc1 -emit-llvm -cl-denorms-are-zero -o - -triple amdgcn--amdhsa -target-cpu fiji %s | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn--amdhsa -target-cpu fiji %s | FileCheck %s --check-prefix=CHECK-DENORM
+// RUN: %clang_cc1 -emit-llvm -target-feature +fp32-denormals -target-feature -fp64-denormals -cl-denorms-are-zero -o - 

Re: [PATCH] D24484: [analyzer] Fix ExprEngine::VisitMemberExpr

2016-09-13 Thread Alexander Shaposhnikov via cfe-commits
alexshap added inline comments.


Comment at: test/Analysis/array-struct.c:147
@@ +146,3 @@
+  bar(((gets3().a)));  
+}
+

compnerd wrote:
> Perhaps Im missing something, but theres no change to actually verify the 
> output?
without the changes the analyzer is crashing (llvm_unreachable (see the 
attached screenshot)) on this code (and the test is failing), with the fix it 
works fine. 


Repository:
  rL LLVM

https://reviews.llvm.org/D24484



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


Re: [PATCH] D22346: [Clang-tidy] CERT-MSC50-CPP (std:rand() )

2016-09-13 Thread Benedek Kiss via cfe-commits
falho marked 5 inline comments as done.


Comment at: clang-tidy/cert/LimitedRandomnessCheck.cpp:22-23
@@ +21,4 @@
+  Finder->addMatcher(
+  declRefExpr(hasDeclaration(functionDecl(namedDecl(hasName("::rand")),
+  parameterCountIs(0
+  .bind("randomGenerator"),

xazax.hun wrote:
> aaron.ballman wrote:
> > xazax.hun wrote:
> > > aaron.ballman wrote:
> > > > xazax.hun wrote:
> > > > > aaron.ballman wrote:
> > > > > > Prazek wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > Prazek wrote:
> > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > This should be looking at a callExpr() rather than a 
> > > > > > > > > > declRefExpr(), should it not?
> > > > > > > > > I was also thinking about this, but this is actually better, 
> > > > > > > > > because it will also match with binding rand with function 
> > > > > > > > > pointer.
> > > > > > > > True, but a DeclRefExpr doesn't mean it's a function call. 
> > > > > > > > Binding the function is not contrary to the CERT rule, just 
> > > > > > > > calling it. For instance, the following pathological case will 
> > > > > > > > be caught by this check:
> > > > > > > > ```
> > > > > > > > if (std::rand) {}
> > > > > > > > ```
> > > > > > > > The behavior of this check should be consistent with 
> > > > > > > > cert-env33-c, which only looks at calls. (If we really care 
> > > > > > > > about bound functions, we'd need flow control analysis, and I 
> > > > > > > > think that's overkill for both of those checks, but wouldn't be 
> > > > > > > > opposed to someone writing the flow analysis if they really 
> > > > > > > > wanted to.)
> > > > > > > It would indeed fire on this pathological case, but I don't think 
> > > > > > > we should care about cases like this, because no one is writing 
> > > > > > > code like this (and if he would then it would probably be a bug).
> > > > > > > I don't think that there is much code that binds pointer to 
> > > > > > > std::rand either, but I think it would be good to display warning 
> > > > > > > for this, because even if the function would be never called, 
> > > > > > > then it means that this is a bug, and if it would be called then 
> > > > > > > it would be nice to tell user that rand might be used here.
> > > > > > > 
> > > > > > > Anyway I don't oppose for changing it to callExpr, but I think it 
> > > > > > > is better this way.
> > > > > > > It would indeed fire on this pathological case, but I don't think 
> > > > > > > we should care about cases like this, because no one is writing 
> > > > > > > code like this (and if he would then it would probably be a bug).
> > > > > > 
> > > > > > It would be a known false-positive for a check designed to conform 
> > > > > > to a particular coding standard. When deviations have come up in 
> > > > > > the past for various coding standards, we've added an option to 
> > > > > > enable the additional functionality, which I don't think would be 
> > > > > > reasonable in this case. Alternatively, the CERT guideline could be 
> > > > > > modified, but that is unlikely to occur because binding the 
> > > > > > function pointer is not a security concern (only calling the 
> > > > > > function).
> > > > > In case you let binding to function pointer you introduce potential 
> > > > > false negatives which is worse in this case in my opinion. 
> > > > Basically: this half-measure is sufficient for the CERT coding rule, 
> > > > but isn't ideal. The ideal check isn't likely to uncover many more 
> > > > cases than the half-measure, which is why it was not implemented in the 
> > > > past. If someone wants to implement the whole-measure, that's great! 
> > > > But implementing a half, half-measure that isn't consistent with other, 
> > > > similar checks is the wrong thing to do.
> > > You can not implement an ideal checker. In general, it is undecidable 
> > > whether std::rand is called or not. (You can easily create an example 
> > > where you would need to solve the halting problem in order to decide 
> > > whether std::rand is called.)
> > > 
> > > Since the ideal checker is infeasible the question is whether you are OK 
> > > with false positives or false negatives. The approach you are suggesting 
> > > result in false negatives. The current approach results in false 
> > > positives. I think, for this security checker, a false positive is much 
> > > less serious to have than a false negative. Moreover, I doubt that people 
> > > write code where such false positives are intended and the code should 
> > > not be changed. But in case you can think of an example, please let us 
> > > know.
> > > You can not implement an ideal checker. In general, it is undecidable 
> > > whether std::rand is called or not. (You can easily create an example 
> > > where you would need to solve the halting problem in order to decide 
> > > whether std::rand is called.)
> > 
> > I said "ideal", not 

Re: [PATCH] D24469: [clang-cl] Diagnose duplicate uuids.

2016-09-13 Thread Nico Weber via cfe-commits
thakis updated this revision to Diff 71181.
thakis added a comment.

comments


https://reviews.llvm.org/D24469

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/AttributeList.h
  include/clang/Sema/Sema.h
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/SemaCXX/ms-uuid.cpp

Index: test/SemaCXX/ms-uuid.cpp
===
--- test/SemaCXX/ms-uuid.cpp
+++ test/SemaCXX/ms-uuid.cpp
@@ -0,0 +1,94 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s
+
+typedef struct _GUID {
+  unsigned long Data1;
+  unsigned short Data2;
+  unsigned short Data3;
+  unsigned char Data4[8];
+} GUID;
+
+namespace {
+// cl.exe's behavior with merging uuid attributes is a bit erratic:
+// * In []-style attributes, a single [] list must not list a duplicate uuid
+//   (even if it's the same uuid), and only a single declaration of a class
+//   must have a uuid else the compiler errors out (even if two declarations of
+//   a class have the same uuid).
+// * For __declspec(uuid(...)), it's ok if several declarations of a class have
+//   an uuid, as long as it's the same uuid each time.  If uuids on declarations
+//   don't match, the compiler errors out.
+// * If there are several __declspec(uuid(...))s on one declaration, the
+//   compiler only warns about this and uses the last uuid.  It even warns if
+//   the uuids are the same.
+
+// clang-cl implements the following simpler (but largely compatible) behavior
+// instead:
+// * [] and __declspec uuids have the same behavior.
+// * If there are several uuids on a a class (no matter if on the same decl or
+//   on several decls), it is an error if they don't match.
+// * Having several uuids that match is ok.
+
+// Both cl and clang-cl accept this:
+class __declspec(uuid("00A0---C000-0049")) C1;
+class __declspec(uuid("00A0---C000-0049")) C1;
+class __declspec(uuid("00A0---C000-0049")) C1 {};
+
+// Both cl and clang-cl error out on this:
+// expected-note@+1 2{{previous uuid specified here}}
+class __declspec(uuid("00A0---C000-0049")) C2;
+// expected-error@+1 {{uuid does not match previous declaration}}
+class __declspec(uuid("11A0---C000-0049")) C2;
+// expected-error@+1 {{uuid does not match previous declaration}}
+class __declspec(uuid("22A0---C000-0049")) C2 {};
+
+// expected-note@+1 {{previous uuid specified here}}
+class __declspec(uuid("00A0---C000-0049")) C2_2;
+class C2_2;
+// expected-error@+1 {{uuid does not match previous declaration}}
+class __declspec(uuid("11A0---C000-0049")) C2_2;
+
+// clang-cl accepts this, but cl errors out:
+[uuid("00A0---C000-0049")] class C3;
+[uuid("00A0---C000-0049")] class C3;
+[uuid("00A0---C000-0049")] class C3 {};
+
+// Both cl and clang-cl error out on this (but for different reasons):
+// expected-note@+1 2{{previous uuid specified here}}
+[uuid("00A0---C000-0049")] class C4;
+// expected-error@+1 {{uuid does not match previous declaration}}
+[uuid("11A0---C000-0049")] class C4;
+// expected-error@+1 {{uuid does not match previous declaration}}
+[uuid("22A0---C000-0049")] class C4 {};
+
+// Both cl and clang-cl error out on this:
+// expected-note@+1 {{previous uuid specified here}}
+class __declspec(uuid("00A0---C000-0049"))
+// expected-error@+1 {{uuid does not match previous declaration}}
+  __declspec(uuid("11A0---C000-0049")) C5;
+
+// expected-note@+1 {{previous uuid specified here}}
+[uuid("00A0---C000-0049"),
+// expected-error@+1 {{uuid does not match previous declaration}}
+ uuid("11A0---C000-0049")] class C6;
+
+// cl doesn't diagnose having one uuid each as []-style attributes and as
+// __declspec, even if the uuids differ.  clang-cl errors if they differ.
+[uuid("00A0---C000-0049")]
+class __declspec(uuid("00A0---C000-0049")) C7;
+
+// expected-note@+1 {{previous uuid specified here}}
+[uuid("00A0---C000-0049")]
+// expected-error@+1 {{uuid does not match previous declaration}}
+class __declspec(uuid("11A0---C000-0049")) C8;
+
+
+// cl warns on this, but clang-cl is fine with it (which is consistent with
+// e.g. specifying __multiple_inheritance several times, which cl accepts
+// without warning too).
+class __declspec(uuid("00A0---C000-0049"))
+  __declspec(uuid("00A0---C000-0049")) C9;
+
+// cl errors out on this, but clang-cl is fine with it (to be consistent with
+// the previous case).
+[uuid("00A0---C000-0049"),
+ uuid("00A0---C000-0049")] class C10;
+}
Index: 

  1   2   >