[PATCH] D74787: [IRBuilder] Always respect inserter/folder

2020-02-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

> There should be at most two iterations, one to perform folds and one to 
> verify the fixpoint. If there are more iterations, that's a bug in worklist 
> management

FWIW, the Attributor uses basically the same scheme. It helps us to monitor 
iteration increases/decreases of patchs and prevents subtle bugs that would 
escape the regressions tests but hit the iteration limit in real code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74787



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


[PATCH] D75009: [Diagnostic] Improve discoverability of ftabstop for misleading indentation

2020-02-22 Thread Tyker via Phabricator via cfe-commits
Tyker created this revision.
Tyker added a reviewer: eli.friedman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Tyker added a comment.

i tried to find a good message but i don't think i succeeded. any suggestions.


This adds an additional note after the misleading warning when the code has a 
mix of tab and space informing about -ftabstop when -ftabstop is used in the 
generation of the warning.


Repository:
  rC Clang

https://reviews.llvm.org/D75009

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseStmt.cpp
  clang/test/Parser/warn-misleading-indentation.cpp

Index: clang/test/Parser/warn-misleading-indentation.cpp
===
--- clang/test/Parser/warn-misleading-indentation.cpp
+++ clang/test/Parser/warn-misleading-indentation.cpp
@@ -234,7 +234,8 @@
  	return 0;
 #if (TAB_SIZE == 1)
 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
-// expected-note@-5 {{here}}
+// expected-note@-3 {{there is a mix of tabs spaces; the tab size (-ftabstop=X) is set to 1}}
+// expected-note@-6 {{here}}
 #endif 
 }
 
@@ -256,7 +257,20 @@
   		return 0;
 #if (TAB_SIZE == 8)
 // expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
-// expected-note@-5 {{here}}
+// expected-note@-3 {{there is a mix of tabs spaces; the tab size (-ftabstop=X) is set to 8}}
+// expected-note@-6 {{here}}
+#endif
+}
+
+int a7()
+{
+	if (0)
+		return 1;
+return 0;
+#if (TAB_SIZE == 4)
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+// expected-note@-3 {{there is a mix of tabs spaces; the tab size (-ftabstop=X) is set to 4}}
+// expected-note@-6 {{here}}
 #endif
 }
 
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1217,11 +1217,12 @@
 
   /// Compute the column number will aligning tabs on TabStop (-ftabstop), this
   /// gives the visual indentation of the SourceLocation.
-  static unsigned getVisualIndentation(SourceManager &SM, SourceLocation Loc) {
+  static unsigned getVisualIndentation(SourceManager &SM, SourceLocation Loc,
+   bool& HasTab, bool& HasSpace) {
 unsigned TabStop = SM.getDiagnostics().getDiagnosticOptions().TabStop;
 
 unsigned ColNo = SM.getSpellingColumnNumber(Loc);
-if (ColNo == 0 || TabStop == 1)
+if (ColNo == 0)
   return ColNo;
 
 std::pair FIDAndOffset = SM.getDecomposedLoc(Loc);
@@ -1241,6 +1242,8 @@
 // expanding tabs.
 for (const char *CurPos = EndPos - (ColNo - 1); CurPos != EndPos;
  ++CurPos) {
+  HasTab |= *CurPos == '\t';
+  HasSpace |= *CurPos == ' ';
   if (*CurPos == '\t')
 // Advance visual column to next tabstop.
 VisualColumn += (TabStop - VisualColumn % TabStop);
@@ -1266,9 +1269,12 @@
   P.MisleadingIndentationElseLoc = SourceLocation();
 
 SourceManager &SM = P.getPreprocessor().getSourceManager();
-unsigned PrevColNum = getVisualIndentation(SM, PrevLoc);
-unsigned CurColNum = getVisualIndentation(SM, Tok.getLocation());
-unsigned StmtColNum = getVisualIndentation(SM, StmtLoc);
+bool HasTab = false;
+bool HasSpace = false;
+unsigned PrevColNum = getVisualIndentation(SM, PrevLoc, HasTab, HasSpace);
+unsigned CurColNum =
+getVisualIndentation(SM, Tok.getLocation(), HasTab, HasSpace);
+unsigned StmtColNum = getVisualIndentation(SM, StmtLoc, HasTab, HasSpace);
 
 if (PrevColNum != 0 && CurColNum != 0 && StmtColNum != 0 &&
 ((PrevColNum > StmtColNum && PrevColNum == CurColNum) ||
@@ -1278,6 +1284,10 @@
 (Tok.isNot(tok::identifier) ||
  P.getPreprocessor().LookAhead(0).isNot(tok::colon))) {
   P.Diag(Tok.getLocation(), diag::warn_misleading_indentation) << Kind;
+  if (HasTab && HasSpace)
+P.Diag(Tok.getLocation(),
+   diag::note_misleading_indentation_tab_space_mix)
+<< SM.getDiagnostics().getDiagnosticOptions().TabStop;
   P.Diag(StmtLoc, diag::note_previous_statement);
 }
   }
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -63,6 +63,8 @@
   InGroup, DefaultIgnore;
 def note_previous_statement : Note<
   "previous statement is here">;
+def note_misleading_indentation_tab_space_mix : Note<
+  "there is a mix of tabs spaces; the tab size (-ftabstop=X) is set to %0">;
 
 def ext_thread_before : Extension<"'__thread' before '%0'">;
 def ext_keyword_as_ident : ExtWarn<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-com

[PATCH] D75009: [Diagnostic] Improve discoverability of ftabstop for misleading indentation

2020-02-22 Thread Tyker via Phabricator via cfe-commits
Tyker added a comment.

i tried to find a good message but i don't think i succeeded. any suggestions.


Repository:
  rC Clang

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

https://reviews.llvm.org/D75009



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


[PATCH] D71037: [Diagnostic] Add ftabstop to -Wmisleading-indentation

2020-02-22 Thread Tyker via Phabricator via cfe-commits
Tyker added a comment.

In D71037#1871089 , @efriedma wrote:

> I just ran into this warning, and I think there's a bit of a discoverability 
> problem related to the width of tabs and -ftabstop.  If you have mixed tabs 
> and spaces, and you've correctly specified the tab stop width with -ftabstop, 
> everything works fine.  If you haven't specified -ftabstop, you get a 
> warning, and the issue isn't obvious.  Depending on your editor settings, the 
> code might look fine at first glance, and the warning text doesn't mention 
> -ftabstop at all.  Maybe there's something that could be improved here, if 
> we're printing a warning for two lines with mismatched indentation styles?


i agree that this is not obvious. i added a patch to improve this 
https://reviews.llvm.org/D75009.


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

https://reviews.llvm.org/D71037



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


[PATCH] D75006: Wrap lines for C# property accessors

2020-02-22 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe updated this revision to Diff 246070.
jbcoe added a comment.

Code and test to avoid wrapping accessors with expression body definitions.


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

https://reviews.llvm.org/D75006

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -554,5 +554,24 @@
Style);
 }
 
+TEST_F(FormatTestCSharp, CSharpPropertyAccessors) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+  verifyFormat(R"(//
+int Value { get; set }
+string Name { get; private set }
+string AnotherName { protected get; private set }
+double Sum { get })",
+   Style);
+
+  // Do not wrap expression body definitions.
+  verifyFormat(R"(//
+public string Name {
+  get => _name;
+  set => _name = value;
+}")",
+   Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -292,6 +292,13 @@
   }
 }
 
+// Try to merge a CSharp property declaration like `{ get; private set }`.
+if (Style.isCSharp()) {
+  unsigned CSPA = tryMergeCSharpPropertyAccessor(I, E, Limit);
+  if (CSPA > 0)
+return CSPA;
+}
+
 // Try to merge a function block with left brace unwrapped
 if (TheLine->Last->is(TT_FunctionLBrace) &&
 TheLine->First != TheLine->Last) {
@@ -421,6 +428,53 @@
 return 0;
   }
 
+  unsigned tryMergeCSharpPropertyAccessor(
+  SmallVectorImpl::const_iterator I,
+  SmallVectorImpl::const_iterator E, unsigned /*Limit*/) {
+// Does line start with `{`
+if (I[0]->Last->isNot(TT_FunctionLBrace))
+  return 0;
+
+// Does line start with `[access-modifier] get`
+if (I + 1 == E)
+  return 0;
+auto *GetToken = I[1]->First;
+if (GetToken &&
+GetToken->isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private))
+  GetToken = GetToken->Next;
+if (!GetToken || GetToken->TokenText != "get")
+  return 0;
+// Keep `get => some_code;` on a single line.
+if (GetToken->Next && GetToken->Next->isNot(tok::semi))
+  return 0;
+
+// Does line start with `[access-modifier] set` or `{`
+if (I + 2 == E)
+  return 0;
+auto *SetToken = I[2]->First;
+if (SetToken &&
+SetToken->isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private))
+  SetToken = SetToken->Next;
+
+if (SetToken && SetToken->is(tok::r_brace))
+  return 2;
+
+if (!SetToken || SetToken->TokenText != "set")
+  return 0;
+// Keep `set => some_code;` on a single line.
+if (SetToken->Next)
+  return 0;
+
+// Does line start with `}`
+if (I + 3 == E)
+  return 0;
+auto *RBrace = I[3]->First;
+if (!RBrace || !RBrace->is(tok::r_brace))
+  return 0;
+
+return 3;
+  }
+
   unsigned
   tryMergeSimplePPDirective(SmallVectorImpl::const_iterator I,
 SmallVectorImpl::const_iterator E,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72857: [SYCL] Driver option to enable SYCL mode and select SYCL version

2020-02-22 Thread Alexey Bader via Phabricator via cfe-commits
bader updated this revision to Diff 246072.
bader added a comment.

Rebase.

Any other comments?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72857

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Driver/sycl.c
  clang/test/Frontend/sycl-aux-triple.cpp
  clang/test/Preprocessor/sycl-macro.cpp
  clang/test/SemaSYCL/kernel-attribute.cpp

Index: clang/test/SemaSYCL/kernel-attribute.cpp
===
--- clang/test/SemaSYCL/kernel-attribute.cpp
+++ clang/test/SemaSYCL/kernel-attribute.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl -fsycl-is-device -verify %s
 
 // Only function templates
 [[clang::sycl_kernel]] int gv2 = 0; // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
Index: clang/test/Preprocessor/sycl-macro.cpp
===
--- clang/test/Preprocessor/sycl-macro.cpp
+++ clang/test/Preprocessor/sycl-macro.cpp
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 %s -E -dM | FileCheck %s
-// RUN: %clang_cc1 %s -fsycl-is-device -E -dM | FileCheck --check-prefix=CHECK-SYCL %s
+// RUN: %clang_cc1 %s -fsycl -sycl-std=2017 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
+// RUN: %clang_cc1 %s -fsycl -fsycl-is-device -sycl-std=1.2.1 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
+// RUN: %clang_cc1 %s -fsycl -fsycl-is-device -E -dM | FileCheck --check-prefixes=CHECK-SYCL %s
 
 // CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1
+// CHECK-NOT:#define CL_SYCL_LANGUAGE_VERSION 121
+// CHECK-SYCL-STD:#define CL_SYCL_LANGUAGE_VERSION 121
 // CHECK-SYCL:#define __SYCL_DEVICE_ONLY__ 1
Index: clang/test/Frontend/sycl-aux-triple.cpp
===
--- clang/test/Frontend/sycl-aux-triple.cpp
+++ clang/test/Frontend/sycl-aux-triple.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 %s -triple spir -aux-triple x86_64-unknown-linux-gnu -E -dM | FileCheck %s
-// RUN: %clang_cc1 %s -fsycl-is-device -triple spir -aux-triple x86_64-unknown-linux-gnu -E -dM | FileCheck --check-prefix=CHECK-SYCL %s
+// RUN: %clang_cc1 %s -fsycl -fsycl-is-device -triple spir -aux-triple x86_64-unknown-linux-gnu -E -dM | FileCheck --check-prefix=CHECK-SYCL %s
 
 // CHECK-NOT:#define __x86_64__ 1
 // CHECK-SYCL:#define __x86_64__ 1
Index: clang/test/Driver/sycl.c
===
--- clang/test/Driver/sycl.c
+++ clang/test/Driver/sycl.c
@@ -1,10 +1,20 @@
 // RUN: %clang -### -fsycl -c %s 2>&1 | FileCheck %s --check-prefix=ENABLED
 // RUN: %clang -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -fsycl -sycl-std=1.2.1 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -fsycl -sycl-std=121 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -fsycl -sycl-std=2017 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -fsycl -sycl-std=sycl-1.2.1 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
 // RUN: %clang -### -fno-sycl -fsycl %s 2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -sycl-std=2017 %s 2>&1 | FileCheck %s --check-prefix=DISABLED
 // RUN: %clangxx -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=ENABLED
 // RUN: %clangxx -### -fno-sycl %s 2>&1 | FileCheck %s --check-prefix=DISABLED
 // RUN: %clangxx -### -fsycl -fno-sycl %s 2>&1 | FileCheck %s --check-prefix=DISABLED
 // RUN: %clangxx -### %s 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: %clang_cl -### -fsycl -sycl-std=2017 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang_cl -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang_cl -### %s 2>&1 | FileCheck %s --check-prefix=DISABLED
 
 // ENABLED: "-cc1"{{.*}} "-fsycl-is-device"
+// ENABLED-SAME: "-sycl-std={{[-.sycl0-9]+}}"
 // DISABLED-NOT: "-fsycl-is-device"
+// DISABLED-NOT: "-sycl-std="
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -460,6 +460,13 @@
 if (LangOpts.FastRelaxedMath)
   Builder.defineMacro("__FAST_RELAXED_MATH__");
   }
+
+  if (LangOpts.SYCL) {
+// SYCL Version is set to a value when building SYCL applications
+if (LangOpts.SYCLVersion == 2017)
+  Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
+  }
+
   // Not "standard" per se, but available even with the -undef flag.
   if (LangOpts.AsmPreprocessor)
 Builder.defineMacro("__ASSEMBLER__");
Index: clang/lib/Frontend/CompilerInvocation.cpp
=

[PATCH] D74935: [LangRef][AliasAnalysis] Clarify `noalias` affects only modified objects

2020-02-22 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle added a comment.

In D74935#1887245 , @efriedma wrote:

> In D74935#1886020 , @nhaehnle wrote:
>
> > I find this phrasing pretty confusing. How about the following:
> >
> > > This indicates that objects accessed via pointer values based on the 
> > > argument or return value are not **modified**, during the execution of 
> > > the function, via pointer values not based on the argument or return 
> > > value. [...]
>
>
> This isn't equivalent.  If the memory location is modified, we want to forbid 
> both reads and writes that aren't based on the noalias pointer.


Oh I see. So another way to put this is:

- If an object is accessed via a pointer based on the noalias argument, then it 
cannot be modified via other pointer values.
- If an object is modified via a pointer based on the noalias argument, then it 
cannot be accessed via other pointer values in any way.

Correct? I think it's useful to spell it out like this, because it makes the 
alias implications clearer (at least to me).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74935



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


[PATCH] D72857: [SYCL] Driver option to enable SYCL mode and select SYCL version

2020-02-22 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

If no other comments, LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72857



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


[PATCH] D74860: [Sema] Fix pointer-to-int-cast diagnostic for _Bool

2020-02-22 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 246082.
Mordante added a comment.

Added some C++ tests for similar c-style casts.


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

https://reviews.llvm.org/D74860

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/MicrosoftExtensions.c
  clang/test/Sema/cast.c
  clang/test/SemaCXX/cstyle-cast.cpp


Index: clang/test/SemaCXX/cstyle-cast.cpp
===
--- clang/test/SemaCXX/cstyle-cast.cpp
+++ clang/test/SemaCXX/cstyle-cast.cpp
@@ -178,6 +178,11 @@
   fnptr fnp = (fnptr)(l);
   (void)(char)(fnp); // expected-error {{cast from pointer to smaller type 
'char' loses information}}
   (void)(long)(fnp);
+
+  (void)(bool)((void*)0);
+  (void)(bool)((int*)0);
+  (void)(char)((void*)0); // expected-error {{cast from pointer to smaller 
type 'char' loses information}}
+  (void)(char)((int*)0);  // expected-error {{cast from pointer to smaller 
type 'char' loses information}}
 }
 
 void pointer_conversion()
Index: clang/test/Sema/cast.c
===
--- clang/test/Sema/cast.c
+++ clang/test/Sema/cast.c
@@ -151,7 +151,7 @@
 }
 
 void testVoidPtr(VoidPtr v) {
-  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' 
(aka '_Bool') from 'VoidPtr' (aka 'void *')}}
+  (void)(Bool) v;
   (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 
'int') from 'VoidPtr' (aka 'void *')}}
   (void) (Long) v;
   (void) (VoidPtr) v;
@@ -160,12 +160,12 @@
   // from other -Wpointer-to-int-cast warnings.
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
-  (void) (Bool) v; // no-warning
+  (void)(Int) v; // no-warning
 #pragma clang diagnostic pop
 }
 
 void testCharPtr(CharPtr v) {
-  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' 
(aka '_Bool') from 'CharPtr' (aka 'char *')}}
+  (void)(Bool) v;
   (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 
'int') from 'CharPtr' (aka 'char *')}}
   (void) (Long) v;
   (void) (VoidPtr) v;
@@ -174,7 +174,7 @@
   // from other -Wpointer-to-int-cast warnings.
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
-  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' 
(aka '_Bool') from 'CharPtr' (aka 'char *')}}
+  (void)(Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 
'int') from 'CharPtr' (aka 'char *')}}
 #pragma clang diagnostic pop
 }
 
Index: clang/test/Sema/MicrosoftExtensions.c
===
--- clang/test/Sema/MicrosoftExtensions.c
+++ clang/test/Sema/MicrosoftExtensions.c
@@ -99,7 +99,7 @@
sh = (short)ptr; // expected-warning{{cast to smaller integer type 'short' 
from 'char *' is a Microsoft extension}}
 
// This is valid ISO C.
-   _Bool b = (_Bool)ptr; // expected-warning{{cast to smaller integer type 
'_Bool' from 'char *' is a Microsoft extension}}
+   _Bool b = (_Bool)ptr;
 }
 
 typedef struct {
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2764,7 +2764,8 @@
 }
 
 if ((Self.Context.getTypeSize(SrcType) >
- Self.Context.getTypeSize(DestType))) {
+ Self.Context.getTypeSize(DestType)) &&
+!DestType->isBooleanType()) {
   // C 6.3.2.3p6: Any pointer type may be converted to an integer type.
   // Except as previously specified, the result is implementation-defined.
   // If the result cannot be represented in the integer type, the behavior


Index: clang/test/SemaCXX/cstyle-cast.cpp
===
--- clang/test/SemaCXX/cstyle-cast.cpp
+++ clang/test/SemaCXX/cstyle-cast.cpp
@@ -178,6 +178,11 @@
   fnptr fnp = (fnptr)(l);
   (void)(char)(fnp); // expected-error {{cast from pointer to smaller type 'char' loses information}}
   (void)(long)(fnp);
+
+  (void)(bool)((void*)0);
+  (void)(bool)((int*)0);
+  (void)(char)((void*)0); // expected-error {{cast from pointer to smaller type 'char' loses information}}
+  (void)(char)((int*)0);  // expected-error {{cast from pointer to smaller type 'char' loses information}}
 }
 
 void pointer_conversion()
Index: clang/test/Sema/cast.c
===
--- clang/test/Sema/cast.c
+++ clang/test/Sema/cast.c
@@ -151,7 +151,7 @@
 }
 
 void testVoidPtr(VoidPtr v) {
-  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' (aka '_Bool') from 'VoidPtr' (aka 'void *')}}
+  (void)(Bool) v;
   (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'VoidPtr' (aka 'void *')}}
   (void) (Long) v;
   (void) (VoidPtr) v;
@@ -160,12 +160,12 @@
   // from other -Wpointer-to-int-cast warnings.
 #

[PATCH] D74860: [Sema] Fix pointer-to-int-cast diagnostic for _Bool

2020-02-22 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D74860#1883415 , @rjmccall wrote:

> Can we test the same thing in C++?


I'll add some tests, but C++ uses a different codepath for c-style casts.

In D74860#1883480 , @nickdesaulniers 
wrote:

> Also, make sure to run `git-clang-format HEAD~` on the patch, as the linter 
> suggests. Thanks for the patch.


I'd rather not run it on the tests. The new code uses the same style as the 
surrounding code. If wanted I can run the formatter on the changed test files 
and commit them separately.


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

https://reviews.llvm.org/D74860



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


[PATCH] D74860: [Sema] Fix pointer-to-int-cast diagnostic for _Bool

2020-02-22 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

In D74860#1888024 , @Mordante wrote:

> In D74860#1883415 , @rjmccall wrote:
>
> > Can we test the same thing in C++?
>
>
> I'll add some tests, but C++ uses a different codepath for c-style casts.


Since the warning applies in both modes, we generally need to be testing all 
the cases in both.  The implementation being significantly different is a 
*better* reason to do this.

Anyway, thanks, LGTM.


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

https://reviews.llvm.org/D74860



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


[clang] 56eb15a - [Sema] Fix pointer-to-int-cast diagnostic for _Bool

2020-02-22 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2020-02-22T19:39:49+01:00
New Revision: 56eb15a1c71061043d50aa669407816bc08dfb5d

URL: 
https://github.com/llvm/llvm-project/commit/56eb15a1c71061043d50aa669407816bc08dfb5d
DIFF: 
https://github.com/llvm/llvm-project/commit/56eb15a1c71061043d50aa669407816bc08dfb5d.diff

LOG: [Sema] Fix pointer-to-int-cast diagnostic for _Bool

The diagnostic added in D72231 also shows a diagnostic when casting to a
_Bool. This is unwanted. This patch removes the diagnostic for _Bool types.

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

Added: 


Modified: 
clang/lib/Sema/SemaCast.cpp
clang/test/Sema/MicrosoftExtensions.c
clang/test/Sema/cast.c
clang/test/SemaCXX/cstyle-cast.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index a89cc4be53aa..2b3b60e6bde4 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -2764,7 +2764,8 @@ void CastOperation::CheckCStyleCast() {
 }
 
 if ((Self.Context.getTypeSize(SrcType) >
- Self.Context.getTypeSize(DestType))) {
+ Self.Context.getTypeSize(DestType)) &&
+!DestType->isBooleanType()) {
   // C 6.3.2.3p6: Any pointer type may be converted to an integer type.
   // Except as previously specified, the result is implementation-defined.
   // If the result cannot be represented in the integer type, the behavior

diff  --git a/clang/test/Sema/MicrosoftExtensions.c 
b/clang/test/Sema/MicrosoftExtensions.c
index 6e784bfe6102..8e7087a57991 100644
--- a/clang/test/Sema/MicrosoftExtensions.c
+++ b/clang/test/Sema/MicrosoftExtensions.c
@@ -99,7 +99,7 @@ void pointer_to_integral_type_conv(char* ptr) {
sh = (short)ptr; // expected-warning{{cast to smaller integer type 'short' 
from 'char *' is a Microsoft extension}}
 
// This is valid ISO C.
-   _Bool b = (_Bool)ptr; // expected-warning{{cast to smaller integer type 
'_Bool' from 'char *' is a Microsoft extension}}
+   _Bool b = (_Bool)ptr;
 }
 
 typedef struct {

diff  --git a/clang/test/Sema/cast.c b/clang/test/Sema/cast.c
index f16064d78dd9..0c4fc7d129fc 100644
--- a/clang/test/Sema/cast.c
+++ b/clang/test/Sema/cast.c
@@ -151,7 +151,7 @@ void testCDouble(CDouble v) {
 }
 
 void testVoidPtr(VoidPtr v) {
-  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' 
(aka '_Bool') from 'VoidPtr' (aka 'void *')}}
+  (void)(Bool) v;
   (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 
'int') from 'VoidPtr' (aka 'void *')}}
   (void) (Long) v;
   (void) (VoidPtr) v;
@@ -160,12 +160,12 @@ void testVoidPtr(VoidPtr v) {
   // from other -Wpointer-to-int-cast warnings.
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
-  (void) (Bool) v; // no-warning
+  (void)(Int) v; // no-warning
 #pragma clang diagnostic pop
 }
 
 void testCharPtr(CharPtr v) {
-  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' 
(aka '_Bool') from 'CharPtr' (aka 'char *')}}
+  (void)(Bool) v;
   (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 
'int') from 'CharPtr' (aka 'char *')}}
   (void) (Long) v;
   (void) (VoidPtr) v;
@@ -174,7 +174,7 @@ void testCharPtr(CharPtr v) {
   // from other -Wpointer-to-int-cast warnings.
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
-  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' 
(aka '_Bool') from 'CharPtr' (aka 'char *')}}
+  (void)(Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 
'int') from 'CharPtr' (aka 'char *')}}
 #pragma clang diagnostic pop
 }
 

diff  --git a/clang/test/SemaCXX/cstyle-cast.cpp 
b/clang/test/SemaCXX/cstyle-cast.cpp
index 2327d7b51d97..32a6e205f769 100644
--- a/clang/test/SemaCXX/cstyle-cast.cpp
+++ b/clang/test/SemaCXX/cstyle-cast.cpp
@@ -178,6 +178,11 @@ void integral_conversion()
   fnptr fnp = (fnptr)(l);
   (void)(char)(fnp); // expected-error {{cast from pointer to smaller type 
'char' loses information}}
   (void)(long)(fnp);
+
+  (void)(bool)((void*)0);
+  (void)(bool)((int*)0);
+  (void)(char)((void*)0); // expected-error {{cast from pointer to smaller 
type 'char' loses information}}
+  (void)(char)((int*)0);  // expected-error {{cast from pointer to smaller 
type 'char' loses information}}
 }
 
 void pointer_conversion()



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


[PATCH] D74860: [Sema] Fix pointer-to-int-cast diagnostic for _Bool

2020-02-22 Thread Mark de Wever via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG56eb15a1c710: [Sema] Fix pointer-to-int-cast diagnostic for 
_Bool (authored by Mordante).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74860

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/MicrosoftExtensions.c
  clang/test/Sema/cast.c
  clang/test/SemaCXX/cstyle-cast.cpp


Index: clang/test/SemaCXX/cstyle-cast.cpp
===
--- clang/test/SemaCXX/cstyle-cast.cpp
+++ clang/test/SemaCXX/cstyle-cast.cpp
@@ -178,6 +178,11 @@
   fnptr fnp = (fnptr)(l);
   (void)(char)(fnp); // expected-error {{cast from pointer to smaller type 
'char' loses information}}
   (void)(long)(fnp);
+
+  (void)(bool)((void*)0);
+  (void)(bool)((int*)0);
+  (void)(char)((void*)0); // expected-error {{cast from pointer to smaller 
type 'char' loses information}}
+  (void)(char)((int*)0);  // expected-error {{cast from pointer to smaller 
type 'char' loses information}}
 }
 
 void pointer_conversion()
Index: clang/test/Sema/cast.c
===
--- clang/test/Sema/cast.c
+++ clang/test/Sema/cast.c
@@ -151,7 +151,7 @@
 }
 
 void testVoidPtr(VoidPtr v) {
-  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' 
(aka '_Bool') from 'VoidPtr' (aka 'void *')}}
+  (void)(Bool) v;
   (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 
'int') from 'VoidPtr' (aka 'void *')}}
   (void) (Long) v;
   (void) (VoidPtr) v;
@@ -160,12 +160,12 @@
   // from other -Wpointer-to-int-cast warnings.
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
-  (void) (Bool) v; // no-warning
+  (void)(Int) v; // no-warning
 #pragma clang diagnostic pop
 }
 
 void testCharPtr(CharPtr v) {
-  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' 
(aka '_Bool') from 'CharPtr' (aka 'char *')}}
+  (void)(Bool) v;
   (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 
'int') from 'CharPtr' (aka 'char *')}}
   (void) (Long) v;
   (void) (VoidPtr) v;
@@ -174,7 +174,7 @@
   // from other -Wpointer-to-int-cast warnings.
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
-  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' 
(aka '_Bool') from 'CharPtr' (aka 'char *')}}
+  (void)(Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 
'int') from 'CharPtr' (aka 'char *')}}
 #pragma clang diagnostic pop
 }
 
Index: clang/test/Sema/MicrosoftExtensions.c
===
--- clang/test/Sema/MicrosoftExtensions.c
+++ clang/test/Sema/MicrosoftExtensions.c
@@ -99,7 +99,7 @@
sh = (short)ptr; // expected-warning{{cast to smaller integer type 'short' 
from 'char *' is a Microsoft extension}}
 
// This is valid ISO C.
-   _Bool b = (_Bool)ptr; // expected-warning{{cast to smaller integer type 
'_Bool' from 'char *' is a Microsoft extension}}
+   _Bool b = (_Bool)ptr;
 }
 
 typedef struct {
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2764,7 +2764,8 @@
 }
 
 if ((Self.Context.getTypeSize(SrcType) >
- Self.Context.getTypeSize(DestType))) {
+ Self.Context.getTypeSize(DestType)) &&
+!DestType->isBooleanType()) {
   // C 6.3.2.3p6: Any pointer type may be converted to an integer type.
   // Except as previously specified, the result is implementation-defined.
   // If the result cannot be represented in the integer type, the behavior


Index: clang/test/SemaCXX/cstyle-cast.cpp
===
--- clang/test/SemaCXX/cstyle-cast.cpp
+++ clang/test/SemaCXX/cstyle-cast.cpp
@@ -178,6 +178,11 @@
   fnptr fnp = (fnptr)(l);
   (void)(char)(fnp); // expected-error {{cast from pointer to smaller type 'char' loses information}}
   (void)(long)(fnp);
+
+  (void)(bool)((void*)0);
+  (void)(bool)((int*)0);
+  (void)(char)((void*)0); // expected-error {{cast from pointer to smaller type 'char' loses information}}
+  (void)(char)((int*)0);  // expected-error {{cast from pointer to smaller type 'char' loses information}}
 }
 
 void pointer_conversion()
Index: clang/test/Sema/cast.c
===
--- clang/test/Sema/cast.c
+++ clang/test/Sema/cast.c
@@ -151,7 +151,7 @@
 }
 
 void testVoidPtr(VoidPtr v) {
-  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' (aka '_Bool') from 'VoidPtr' (aka 'void *')}}
+  (void)(Bool) v;
   (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'VoidPtr' (aka 'void *')}}
   (void) (Long)

[PATCH] D72103: [Sema] Avoid using an invalid InsertPos

2020-02-22 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

Friendly ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72103



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


[PATCH] D75012: [ReleaseNotes] Mention -fmacro-prefix-map and -ffile-prefix-map.

2020-02-22 Thread Peter Wu via Phabricator via cfe-commits
Lekensteyn created this revision.
Lekensteyn added reviewers: dankm, MaskRay, hans.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75012

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -138,6 +138,12 @@
   please let us know if you encounter a situation where you need to specify 
this
   flag for correct program behavior.
 
+- ``-fmacro-prefix-map=OLD=NEW`` allows a directory prefix ``OLD`` in
+  ``__FILE__`` preprocessor macros to be substituted for ``NEW``. This helps
+  with reproducible builds that are location independent. The new
+  ``-ffile-prefix-map`` option is equivalent to specifying both
+  ``-fdebug-prefix-map`` and ``-fmacro-prefix-map``.
+
 Deprecated Compiler Flags
 -
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -138,6 +138,12 @@
   please let us know if you encounter a situation where you need to specify this
   flag for correct program behavior.
 
+- ``-fmacro-prefix-map=OLD=NEW`` allows a directory prefix ``OLD`` in
+  ``__FILE__`` preprocessor macros to be substituted for ``NEW``. This helps
+  with reproducible builds that are location independent. The new
+  ``-ffile-prefix-map`` option is equivalent to specifying both
+  ``-fdebug-prefix-map`` and ``-fmacro-prefix-map``.
+
 Deprecated Compiler Flags
 -
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75009: [Diagnostic] Improve discoverability of ftabstop for misleading indentation

2020-02-22 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:67
+def note_misleading_indentation_tab_space_mix : Note<
+  "there is a mix of tabs spaces; the tab size (-ftabstop=X) is set to %0">;
 

Maybe "assuming tabstops every %0 spaces (override with -ftabstop=)"



Repository:
  rC Clang

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

https://reviews.llvm.org/D75009



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


[PATCH] D75012: [ReleaseNotes] Mention -fmacro-prefix-map and -ffile-prefix-map.

2020-02-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:142
+- ``-fmacro-prefix-map=OLD=NEW`` allows a directory prefix ``OLD`` in
+  ``__FILE__`` preprocessor macros to be substituted for ``NEW``. This helps
+  with reproducible builds that are location independent. The new

It affects `__FILE__` (C99) `__BASE_FILE__` (GNU extension) and `__FILE_NAME__` 
(clang extension).

Should such change be committed directly to the release/10.x branch by @hans ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75012



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


[PATCH] D74935: [LangRef][AliasAnalysis] Clarify `noalias` affects only modified objects

2020-02-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 246088.
jdoerfert added a comment.

Update language to memory locations instead of objects


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74935

Files:
  llvm/docs/LangRef.rst


Index: llvm/docs/LangRef.rst
===
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -1107,14 +1107,16 @@
 .. _noalias:
 
 ``noalias``
-This indicates that objects accessed via pointer values
+This indicates that memory locations accessed via pointer values
 :ref:`based ` on the argument or return value are not also
 accessed, during the execution of the function, via pointer values not
-*based* on the argument or return value. The attribute on a return value
-also has additional semantics described below. The caller shares the
-responsibility with the callee for ensuring that these requirements are 
met.
-For further details, please see the discussion of the NoAlias response in
-:ref:`alias analysis `.
+*based* on the argument or return value. This guarantee only holds for
+memory locations that are *modified*, by any means, during the execution of
+the function. The attribute on a return value also has additional semantics
+described below. The caller shares the responsibility with the callee for
+ensuring that these requirements are met.  For further details, please see
+the discussion of the NoAlias response in :ref:`alias analysis `.
 
 Note that this definition of ``noalias`` is intentionally similar
 to the definition of ``restrict`` in C99 for function arguments.


Index: llvm/docs/LangRef.rst
===
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -1107,14 +1107,16 @@
 .. _noalias:
 
 ``noalias``
-This indicates that objects accessed via pointer values
+This indicates that memory locations accessed via pointer values
 :ref:`based ` on the argument or return value are not also
 accessed, during the execution of the function, via pointer values not
-*based* on the argument or return value. The attribute on a return value
-also has additional semantics described below. The caller shares the
-responsibility with the callee for ensuring that these requirements are met.
-For further details, please see the discussion of the NoAlias response in
-:ref:`alias analysis `.
+*based* on the argument or return value. This guarantee only holds for
+memory locations that are *modified*, by any means, during the execution of
+the function. The attribute on a return value also has additional semantics
+described below. The caller shares the responsibility with the callee for
+ensuring that these requirements are met.  For further details, please see
+the discussion of the NoAlias response in :ref:`alias analysis `.
 
 Note that this definition of ``noalias`` is intentionally similar
 to the definition of ``restrict`` in C99 for function arguments.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D74935: [LangRef][AliasAnalysis] Clarify `noalias` affects only modified objects

2020-02-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D74935#1887960 , @nhaehnle wrote:

> In D74935#1887245 , @efriedma wrote:
>
> > In D74935#1886020 , @nhaehnle 
> > wrote:
> >
> > > I find this phrasing pretty confusing. How about the following:
> > >
> > > > This indicates that objects accessed via pointer values based on the 
> > > > argument or return value are not **modified**, during the execution of 
> > > > the function, via pointer values not based on the argument or return 
> > > > value. [...]
> >
> >
> > This isn't equivalent.  If the memory location is modified, we want to 
> > forbid both reads and writes that aren't based on the noalias pointer.
>
>
> Oh I see. So another way to put this is:
>
> - If an object is accessed via a pointer based on the noalias argument, then 
> it cannot be modified via other pointer values.
> - If an object is modified via a pointer based on the noalias argument, then 
> it cannot be accessed via other pointer values in any way.
>
>   Correct? I think it's useful to spell it out like this, because it makes 
> the alias implications clearer (at least to me).


I think it might make sense to actually add a page with examples and more 
details. I don't have a strong opinion on the wording for this short paragraph 
though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74935



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


[PATCH] D74813: [RFC] Add hash of block contents to function block names

2020-02-22 Thread Alex Borcan via Phabricator via cfe-commits
alexbdv added a comment.

@dexonsmith I did a benchmark with the worst case example I can come up with - 
1000 regular functions and 1000 blocks : 
https://paste.ofcode.org/CFU6b46nuAA6ymxUEpkzka
I didn't manage to measure any performance decrease (the performance decrease 
was within the noise of repeated runs) - so seems the hashing is insignificant 
compile-time-wise even in worst case scenario (where most of the code is in 
function blocks).
And here is the actual text that is being hashed - the textual representation 
of the AST, not the IR: https://paste.ofcode.org/bfMzhbvHz9HRT7mVMe48Mx


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74813



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


[PATCH] D74941: [OpenMP] `omp begin/end declare variant` - part 1, parsing

2020-02-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 246094.
jdoerfert added a comment.

minor adjustment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74941

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant.c
  clang/test/OpenMP/begin-declare-variant_no_end_for_matching_selector.c
  clang/test/OpenMP/begin_declare_variant_messages.c
  clang/test/OpenMP/declare_variant_begin_messages.c
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -91,6 +91,8 @@
 __OMP_DIRECTIVE_EXT(master_taskloop_simd, "master taskloop simd")
 __OMP_DIRECTIVE_EXT(parallel_master_taskloop_simd,
 "parallel master taskloop simd")
+__OMP_DIRECTIVE_EXT(begin_declare_variant, "begin declare variant")
+__OMP_DIRECTIVE_EXT(end_declare_variant, "end declare variant")
 
 // Has to be the last because Clang implicitly expects it to be.
 __OMP_DIRECTIVE(unknown)
Index: clang/test/OpenMP/declare_variant_begin_messages.c
===
--- /dev/null
+++ clang/test/OpenMP/declare_variant_begin_messages.c
@@ -0,0 +1,117 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -verify -fopenmp -x c -std=c99 -fms-extensions -Wno-pragma-pack %s
+
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -verify -fopenmp-simd -x c -std=c99 -fms-extensions -Wno-pragma-pack %s
+
+
+#pragma omp begin // expected-error {{expected an OpenMP directive}}
+#pragma omp end declare variant
+#pragma omp begin declare // expected-error {{expected an OpenMP directive}}
+#pragma omp end declare variant
+#pragma omp begin variant // expected-error {{expected an OpenMP directive}}
+#pragma omp end declare variant
+#pragma omp variant begin // expected-error {{expected an OpenMP directive}}
+#pragma omp declare variant end // expected-error {{function declaration is expected after 'declare variant' directive}}
+#pragma omp begin declare variant // expected-error {{expected 'match' clause on 'omp declare variant' directive}}
+#pragma omp end declare variant
+
+int foo(void);
+const int var;
+
+#pragma omp begin declare variant // expected-error {{expected 'match' clause on 'omp declare variant' directive}}
+#pragma omp end declare variant
+#pragma omp begin declare variant xxx // expected-error {{expected 'match' clause on 'omp declare variant' directive}}
+#pragma omp end declare variant
+#pragma omp begin declare variant match // expected-error {{expected '(' after 'match'}}
+#pragma omp end declare variant
+#pragma omp begin declare variant match( // expected-error {{expected ')'}} expected-warning {{expected identifier or string literal describing a context set; set skipped}} expected-note {{context set options are: 'construct' 'device' 'implementation' 'user'}} expected-note {{the ignored set spans until here}} expected-note {{to match this '('}}
+#pragma omp end declare variant
+#pragma omp begin declare variant match() // expected-warning {{expected identifier or string literal describing a context set; set skipped}} expected-note {{context set options are: 'construct' 'device' 'implementation' 'user'}} expected-note {{the ignored set spans until here}}
+#pragma omp end declare variant
+#pragma omp begin declare variant match(xxx) // expected-warning {{'xxx' is not a valid context set in a `declare variant`; set ignored}} expected-note {{context set options are: 'construct' 'device' 'implementation' 'user'}} expected-note {{the ignored set spans until here}}
+#pragma omp end declare variant
+#pragma omp begin declare variant match(xxx=) // expected-warning {{'xxx' is not a valid context set in a `declare variant`; set ignored}} expected-note {{context set options are: 'construct' 'device' 'implementation' 'user'}} expected-note {{the ignored set spans until here}}
+#pragma omp end declare variant
+#pragma omp begin declare variant match(xxx=yyy) // expected-warning {{'xxx' is not a valid context set in a `declare variant`; set ignored}} expected-note {{context set options are: 'construct' 'device' 'implementation' 'user'}} expected-note {{the ignored set spans until here}}
+#pragma omp end declare variant
+#pragma omp begin declare variant match(xxx=yyy}) // expected-error {{expected ')'}} expected-warning {{'xxx' is not a valid context set in a `declare variant`; set ignored}} expected-note {{context set options are: 'construct' 'device' 'implementation' 'user'}} ex

[PATCH] D74643: [Parse] Consider attributes in `TryParsePtrOperatorSeq`.

2020-02-22 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.



Comment at: clang/include/clang/Parse/Parser.h:2444
 
+  /// Try to skip a possibly empty sequence of 'attribute-specifier' without of
+  /// full validation of the syntactic structure of attributes.

Stray "of' here. (And an 's' after "attribute-specifier" would improve 
readability.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74643



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


[PATCH] D74643: [Parse] Consider attributes in `TryParsePtrOperatorSeq`.

2020-02-22 Thread Michele Scandale via Phabricator via cfe-commits
michele.scandale updated this revision to Diff 246095.
michele.scandale added a comment.

Fixed comment wording + rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74643

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseTentative.cpp
  clang/test/CXX/dcl.decl/p4-0x.cpp

Index: clang/test/CXX/dcl.decl/p4-0x.cpp
===
--- clang/test/CXX/dcl.decl/p4-0x.cpp
+++ clang/test/CXX/dcl.decl/p4-0x.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 struct X {
   void f() &;
@@ -7,3 +6,11 @@
 };
 
 void (X::*pmf)() & = &X::f;
+
+void fn() {
+  void (*[[attr]] fn_ptr)() = &fn; // expected-warning{{unknown attribute 'attr' ignored}}
+  void (*[[attrA]] *[[attrB]] fn_ptr_ptr)() = &fn_ptr; // expected-warning{{unknown attribute 'attrA' ignored}} expected-warning{{unknown attribute 'attrB' ignored}}
+
+  void (&[[attr]] fn_lref)() = fn; // expected-warning{{unknown attribute 'attr' ignored}}
+  void (&&[[attr]] fn_rref)() = fn; // expected-warning{{unknown attribute 'attr' ignored}}
+}
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -186,21 +186,8 @@
 ConsumeToken();
 
 // Skip attributes.
-while (Tok.isOneOf(tok::l_square, tok::kw___attribute, tok::kw___declspec,
-   tok::kw_alignas)) {
-  if (Tok.is(tok::l_square)) {
-ConsumeBracket();
-if (!SkipUntil(tok::r_square))
-  return TPResult::Error;
-  } else {
-ConsumeToken();
-if (Tok.isNot(tok::l_paren))
-  return TPResult::Error;
-ConsumeParen();
-if (!SkipUntil(tok::r_paren))
-  return TPResult::Error;
-  }
-}
+if (!TrySkipAttributes())
+  return TPResult::Error;
 
 if (TryAnnotateOptionalCXXScopeToken())
   return TPResult::Error;
@@ -781,6 +768,32 @@
   return CAK_NotAttributeSpecifier;
 }
 
+bool Parser::TrySkipAttributes() {
+  while (Tok.isOneOf(tok::l_square, tok::kw___attribute, tok::kw___declspec,
+ tok::kw_alignas)) {
+if (Tok.is(tok::l_square)) {
+  ConsumeBracket();
+  if (Tok.isNot(tok::l_square))
+return false;
+  ConsumeBracket();
+  if (!SkipUntil(tok::r_square) || Tok.isNot(tok::r_square))
+return false;
+  // Note that explicitly checking for `[[` and `]]` allows to fail as
+  // expected in the case of the Objective-C message send syntax.
+  ConsumeBracket();
+} else {
+  ConsumeToken();
+  if (Tok.isNot(tok::l_paren))
+return false;
+  ConsumeParen();
+  if (!SkipUntil(tok::r_paren))
+return false;
+}
+  }
+
+  return true;
+}
+
 Parser::TPResult Parser::TryParsePtrOperatorSeq() {
   while (true) {
 if (TryAnnotateOptionalCXXScopeToken(true))
@@ -790,6 +803,11 @@
 (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::star))) {
   // ptr-operator
   ConsumeAnyToken();
+
+  // Skip attributes.
+  if (!TrySkipAttributes())
+return TPResult::Error;
+
   while (Tok.isOneOf(tok::kw_const, tok::kw_volatile, tok::kw_restrict,
  tok::kw__Nonnull, tok::kw__Nullable,
  tok::kw__Null_unspecified))
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2441,6 +2441,10 @@
   TPResult TryParseBracketDeclarator();
   TPResult TryConsumeDeclarationSpecifier();
 
+  /// Try to skip a possibly empty sequence of 'attribute-specifier's without
+  /// full validation of the syntactic structure of attributes.
+  bool TrySkipAttributes();
+
 public:
   TypeResult ParseTypeName(SourceRange *Range = nullptr,
DeclaratorContext Context
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits