[clang] [clang] Correct Microsoft mangling of lifetime extended temporary objects. (PR #85529)

2024-03-18 Thread David Majnemer via cfe-commits


@@ -54,6 +54,12 @@ ABI Changes in This Version
   inline member function that contains a static local variable with a dynamic
   initializer is declared with ``__declspec(dllimport)``. (#GH83616).
 
+- Fixed Microsoft name mangling of lifetime extended temporary objects. This
+  change corrects missing back reference registrations that could result in
+  incorrect back reference indexes and suprising demangled name results. Since
+  MSVC uses a different mangling for these objects, compatibility is not 
affected.
+  (#GH85423).

majnemer wrote:

LGTM

https://github.com/llvm/llvm-project/pull/85529
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][MSVC] Correct mangling of thread-safe static initialization variables. (PR #85300)

2024-03-14 Thread David Majnemer via cfe-commits


@@ -47,6 +47,12 @@ C++ Specific Potentially Breaking Changes
 
 ABI Changes in This Version
 ---
+- Fixed Microsoft name mangling of implicitly defined variables used for thread
+  safe static initialization of static local variables. This change resolves
+  incompatibilities with code compiled by MSVC but might introduce
+  incompatibilities with code compiled by earlier versions of Clang when an
+  inline member function that contains a static local variable with a dynamic
+  initializer is declared with ``__declspec(dllimport)``. (#GH83616).

majnemer wrote:

The only thing we try to do is respect the version of MSVC we are attempting to 
be compatible with.

https://github.com/llvm/llvm-project/pull/85300
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2f086f2 - [APFloat] Add E4M3B11FNUZ

2023-03-24 Thread David Majnemer via cfe-commits

Author: David Majnemer
Date: 2023-03-24T20:06:40Z
New Revision: 2f086f265bf97fe6543fb199f4ef874ca3522479

URL: 
https://github.com/llvm/llvm-project/commit/2f086f265bf97fe6543fb199f4ef874ca3522479
DIFF: 
https://github.com/llvm/llvm-project/commit/2f086f265bf97fe6543fb199f4ef874ca3522479.diff

LOG: [APFloat] Add E4M3B11FNUZ

X. Sun et al. (https://dl.acm.org/doi/10./3454287.3454728) published
a paper showing that an FP format with 4 bits of exponent, 3 bits of
significand and an exponent bias of 11 would work quite well for ML
applications.

Google hardware supports a variant of this format where 0x80 is used to
represent NaN, as in the Float8E4M3FNUZ format. Just like the
Float8E4M3FNUZ format, this format does not support -0 and values which
would map to it will become +0.

This format is proposed for inclusion in OpenXLA's StableHLO dialect: 
https://github.com/openxla/stablehlo/pull/1308

As part of inclusion in that dialect, APFloat needs to know how to
handle this format.

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

Added: 


Modified: 
clang/lib/AST/MicrosoftMangle.cpp
llvm/include/llvm/ADT/APFloat.h
llvm/lib/Support/APFloat.cpp
llvm/unittests/ADT/APFloatTest.cpp
mlir/include/mlir-c/BuiltinTypes.h
mlir/include/mlir/IR/Builders.h
mlir/include/mlir/IR/BuiltinTypes.h
mlir/include/mlir/IR/BuiltinTypes.td
mlir/include/mlir/IR/OpBase.td
mlir/include/mlir/IR/Types.h
mlir/lib/AsmParser/TokenKinds.def
mlir/lib/AsmParser/TypeParser.cpp
mlir/lib/Bindings/Python/IRTypes.cpp
mlir/lib/CAPI/IR/BuiltinTypes.cpp
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/IR/Builders.cpp
mlir/lib/IR/BuiltinTypes.cpp
mlir/lib/IR/MLIRContext.cpp
mlir/lib/IR/Types.cpp
mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
mlir/test/IR/attribute.mlir
mlir/test/python/ir/builtin_types.py
mlir/utils/lldb-scripts/mlirDataFormatters.py

Removed: 




diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index b8a916a72f750..d8c837bcade02 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -845,6 +845,7 @@ void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat 
Number) {
   case APFloat::S_Float8E4M3FN:
   case APFloat::S_Float8E5M2FNUZ:
   case APFloat::S_Float8E4M3FNUZ:
+  case APFloat::S_Float8E4M3B11FNUZ:
 llvm_unreachable("Tried to mangle unexpected APFloat semantics");
   }
 

diff  --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index c3064651fbc56..d7fcf02decea7 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -177,6 +177,13 @@ struct APFloatBase {
 // This format's exponent bias is 8, instead of the 7 (2 ** (4 - 1) - 1)
 // that IEEE precedent would imply.
 S_Float8E4M3FNUZ,
+// 8-bit floating point number mostly following IEEE-754 conventions
+// and bit layout S1E4M3 with expanded range and with no infinity or signed
+// zero.
+// NaN is represnted as negative zero. (FN -> Finite, UZ -> unsigned zero).
+// This format's exponent bias is 11, instead of the 7 (2 ** (4 - 1) - 1)
+// that IEEE precedent would imply.
+S_Float8E4M3B11FNUZ,
 
 S_x87DoubleExtended,
 S_MaxSemantics = S_x87DoubleExtended,
@@ -195,6 +202,7 @@ struct APFloatBase {
   static const fltSemantics () LLVM_READNONE;
   static const fltSemantics () LLVM_READNONE;
   static const fltSemantics () LLVM_READNONE;
+  static const fltSemantics () LLVM_READNONE;
   static const fltSemantics () LLVM_READNONE;
 
   /// A Pseudo fltsemantic used to construct APFloats that cannot conflict with
@@ -590,6 +598,7 @@ class IEEEFloat final : public APFloatBase {
   APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
   APInt convertFloat8E4M3FNAPFloatToAPInt() const;
   APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
+  APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
   void initFromAPInt(const fltSemantics *Sem, const APInt );
   void initFromHalfAPInt(const APInt );
   void initFromBFloatAPInt(const APInt );
@@ -602,6 +611,7 @@ class IEEEFloat final : public APFloatBase {
   void initFromFloat8E5M2FNUZAPInt(const APInt );
   void initFromFloat8E4M3FNAPInt(const APInt );
   void initFromFloat8E4M3FNUZAPInt(const APInt );
+  void initFromFloat8E4M3B11FNUZAPInt(const APInt );
 
   void assign(const IEEEFloat &);
   void copySignificand(const IEEEFloat &);

diff  --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 05053828bfc18..97c811a18e8af 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -60,8 +60,9 @@ enum class fltNonfiniteBehavior {
   IEEE754,
 
   // This behavior is present in the Float8ExMyFN* types (Float8E4M3FN,
-  // Float8E5M2FNUZ, and Float8E4M3FNUZ). There is no representation for Inf,
-  // and operations that would ordinarily produce Inf produce NaN 

[clang] 955d7c3 - [clang] Add support for #pragma strict_gs_check

2022-09-19 Thread David Majnemer via cfe-commits

Author: David Majnemer
Date: 2022-09-19T20:07:14Z
New Revision: 955d7c39ff74868a28c848a0462ff41be972043e

URL: 
https://github.com/llvm/llvm-project/commit/955d7c39ff74868a28c848a0462ff41be972043e
DIFF: 
https://github.com/llvm/llvm-project/commit/955d7c39ff74868a28c848a0462ff41be972043e.diff

LOG: [clang] Add support for #pragma strict_gs_check

Added: 
clang/test/CodeGenCXX/pragma-strict_gs_check.cpp

Modified: 
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParsePragma.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index ee9deef0dde1..0238b3877120 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4454,8 +4454,8 @@ def NoStackProtectorDocs : Documentation {
   let Category = DocCatFunction;
   let Heading = "no_stack_protector, safebuffers";
   let Content = [{
-Clang supports the ``__attribute__((no_stack_protector))`` and Microsoft style
-``__declspec(safebuffers)`` attribute which disables
+Clang supports the GNU style ``__attribute__((no_stack_protector))`` and 
Microsoft
+style ``__declspec(safebuffers)`` attribute which disables
 the stack protector on the specified function. This attribute is useful for
 selectively disabling the stack protector on some functions when building with
 ``-fstack-protector`` compiler option.

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 690a56bf6614..273af97ef241 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -194,6 +194,7 @@ class Parser : public CodeCompletionHandler {
   std::unique_ptr MSConstSeg;
   std::unique_ptr MSCodeSeg;
   std::unique_ptr MSSection;
+  std::unique_ptr MSStrictGuardStackCheck;
   std::unique_ptr MSRuntimeChecks;
   std::unique_ptr MSIntrinsic;
   std::unique_ptr MSFunction;
@@ -725,6 +726,8 @@ class Parser : public CodeCompletionHandler {
  SourceLocation PragmaLocation);
   bool HandlePragmaMSInitSeg(StringRef PragmaName,
  SourceLocation PragmaLocation);
+  bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
+   SourceLocation PragmaLocation);
   bool HandlePragmaMSFunction(StringRef PragmaName,
   SourceLocation PragmaLocation);
   bool HandlePragmaMSAllocText(StringRef PragmaName,

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f1a4c8d914c0..6dd656e29559 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -691,6 +691,9 @@ class Sema final {
   PragmaStack ConstSegStack;
   PragmaStack CodeSegStack;
 
+  // #pragma strict_gs_check.
+  PragmaStack StrictGuardStackCheckStack;
+
   // This stack tracks the current state of Sema.CurFPFeatures.
   PragmaStack FpPragmaStack;
   FPOptionsOverride CurFPFeatureOverrides() {
@@ -10295,6 +10298,12 @@ class Sema final {
  SourceLocation IncludeLoc);
   void DiagnoseUnterminatedPragmaAlignPack();
 
+  /// ActOnPragmaMSStrictGuardStackCheck - Called on well formed \#pragma
+  /// strict_gs_check.
+  void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation,
+  PragmaMsStackAction Action,
+  bool Value);
+
   /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off].
   void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
 

diff  --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 74fa70379858..123d94ee703f 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -449,6 +449,9 @@ void Parser::initializePragmaHandlers() {
 PP.AddPragmaHandler(MSCodeSeg.get());
 MSSection = std::make_unique("section");
 PP.AddPragmaHandler(MSSection.get());
+MSStrictGuardStackCheck =
+std::make_unique("strict_gs_check");
+PP.AddPragmaHandler(MSStrictGuardStackCheck.get());
 MSFunction = std::make_unique("function");
 PP.AddPragmaHandler(MSFunction.get());
 MSAllocText = std::make_unique("alloc_text");
@@ -567,6 +570,8 @@ void Parser::resetPragmaHandlers() {
 MSCodeSeg.reset();
 PP.RemovePragmaHandler(MSSection.get());
 MSSection.reset();
+PP.RemovePragmaHandler(MSStrictGuardStackCheck.get());
+MSStrictGuardStackCheck.reset();
 PP.RemovePragmaHandler(MSFunction.get());
 MSFunction.reset();
 PP.RemovePragmaHandler(MSAllocText.get());
@@ -936,6 +941,7 @@ void Parser::HandlePragmaMSPragma() {
   .Case("code_seg", ::HandlePragmaMSSegment)
   .Case("section", 

[clang] 8a868d8 - Revert "Revert "[clang, llvm] Add __declspec(safebuffers), support it in CodeView""

2022-09-16 Thread David Majnemer via cfe-commits

Author: David Majnemer
Date: 2022-09-16T19:39:48Z
New Revision: 8a868d8859f9da23ee051848863045208c17ab47

URL: 
https://github.com/llvm/llvm-project/commit/8a868d8859f9da23ee051848863045208c17ab47
DIFF: 
https://github.com/llvm/llvm-project/commit/8a868d8859f9da23ee051848863045208c17ab47.diff

LOG: Revert "Revert "[clang, llvm] Add __declspec(safebuffers), support it in 
CodeView""

This reverts commit cd20a1828605887699579789b5433111d5bc0319 and adds a
"let Heading" to NoStackProtectorDocs.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/Parser/MicrosoftExtensions.c
llvm/include/llvm/BinaryFormat/COFF.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/X86/X86AsmPrinter.cpp
llvm/test/DebugInfo/COFF/frameproc-flags.ll
llvm/test/DebugInfo/COFF/multifunction.ll
llvm/test/DebugInfo/COFF/simple.ll
llvm/test/DebugInfo/COFF/vframe-fpo.ll

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 2e3297b72a8c..b68f3e621769 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2080,12 +2080,19 @@ def NotTailCalled : InheritableAttr {
 def : MutualExclusions<[AlwaysInline, NotTailCalled]>;
 
 def NoStackProtector : InheritableAttr {
-  let Spellings = [Clang<"no_stack_protector">];
+  let Spellings = [Clang<"no_stack_protector">, Declspec<"safebuffers">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [NoStackProtectorDocs];
   let SimpleHandler = 1;
 }
 
+def StrictGuardStackCheck : InheritableAttr {
+  let Spellings = [Declspec<"strict_gs_check">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [StrictGuardStackCheckDocs];
+  let SimpleHandler = 1;
+}
+
 def NoThrow : InheritableAttr {
   let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
   let Subjects = SubjectList<[FunctionLike]>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 68f1268ed7da..ee9deef0dde1 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4452,8 +4452,10 @@ spelled "XYZ" in the `OpenMP 5.1 Standard`_).
 
 def NoStackProtectorDocs : Documentation {
   let Category = DocCatFunction;
+  let Heading = "no_stack_protector, safebuffers";
   let Content = [{
-Clang supports the ``__attribute__((no_stack_protector))`` attribute which 
disables
+Clang supports the ``__attribute__((no_stack_protector))`` and Microsoft style
+``__declspec(safebuffers)`` attribute which disables
 the stack protector on the specified function. This attribute is useful for
 selectively disabling the stack protector on some functions when building with
 ``-fstack-protector`` compiler option.
@@ -4472,6 +4474,27 @@ option.
 }];
 }
 
+def StrictGuardStackCheckDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the Microsoft style ``__declspec((strict_gs_check))`` attribute
+which upgrades the stack protector check from ``-fstack-protector`` to
+``-fstack-protector-strong``.
+
+For example, it upgrades the stack protector for the function ``foo`` to
+``-fstack-protector-strong`` but function ``bar`` will still be built with the
+stack protector with the ``-fstack-protector`` option.
+
+.. code-block:: c
+
+__declspec((strict_gs_check))
+int foo(int x); // stack protection will be upgraded for foo.
+
+int bar(int y); // bar can be built with the standard stack protector 
checks.
+
+}];
+}
+
 def NotTailCalledDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 9edd618d359b..bbd42956a4b0 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1970,14 +1970,17 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   if (!hasUnwindExceptions(LangOpts))
 B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (!D || !D->hasAttr()) {
-if (LangOpts.getStackProtector() == LangOptions::SSPOn)
-  B.addAttribute(llvm::Attribute::StackProtect);
-else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
-  B.addAttribute(llvm::Attribute::StackProtectStrong);
-else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
-  B.addAttribute(llvm::Attribute::StackProtectReq);
-  }
+  if (D && D->hasAttr())
+; // Do nothing.
+  else if (D && D->hasAttr() &&
+   LangOpts.getStackProtector() == LangOptions::SSPOn)
+B.addAttribute(llvm::Attribute::StackProtectStrong);
+  else if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+B.addAttribute(llvm::Attribute::StackProtect);
+  else if 

[clang] ab56719 - [clang, llvm] Add __declspec(safebuffers), support it in CodeView

2022-09-12 Thread David Majnemer via cfe-commits

Author: David Majnemer
Date: 2022-09-12T21:15:34Z
New Revision: ab56719acd98778fb2e48fa425ac7c8d27bdea86

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

LOG: [clang, llvm] Add __declspec(safebuffers), support it in CodeView

__declspec(safebuffers) is equivalent to
__attribute__((no_stack_protector)).  This information is recorded in
CodeView.

While we are here, add support for strict_gs_check.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/Parser/MicrosoftExtensions.c
llvm/include/llvm/BinaryFormat/COFF.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/X86/X86AsmPrinter.cpp
llvm/test/DebugInfo/COFF/frameproc-flags.ll
llvm/test/DebugInfo/COFF/multifunction.ll
llvm/test/DebugInfo/COFF/simple.ll
llvm/test/DebugInfo/COFF/vframe-fpo.ll

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 0ad59b2c153ae..af0e086540146 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2080,12 +2080,19 @@ def NotTailCalled : InheritableAttr {
 def : MutualExclusions<[AlwaysInline, NotTailCalled]>;
 
 def NoStackProtector : InheritableAttr {
-  let Spellings = [Clang<"no_stack_protector">];
+  let Spellings = [Clang<"no_stack_protector">, Declspec<"safebuffers">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [NoStackProtectorDocs];
   let SimpleHandler = 1;
 }
 
+def StrictGuardStackCheck : InheritableAttr {
+  let Spellings = [Declspec<"strict_gs_check">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [StrictGuardStackCheckDocs];
+  let SimpleHandler = 1;
+}
+
 def NoThrow : InheritableAttr {
   let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
   let Subjects = SubjectList<[FunctionLike]>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 68f1268ed7da9..b6c15c92d5815 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4453,7 +4453,8 @@ spelled "XYZ" in the `OpenMP 5.1 Standard`_).
 def NoStackProtectorDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
-Clang supports the ``__attribute__((no_stack_protector))`` attribute which 
disables
+Clang supports the ``__attribute__((no_stack_protector))`` and Microsoft style
+``__declspec(safebuffers)`` attribute which disables
 the stack protector on the specified function. This attribute is useful for
 selectively disabling the stack protector on some functions when building with
 ``-fstack-protector`` compiler option.
@@ -4472,6 +4473,27 @@ option.
 }];
 }
 
+def StrictGuardStackCheckDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the Microsoft style ``__declspec((strict_gs_check))`` attribute
+which upgrades the stack protector check from ``-fstack-protector`` to
+``-fstack-protector-strong``.
+
+For example, it upgrades the stack protector for the function ``foo`` to
+``-fstack-protector-strong`` but function ``bar`` will still be built with the
+stack protector with the ``-fstack-protector`` option.
+
+.. code-block:: c
+
+__declspec((strict_gs_check))
+int foo(int x); // stack protection will be upgraded for foo.
+
+int bar(int y); // bar can be built with the standard stack protector 
checks.
+
+}];
+}
+
 def NotTailCalledDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index f9087cdd5d4dc..ad6eb32ccc649 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1957,14 +1957,17 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   if (!hasUnwindExceptions(LangOpts))
 B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (!D || !D->hasAttr()) {
-if (LangOpts.getStackProtector() == LangOptions::SSPOn)
-  B.addAttribute(llvm::Attribute::StackProtect);
-else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
-  B.addAttribute(llvm::Attribute::StackProtectStrong);
-else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
-  B.addAttribute(llvm::Attribute::StackProtectReq);
-  }
+  if (D && D->hasAttr())
+; // Do nothing.
+  else if (D && D->hasAttr() &&
+   LangOpts.getStackProtector() == LangOptions::SSPOn)
+B.addAttribute(llvm::Attribute::StackProtectStrong);
+  else if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+B.addAttribute(llvm::Attribute::StackProtect);
+  else if 

[clang] bd28bd5 - [clang-cl] /kernel should toggle bit 30 in @feat.00

2022-08-25 Thread David Majnemer via cfe-commits

Author: David Majnemer
Date: 2022-08-25T14:17:26Z
New Revision: bd28bd59a3693b6abc12231f2140e02760c0ada0

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

LOG: [clang-cl] /kernel should toggle bit 30 in @feat.00

The linker is supposed to detect when an object with /kernel is linked
with another object which is not compiled with /kernel. The linker
detects this by checking bit 30 in @feat.00.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/cfguardtable.c
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/X86/X86AsmPrinter.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 6238a289978d..9df197056664 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -697,6 +697,10 @@ void CodeGenModule::Release() {
 // Function ID tables for EH Continuation Guard.
 getModule().addModuleFlag(llvm::Module::Warning, "ehcontguard", 1);
   }
+  if (Context.getLangOpts().Kernel) {
+// Note if we are compiling with /kernel.
+getModule().addModuleFlag(llvm::Module::Warning, "ms-kernel", 1);
+  }
   if (CodeGenOpts.OptimizationLevel > 0 && CodeGenOpts.StrictVTablePointers) {
 // We don't support LTO with 2 with 
diff erent StrictVTablePointers
 // FIXME: we could support it by stripping all the information introduced

diff  --git a/clang/test/CodeGen/cfguardtable.c 
b/clang/test/CodeGen/cfguardtable.c
index a92e1f6c610c..fe65d2a81c23 100644
--- a/clang/test/CodeGen/cfguardtable.c
+++ b/clang/test/CodeGen/cfguardtable.c
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -cfguard-no-checks -emit-llvm %s -o - | FileCheck %s 
-check-prefix=CFGUARDNOCHECKS
 // RUN: %clang_cc1 -cfguard -emit-llvm %s -o - | FileCheck %s 
-check-prefix=CFGUARD
 // RUN: %clang_cc1 -ehcontguard -emit-llvm %s -o - | FileCheck %s 
-check-prefix=EHCONTGUARD
+// RUN: %clang_cc1 -fms-kernel -emit-llvm %s -o - | FileCheck %s 
-check-prefix=MS-KERNEL
 
 void f(void) {}
 
@@ -8,3 +9,4 @@ void f(void) {}
 // CFGUARDNOCHECKS: !"cfguard", i32 1}
 // CFGUARD: !"cfguard", i32 2}
 // EHCONTGUARD: !"ehcontguard", i32 1}
+// MS-KERNEL: !"ms-kernel", i32 1}

diff  --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp 
b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 32d2f7945646..df2fce5621ad 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -219,6 +219,10 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module ) {
   Feat00Flags |= 0x4000; // Object also has EHCont.
 }
 
+if (M.getModuleFlag("ms-kernel")) {
+  Feat00Flags |= 0x4000; // Object is compiled with /kernel.
+}
+
 OutStreamer->emitSymbolAttribute(S, MCSA_Global);
 OutStreamer->emitAssignment(
 S, MCConstantExpr::create(Feat00Flags, MMI->getContext()));

diff  --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp 
b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 834b626dbb15..3e0f2a41ee74 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -818,6 +818,10 @@ void X86AsmPrinter::emitStartOfAsmFile(Module ) {
   Feat00Flags |= 0x4000; // Object also has EHCont.
 }
 
+if (M.getModuleFlag("ms-kernel")) {
+  Feat00Flags |= 0x4000; // Object is compiled with /kernel.
+}
+
 OutStreamer->emitSymbolAttribute(S, MCSA_Global);
 OutStreamer->emitAssignment(
 S, MCConstantExpr::create(Feat00Flags, MMI->getContext()));



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


[clang] 2c923b8 - [clang-cl] Expose the /volatile:{iso, ms} choice via _ISO_VOLATILE

2022-08-23 Thread David Majnemer via cfe-commits

Author: David Majnemer
Date: 2022-08-23T14:29:52Z
New Revision: 2c923b88631cda41cbddf58a13ccfb5c04a2fc3c

URL: 
https://github.com/llvm/llvm-project/commit/2c923b88631cda41cbddf58a13ccfb5c04a2fc3c
DIFF: 
https://github.com/llvm/llvm-project/commit/2c923b88631cda41cbddf58a13ccfb5c04a2fc3c.diff

LOG: [clang-cl] Expose the /volatile:{iso,ms} choice via _ISO_VOLATILE

MSVC allows interpreting volatile loads and stores, when combined with
/volatile:iso, as having acquire/release semantics. MSVC also exposes a
define, _ISO_VOLATILE, which allows users to enquire if this feature is
enabled or disabled.

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/OSTargets.cpp
clang/lib/CodeGen/CGAtomic.cpp
clang/test/Preprocessor/predefined-win-macros.c

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 0f35420f43133..87c75bb98d433 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -173,7 +173,6 @@ CODEGENOPT(IncrementalLinkerCompatible, 1, 0) ///< Emit an 
object file which can
   ///< linker.
 CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical constants.
 CODEGENOPT(MergeFunctions, 1, 0) ///< Set when -fmerge-functions is 
enabled.
-CODEGENOPT(MSVolatile, 1, 0) ///< Set when /volatile:ms is enabled.
 CODEGENOPT(NoCommon  , 1, 0) ///< Set when -fno-common or C++ is 
enabled.
 CODEGENOPT(NoDwarfDirectoryAsm , 1, 0) ///< Set when -fno-dwarf-directory-asm 
is
///< enabled.

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index ad366821f3cbf..4f3f6fc9da8c0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -148,6 +148,7 @@ LANGOPT(TraditionalCPP, 1, 0, "traditional CPP 
emulation")
 LANGOPT(RTTI  , 1, 1, "run-time type information")
 LANGOPT(RTTIData  , 1, 1, "emit run-time type information data")
 LANGOPT(MSBitfields   , 1, 0, "Microsoft-compatible structure layout")
+LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and 
stores")
 LANGOPT(Freestanding, 1, 0, "freestanding implementation")
 LANGOPT(NoBuiltin , 1, 0, "disable builtin functions")
 LANGOPT(NoMathBuiltin , 1, 0, "disable math builtin functions")

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index aadd516cf6209..ec5f553f64584 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2204,7 +2204,7 @@ defm asm_blocks : BoolFOption<"asm-blocks",
   LangOpts<"AsmBlocks">, Default,
   PosFlag, NegFlag>;
 def fms_volatile : Flag<["-"], "fms-volatile">, Group, 
Flags<[CC1Option]>,
-  MarshallingInfoFlag>;
+  MarshallingInfoFlag>;
 def fmsc_version : Joined<["-"], "fmsc-version=">, Group, 
Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Microsoft compiler version number to report in _MSC_VER (0 = don't 
define it (default))">;
 def fms_compatibility_version

diff  --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 5c734024897cb..d11b9f5dbba5a 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -263,6 +263,9 @@ static void addVisualCDefines(const LangOptions , 
MacroBuilder ) {
 }
   }
 
+  if (!Opts.MSVolatile)
+Builder.defineMacro("_ISO_VOLATILE");
+
   if (Opts.Kernel)
 Builder.defineMacro("_KERNEL_MODE");
 

diff  --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index ccc66bc28605f..8ef95bb808468 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -1594,7 +1594,7 @@ llvm::Value 
*AtomicInfo::EmitAtomicLoadOp(llvm::AtomicOrdering AO,
 /// we are operating under /volatile:ms *and* the LValue itself is volatile and
 /// performing such an operation can be performed without a libcall.
 bool CodeGenFunction::LValueIsSuitableForInlineAtomic(LValue LV) {
-  if (!CGM.getCodeGenOpts().MSVolatile) return false;
+  if (!CGM.getLangOpts().MSVolatile) return false;
   AtomicInfo AI(*this, LV);
   bool IsVolatile = LV.isVolatile() || hasVolatileMember(LV.getType());
   // An atomic is inline if we don't need to use a libcall.

diff  --git a/clang/test/Preprocessor/predefined-win-macros.c 
b/clang/test/Preprocessor/predefined-win-macros.c
index df43ae59cef42..f402ce91838d6 100644
--- a/clang/test/Preprocessor/predefined-win-macros.c
+++ b/clang/test/Preprocessor/predefined-win-macros.c
@@ -5,6 +5,7 @@
 // RUN: %clang_cc1 %s -x c++ -E -dM -triple x86_64-pc-win32 -fms-extensions 
-fms-compatibility \
 // 

[clang] 0bf525b - [clang-cl] Add _M_FP_* #defines for floating point modes

2022-08-22 Thread David Majnemer via cfe-commits

Author: David Majnemer
Date: 2022-08-22T20:04:35Z
New Revision: 0bf525bf902e3cd2072ddac82069f28e6d01fdc5

URL: 
https://github.com/llvm/llvm-project/commit/0bf525bf902e3cd2072ddac82069f28e6d01fdc5
DIFF: 
https://github.com/llvm/llvm-project/commit/0bf525bf902e3cd2072ddac82069f28e6d01fdc5.diff

LOG: [clang-cl] Add _M_FP_* #defines for floating point modes

This keeps clang compatible with MSVC defines for the FP environment.
These defines are used by the CRT and other libraries to interrogate
what to expect. Perhaps most importantly, they feed into the definition
of float_t and double_t which may result in ODR violations between MSVC
and clang.

Added: 


Modified: 
clang/lib/Basic/Targets/OSTargets.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index f2ed076039a0b..5c734024897cb 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -178,6 +178,54 @@ static void addVisualCDefines(const LangOptions , 
MacroBuilder ) {
   if (!Opts.CharIsSigned)
 Builder.defineMacro("_CHAR_UNSIGNED");
 
+  // "The /fp:contract option allows the compiler to generate floating-point
+  // contractions [...]"
+  if (Opts.getDefaultFPContractMode() != LangOptions::FPModeKind::FPM_Off)
+Builder.defineMacro("_M_FP_CONTRACT");
+
+  // "The /fp:except option generates code to ensures that any unmasked
+  // floating-point exceptions are raised at the exact point at which they
+  // occur, and that no other floating-point exceptions are raised."
+  if (Opts.getDefaultExceptionMode() ==
+  LangOptions::FPExceptionModeKind::FPE_Strict)
+Builder.defineMacro("_M_FP_EXCEPT");
+
+  // "The /fp:fast option allows the compiler to reorder, combine, or simplify
+  // floating-point operations to optimize floating-point code for speed and
+  // space. The compiler may omit rounding at assignment statements,
+  // typecasts, or function calls. It may reorder operations or make algebraic
+  // transforms, for example, by use of associative and distributive laws. It
+  // may reorder code even if such transformations result in observably
+  // 
diff erent rounding behavior."
+  //
+  // "Under /fp:precise and /fp:strict, the compiler doesn't do any 
mathematical
+  // transformation unless the transformation is guaranteed to produce a 
bitwise
+  // identical result."
+  const bool any_imprecise_flags =
+  Opts.FastMath || Opts.FiniteMathOnly || Opts.UnsafeFPMath ||
+  Opts.AllowFPReassoc || Opts.NoHonorNaNs || Opts.NoHonorInfs ||
+  Opts.NoSignedZero || Opts.AllowRecip || Opts.ApproxFunc;
+
+  // "Under both /fp:precise and /fp:fast, the compiler generates code intended
+  // to run in the default floating-point environment."
+  //
+  // "[The] default floating point environment [...] sets the rounding mode
+  // to round to nearest."
+  if (Opts.getDefaultRoundingMode() ==
+  LangOptions::RoundingMode::NearestTiesToEven) {
+if (any_imprecise_flags) {
+  Builder.defineMacro("_M_FP_FAST");
+} else {
+  Builder.defineMacro("_M_FP_PRECISE");
+}
+  } else if (!any_imprecise_flags && Opts.getDefaultRoundingMode() ==
+ LangOptions::RoundingMode::Dynamic) {
+// "Under /fp:strict, the compiler generates code that allows the
+// program to safely unmask floating-point exceptions, read or write
+// floating-point status registers, or change rounding modes."
+Builder.defineMacro("_M_FP_STRICT");
+  }
+
   // FIXME: POSIXThreads isn't exactly the option this should be defined for,
   //but it works for now.
   if (Opts.POSIXThreads)



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


[clang] 3d89323 - [clang-cl] Increase /fp flag fidelity

2022-08-22 Thread David Majnemer via cfe-commits

Author: David Majnemer
Date: 2022-08-22T18:32:58Z
New Revision: 3d89323d1896fde5dc69ecb8306917718c5e3aed

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

LOG: [clang-cl] Increase /fp flag fidelity

They were mapped as follows:
- /fp:except to --ftrapping-math
- /fp:except- to --fno-trapping-math
- /fp:strict to --fno-fast-math
- /fp:precise to --fno-fast-math

Let's map them as follows:
- /fp:except to --ffp-exception-behavior=strict
- /fp:except- to --ffp-exception-behavior=ignore
- /fp:strict to --ffp-model=strict
- /fp:precise to --ffp-model=ignore

I believe the changes to /fp:except are technically a no-op but it makes
the mapping a lot clearer. The changes for /fp:strict and /fp:precise are not
no-ops, they now match MSVC's behavior.

While we are here, also add support for /fp:contract by mapping it to
-ffp-contract=on.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/cl-options.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1939312ffd685..aadd516cf6209 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6447,13 +6447,12 @@ def _SLASH_E : CLFlag<"E">, HelpText<"Preprocess to 
stdout">, Alias;
 def _SLASH_external_COLON_I : CLJoinedOrSeparate<"external:I">, Alias,
   HelpText<"Add directory to include search path with warnings suppressed">,
   MetaVarName<"">;
-def _SLASH_fp_except : CLFlag<"fp:except">, HelpText<"">, 
Alias;
-def _SLASH_fp_except_ : CLFlag<"fp:except-">,
-  HelpText<"">, Alias;
+def _SLASH_fp_contract : CLFlag<"fp:contract">, HelpText<"">, 
Alias, AliasArgs<["on"]>;
+def _SLASH_fp_except : CLFlag<"fp:except">, HelpText<"">, 
Alias, AliasArgs<["strict"]>;
+def _SLASH_fp_except_ : CLFlag<"fp:except-">, HelpText<"">, 
Alias, AliasArgs<["ignore"]>;
 def _SLASH_fp_fast : CLFlag<"fp:fast">, HelpText<"">, Alias;
-def _SLASH_fp_precise : CLFlag<"fp:precise">,
-  HelpText<"">, Alias;
-def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, Alias;
+def _SLASH_fp_precise : CLFlag<"fp:precise">, HelpText<"">, 
Alias, AliasArgs<["precise"]>;
+def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, Alias, 
AliasArgs<["strict"]>;
 def _SLASH_fsanitize_EQ_address : CLFlag<"fsanitize=address">,
   HelpText<"Enable AddressSanitizer">,
   Alias, AliasArgs<["address"]>;

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index a2e350a0a8355..35caf2722c5f9 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -44,9 +44,11 @@
 
 // RUN: %clang_cl /fp:fast /fp:except -### -- %s 2>&1 | FileCheck 
-check-prefix=fpexcept %s
 // fpexcept-NOT: -menable-unsafe-fp-math
+// fpexcept: -ffp-exception-behavior=strict
 
 // RUN: %clang_cl /fp:fast /fp:except /fp:except- -### -- %s 2>&1 | FileCheck 
-check-prefix=fpexcept_ %s
 // fpexcept_: -menable-unsafe-fp-math
+// fpexcept_: -ffp-exception-behavior=ignore
 
 // RUN: %clang_cl /fp:precise /fp:fast -### -- %s 2>&1 | FileCheck 
-check-prefix=fpfast %s
 // fpfast: -menable-unsafe-fp-math
@@ -59,6 +61,10 @@
 // RUN: %clang_cl /fp:fast /fp:strict -### -- %s 2>&1 | FileCheck 
-check-prefix=fpstrict %s
 // fpstrict-NOT: -menable-unsafe-fp-math
 // fpstrict-NOT: -ffast-math
+// fpstrict: -ffp-contract=off
+
+// RUN: %clang_cl /fp:strict /fp:contract -### -- %s 2>&1 | FileCheck 
-check-prefix=fpcontract %s
+// fpcontract: -ffp-contract=on
 
 // RUN: %clang_cl /fsanitize=address -### -- %s 2>&1 | FileCheck 
-check-prefix=fsanitize_address %s
 // fsanitize_address: -fsanitize=address



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


[clang] 072e2a7 - [MS] Implement on-demand TLS initialization for Microsoft CXX ABI

2022-01-13 Thread David Majnemer via cfe-commits

Author: Maurice Heumann
Date: 2022-01-13T21:23:23-08:00
New Revision: 072e2a7c67b74b8bde35f78ac0b0b13a269380f8

URL: 
https://github.com/llvm/llvm-project/commit/072e2a7c67b74b8bde35f78ac0b0b13a269380f8
DIFF: 
https://github.com/llvm/llvm-project/commit/072e2a7c67b74b8bde35f78ac0b0b13a269380f8.diff

LOG: [MS] Implement on-demand TLS initialization for Microsoft CXX ABI

TLS initializers, for example constructors of thread-local variables, don't 
necessarily get called. If a thread was created before a module is loaded, the 
module's TLS initializers are not executed for this particular thread.

This is why Microsoft added support for dynamic TLS initialization. Before 
every use of thread-local variables, a check is added that runs the module's 
TLS initializers on-demand.

To do this, the method `__dyn_tls_on_demand_init` gets called. Internally, it 
simply calls `__dyn_tls_init`.

No additional TLS initializer that sets the guard needs to be emitted, as the 
guard always gets set by `__dyn_tls_init`.
The guard is also checked again within `__dyn_tls_init`. This makes our check 
redundant, however, as Microsoft's compiler also emits this check, the 
behaviour is adopted here.

Reviewed By: majnemer

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

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.h
clang/lib/CodeGen/CGCXXABI.cpp
clang/lib/CodeGen/CGCXXABI.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/ms-thread_local.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 35b33c2e09716..09afa641acf9b 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -124,6 +124,7 @@ class LangOptions : public LangOptionsBase {
 MSVC2017_5 = 1912,
 MSVC2017_7 = 1914,
 MSVC2019 = 1920,
+MSVC2019_5 = 1925,
 MSVC2019_8 = 1928,
   };
 

diff  --git a/clang/lib/CodeGen/CGCXXABI.cpp b/clang/lib/CodeGen/CGCXXABI.cpp
index 9714730e3c4bf..0b441e382f11c 100644
--- a/clang/lib/CodeGen/CGCXXABI.cpp
+++ b/clang/lib/CodeGen/CGCXXABI.cpp
@@ -154,6 +154,51 @@ void CGCXXABI::setCXXABIThisValue(CodeGenFunction , 
llvm::Value *ThisPtr) {
   CGF.CXXABIThisValue = ThisPtr;
 }
 
+bool CGCXXABI::mayNeedDestruction(const VarDecl *VD) const {
+  if (VD->needsDestruction(getContext()))
+return true;
+
+  // If the variable has an incomplete class type (or array thereof), it
+  // might need destruction.
+  const Type *T = VD->getType()->getBaseElementTypeUnsafe();
+  if (T->getAs() && T->isIncompleteType())
+return true;
+
+  return false;
+}
+
+bool CGCXXABI::isEmittedWithConstantInitializer(
+const VarDecl *VD, bool InspectInitForWeakDef) const {
+  VD = VD->getMostRecentDecl();
+  if (VD->hasAttr())
+return true;
+
+  // All later checks examine the initializer specified on the variable. If
+  // the variable is weak, such examination would not be correct.
+  if (!InspectInitForWeakDef && (VD->isWeak() || VD->hasAttr()))
+return false;
+
+  const VarDecl *InitDecl = VD->getInitializingDeclaration();
+  if (!InitDecl)
+return false;
+
+  // If there's no initializer to run, this is constant initialization.
+  if (!InitDecl->hasInit())
+return true;
+
+  // If we have the only definition, we don't need a thread wrapper if we
+  // will emit the value as a constant.
+  if (isUniqueGVALinkage(getContext().GetGVALinkageForVariable(VD)))
+return !mayNeedDestruction(VD) && InitDecl->evaluateValue();
+
+  // Otherwise, we need a thread wrapper unless we know that every
+  // translation unit will emit the value as a constant. We rely on the
+  // variable being constant-initialized in every translation unit if it's
+  // constant-initialized in any translation unit, which isn't actually
+  // guaranteed by the standard but is necessary for sanity.
+  return InitDecl->hasConstantInitialization();
+}
+
 void CGCXXABI::EmitReturnFromThunk(CodeGenFunction ,
RValue RV, QualType ResultType) {
   assert(!CGF.hasAggregateEvaluationKind(ResultType) &&

diff  --git a/clang/lib/CodeGen/CGCXXABI.h b/clang/lib/CodeGen/CGCXXABI.h
index e94e19bab0ad1..b96222b3ce280 100644
--- a/clang/lib/CodeGen/CGCXXABI.h
+++ b/clang/lib/CodeGen/CGCXXABI.h
@@ -79,6 +79,18 @@ class CGCXXABI {
 
   ASTContext () const { return CGM.getContext(); }
 
+  bool mayNeedDestruction(const VarDecl *VD) const;
+
+  /// Determine whether we will definitely emit this variable with a constant
+  /// initializer, either because the language semantics demand it or because
+  /// we know that the initializer is a constant.
+  // For weak definitions, any initializer available in the current translation
+  // is not necessarily reflective of the initializer used; such initializers
+  // are ignored unless if 

Re: r350643 - Limit COFF 'common' emission to <=32 alignment types.

2019-01-08 Thread David Majnemer via cfe-commits
Yes, the MinGW toolchain can handle this by specifying the alignment of a
common symbol using the aligncomm directive. The MSVC toolchain has no such
mechanism.

This is why the check uses isKnownWindowsMSVCEnvironment.

On Tue, Jan 8, 2019 at 1:09 PM Shoaib Meenai  wrote:

> It checks for both OS=Win32 and Environment=MSVC, so that wouldn't cover
> other COFF environments. wbs (Martin Storsjo) mentioned on IRC that MinGW
> adds an aligncomm directive to specify alignment for common symbols, so
> perhaps that's part of it?
>
>
>
> *From: *"Keane, Erich" 
> *Date: *Tuesday, January 8, 2019 at 1:04 PM
> *To: *Shoaib Meenai , "cfe-commits@lists.llvm.org" <
> cfe-commits@lists.llvm.org>, David Majnemer 
> *Subject: *RE: r350643 - Limit COFF 'common' emission to <=32 alignment
> types.
>
>
>
> Yep, exactly.  I looked, and isKnownWindowsMSVCEnvironment checks for
> OS=Win32, which I believe would be different for other architectures.
>
>
>
> *From:* Shoaib Meenai [mailto:smee...@fb.com]
> *Sent:* Tuesday, January 8, 2019 12:41 PM
> *To:* Keane, Erich ; cfe-commits@lists.llvm.org;
> David Majnemer 
> *Subject:* Re: r350643 - Limit COFF 'common' emission to <=32 alignment
> types.
>
>
>
> Ah, looks like you were originally checking for COFF, and then David
> suggested checking for MSVC instead? I'm curious about why, although I'm
> sure the suggestion is legit :)
>
>
>
> *From: *cfe-commits  on behalf of
> Shoaib Meenai via cfe-commits 
> *Reply-To: *Shoaib Meenai 
> *Date: *Tuesday, January 8, 2019 at 12:39 PM
> *To: *Erich Keane , "cfe-commits@lists.llvm.org" <
> cfe-commits@lists.llvm.org>
> *Subject: *Re: r350643 - Limit COFF 'common' emission to <=32 alignment
> types.
>
>
>
> Why does this check for isKnownWindowsMSVCEnvironment specifically?
> Wouldn't any COFF target (windows-cygnus, windows-gnu, windows-itanium,
> etc.) have the same limitation, since it's an object file format issue and
> not an ABI issue?
>
>
>
> *From: *cfe-commits  on behalf of
> Erich Keane via cfe-commits 
> *Reply-To: *Erich Keane 
> *Date: *Tuesday, January 8, 2019 at 10:48 AM
> *To: *"cfe-commits@lists.llvm.org" 
> *Subject: *r350643 - Limit COFF 'common' emission to <=32 alignment types.
>
>
>
> Author: erichkeane
>
> Date: Tue Jan  8 10:44:22 2019
>
> New Revision: 350643
>
>
>
> URL:
> https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D350643-26view-3Drev=DwIGaQ=5VD0RTtNlTh3ycd41b3MUw=o3kDXzdBUE3ljQXKeTWOMw=RNVKy_b0_Wgp_PTFDpvQXETsZdWubmT5SGnGz3GigS0=Ph9GOtRaQERmqyeJeAJTFwV3sg3q8fE05FlJ3qwNx4I=
>
> Log:
>
> Limit COFF 'common' emission to <=32 alignment types.
>
>
>
> As reported in PR33035, LLVM crashes if given a common object with an
>
> alignment of greater than 32 bits. This is because the COFF file format
>
> does not support these alignments, so emitting them is broken anyway.
>
>
>
> This patch changes any global definitions greater than 32 bit alignment
>
> to no longer be in 'common'.
>
>
>
>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__bugs.llvm.org_show-5Fbug.cgi-3Fid-3D33035=DwIGaQ=5VD0RTtNlTh3ycd41b3MUw=o3kDXzdBUE3ljQXKeTWOMw=RNVKy_b0_Wgp_PTFDpvQXETsZdWubmT5SGnGz3GigS0=ac1NEHuvztd6jSTCsOUJajkklfeyqdzW-xqtddJ-hvM=
>
>
>
> Differential Revision:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D56391=DwIGaQ=5VD0RTtNlTh3ycd41b3MUw=o3kDXzdBUE3ljQXKeTWOMw=RNVKy_b0_Wgp_PTFDpvQXETsZdWubmT5SGnGz3GigS0=AucP9Sp-DYHSaOP-sPfpAOrww3xwdh8FjQkHrLZhhyo=
>
>
>
> Change-Id: I48609289753b7f3b58c5e2bc1712756750fbd45a
>
>
>
> Added:
>
> cfe/trunk/test/CodeGen/microsoft-no-common-align.c
>
> Modified:
>
> cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>
>
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>
> URL:
> https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_CodeGen_CodeGenModule.cpp-3Frev-3D350643-26r1-3D350642-26r2-3D350643-26view-3Ddiff=DwIGaQ=5VD0RTtNlTh3ycd41b3MUw=o3kDXzdBUE3ljQXKeTWOMw=RNVKy_b0_Wgp_PTFDpvQXETsZdWubmT5SGnGz3GigS0=gmTnEmW03ruG8LbJluf5Z4yQcxM64QP7Ce1VTnVqvPo=
>
>
> ==
>
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
>
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Jan  8 10:44:22 2019
>
> @@ -3761,6 +3761,11 @@ static bool isVarDeclStrongDefinition(co
>
>}
>
>  }
>
>}
>
> +  // COFF doesn't support alignments greater than 32, so these cannot be
>
> +  // in common.
>
> +  if (Context.getTargetInfo().getTriple().isKnownWindowsMSVCEnvironment()
> &&
>
> +  Context.getTypeAlignIfKnown(D->getType()) > 32)
>
> +return true;
>
>return false;
>
> }
>
>
>
> Added: cfe/trunk/test/CodeGen/microsoft-no-common-align.c
>
> URL:
> 

Re: r331244 - Implement P0482R2, support for char8_t type.

2018-05-01 Thread David Majnemer via cfe-commits
On Mon, Apr 30, 2018 at 10:02 PM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Mon Apr 30 22:02:45 2018
> New Revision: 331244
>
> URL: http://llvm.org/viewvc/llvm-project?rev=331244=rev
> Log:
> Implement P0482R2, support for char8_t type.
>
> This is not yet part of any C++ working draft, and so is controlled by the
> flag
> -fchar8_t rather than a -std= flag. (The GCC implementation is controlled
> by a
> flag with the same name.)
>
> This implementation is experimental, and will be removed or revised
> substantially to match the proposal as it makes its way through the C++
> committee.
>
> Added:
> cfe/trunk/test/CodeGenCXX/char8_t.cpp
> cfe/trunk/test/Lexer/char8_t.cpp
> cfe/trunk/test/SemaCXX/char8_t.cpp
> Modified:
> cfe/trunk/include/clang/AST/ASTContext.h
> cfe/trunk/include/clang/AST/BuiltinTypes.def
> cfe/trunk/include/clang/AST/Type.h
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/include/clang/Basic/LangOptions.def
> cfe/trunk/include/clang/Basic/Specifiers.h
> cfe/trunk/include/clang/Basic/TokenKinds.def
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/include/clang/Sema/DeclSpec.h
> cfe/trunk/include/clang/Sema/Initialization.h
> cfe/trunk/include/clang/Serialization/ASTBitCodes.h
> cfe/trunk/lib/AST/ASTContext.cpp
> cfe/trunk/lib/AST/ExprConstant.cpp
> cfe/trunk/lib/AST/ItaniumMangle.cpp
> cfe/trunk/lib/AST/MicrosoftMangle.cpp
> cfe/trunk/lib/AST/NSAPI.cpp
> cfe/trunk/lib/AST/Type.cpp
> cfe/trunk/lib/AST/TypeLoc.cpp
> cfe/trunk/lib/Analysis/PrintfFormatString.cpp
> cfe/trunk/lib/Basic/IdentifierTable.cpp
> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
> cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> cfe/trunk/lib/Format/FormatToken.cpp
> cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> cfe/trunk/lib/Frontend/InitPreprocessor.cpp
> cfe/trunk/lib/Index/USRGeneration.cpp
> cfe/trunk/lib/Lex/PPExpressions.cpp
> cfe/trunk/lib/Parse/ParseDecl.cpp
> cfe/trunk/lib/Parse/ParseExpr.cpp
> cfe/trunk/lib/Parse/ParseExprCXX.cpp
> cfe/trunk/lib/Parse/ParseTentative.cpp
> cfe/trunk/lib/Sema/DeclSpec.cpp
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/lib/Sema/SemaInit.cpp
> cfe/trunk/lib/Sema/SemaOverload.cpp
> cfe/trunk/lib/Sema/SemaTemplate.cpp
> cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
> cfe/trunk/lib/Sema/SemaType.cpp
> cfe/trunk/lib/Serialization/ASTCommon.cpp
> cfe/trunk/lib/Serialization/ASTReader.cpp
> cfe/trunk/test/Lexer/cxx-features.cpp
>
> Modified: cfe/trunk/include/clang/AST/ASTContext.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/ASTContext.h?rev=331244=331243=331244=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
> +++ cfe/trunk/include/clang/AST/ASTContext.h Mon Apr 30 22:02:45 2018
> @@ -999,6 +999,7 @@ public:
>CanQualType WCharTy;  // [C++ 3.9.1p5].
>CanQualType WideCharTy; // Same as WCharTy in C++, integer type in C99.
>CanQualType WIntTy;   // [C99 7.24.1], integer type unchanged by
> default promotions.
> +  CanQualType Char8Ty;  // [C++20 proposal]
>CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
>CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
>CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
>
> Modified: cfe/trunk/include/clang/AST/BuiltinTypes.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/BuiltinTypes.def?rev=331244=331243=331244=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/BuiltinTypes.def (original)
> +++ cfe/trunk/include/clang/AST/BuiltinTypes.def Mon Apr 30 22:02:45 2018
> @@ -72,6 +72,9 @@ UNSIGNED_TYPE(UChar, UnsignedCharTy)
>  // 'wchar_t' for targets where it's unsigned
>  SHARED_SINGLETON_TYPE(UNSIGNED_TYPE(WChar_U, WCharTy))
>
> +// 'char8_t' in C++20 (proposed)
> +UNSIGNED_TYPE(Char8, Char8Ty)
> +
>  // 'char16_t' in C++
>  UNSIGNED_TYPE(Char16, Char16Ty)
>
>
> Modified: cfe/trunk/include/clang/AST/Type.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/Type.h?rev=331244=331243=331244=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/Type.h (original)
> +++ cfe/trunk/include/clang/AST/Type.h Mon Apr 30 22:02:45 2018
> @@ -1777,6 +1777,7 @@ public:
>bool isBooleanType() const;
>bool isCharType() const;
>bool isWideCharType() const;
> +  bool isChar8Type() const;
>bool isChar16Type() const;
>bool isChar32Type() const;
>bool 

Re: r316518 - mplement __has_unique_object_representations

2017-10-24 Thread David Majnemer via cfe-commits
On Tue, Oct 24, 2017 at 2:31 PM, Erich Keane via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: erichkeane
> Date: Tue Oct 24 14:31:50 2017
> New Revision: 316518
>
> URL: http://llvm.org/viewvc/llvm-project?rev=316518=rev
> Log:
> mplement __has_unique_object_representations
>
> A helper builtin to facilitate implementing the
> std::has_unique_object_representations type trait.
>
> Requested here: https://bugs.llvm.org/show_bug.cgi?id=34942
> Also already exists in GCC and MSVC.
>
> Differential Revision: https://reviews.llvm.org/D39064
>
> Modified:
> cfe/trunk/include/clang/AST/Type.h
> cfe/trunk/include/clang/Basic/TokenKinds.def
> cfe/trunk/include/clang/Basic/TypeTraits.h
> cfe/trunk/lib/AST/Type.cpp
> cfe/trunk/lib/Parse/ParseExpr.cpp
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> cfe/trunk/test/SemaCXX/type-traits.cpp
>
> Modified: cfe/trunk/include/clang/AST/Type.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/Type.h?rev=316518=316517=316518=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/Type.h (original)
> +++ cfe/trunk/include/clang/AST/Type.h Tue Oct 24 14:31:50 2017
> @@ -770,6 +770,10 @@ public:
>/// Return true if this is a trivially copyable type (C++0x
> [basic.types]p9)
>bool isTriviallyCopyableType(const ASTContext ) const;
>
> +  /// Return true if this has unique object representations according to
> (C++17
> +  /// [meta.unary.prop]p9)
> +  bool hasUniqueObjectRepresentations(const ASTContext ) const;
> +
>// Don't promise in the API that anything besides 'const' can be
>// easily added.
>
> @@ -1114,6 +1118,8 @@ public:
>QualType getAtomicUnqualifiedType() const;
>
>  private:
> +  bool unionHasUniqueObjectRepresentations(const ASTContext& Context)
> const;
> +  bool structHasUniqueObjectRepresentations(const ASTContext& Context)
> const;
>// These methods are implemented in a separate translation unit;
>// "static"-ize them to avoid creating temporary QualTypes in the
>// caller.
>
> Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/TokenKinds.def?rev=316518=316517=316518=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
> +++ cfe/trunk/include/clang/Basic/TokenKinds.def Tue Oct 24 14:31:50 2017
> @@ -455,6 +455,8 @@ TYPE_TRAIT_1(__is_pod, IsPOD, KEYCXX)
>  TYPE_TRAIT_1(__is_polymorphic, IsPolymorphic, KEYCXX)
>  TYPE_TRAIT_1(__is_trivial, IsTrivial, KEYCXX)
>  TYPE_TRAIT_1(__is_union, IsUnion, KEYCXX)
> +TYPE_TRAIT_1(__has_unique_object_representations,
> + HasUniqueObjectRepresentations, KEYCXX)
>
>  // Clang-only C++ Type Traits
>  TYPE_TRAIT_N(__is_trivially_constructible, IsTriviallyConstructible,
> KEYCXX)
>
> Modified: cfe/trunk/include/clang/Basic/TypeTraits.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/TypeTraits.h?rev=316518=316517=316518=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/TypeTraits.h (original)
> +++ cfe/trunk/include/clang/Basic/TypeTraits.h Tue Oct 24 14:31:50 2017
> @@ -70,7 +70,8 @@ namespace clang {
>  UTT_IsUnsigned,
>  UTT_IsVoid,
>  UTT_IsVolatile,
> -UTT_Last = UTT_IsVolatile,
> +UTT_HasUniqueObjectRepresentations,
> +UTT_Last = UTT_HasUniqueObjectRepresentations,
>  BTT_IsBaseOf,
>  BTT_IsConvertible,
>  BTT_IsConvertibleTo,
>
> Modified: cfe/trunk/lib/AST/Type.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> Type.cpp?rev=316518=316517=316518=diff
> 
> ==
> --- cfe/trunk/lib/AST/Type.cpp (original)
> +++ cfe/trunk/lib/AST/Type.cpp Tue Oct 24 14:31:50 2017
> @@ -2166,6 +2166,152 @@ bool QualType::isTriviallyCopyableType(c
>return false;
>  }
>
> +bool QualType::unionHasUniqueObjectRepresentations(
> +const ASTContext ) const {
> +  assert((*this)->isUnionType() && "must be union type");
> +  CharUnits UnionSize = Context.getTypeSizeInChars(*this);
> +  const RecordDecl *Union = getTypePtr()->getAs()->getDecl();
> +
> +  for (const auto *Field : Union->fields()) {
> +if (!Field->getType().hasUniqueObjectRepresentations(Context))
> +  return false;
> +CharUnits FieldSize = Context.getTypeSizeInChars(Field->getType());
> +if (FieldSize != UnionSize)
> +  return false;
> +  }
> +  return true;
> +}
> +
> +bool isStructEmpty(QualType Ty) {
> +  assert(Ty.getTypePtr()->isStructureOrClassType() &&
> + "Must be struct or class");
> +  const RecordDecl *RD = Ty.getTypePtr()->getAs()->getDecl();
> +
> +  if (!RD->field_empty())
> +return false;
> +
> +  if (const CXXRecordDecl *ClassDecl = dyn_cast(RD)) {
> +return 

Re: r314226 - Sema: Windows/ARM __va_start is not const correct

2017-09-26 Thread David Majnemer via cfe-commits
Shouldn't you only loosen the check for things targeting the Windows SDK?
GNU platforms shouldn't need this.

On Tue, Sep 26, 2017 at 10:44 AM, Saleem Abdulrasool via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: compnerd
> Date: Tue Sep 26 10:44:10 2017
> New Revision: 314226
>
> URL: http://llvm.org/viewvc/llvm-project?rev=314226=rev
> Log:
> Sema: Windows/ARM __va_start is not const correct
>
> The `__va_start` intrinsic for Windows ARM does not account for const
> correctness when performing a check.  All local qualifiers are ignored
> when validating the invocation.  This was exposed by building the swift
> stdlib against the Windows 10586 SDK for ARM.  Simply expand out the
> check for the two parameters and ignore the qualifiers for the check.
>
> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/SemaCXX/microsoft-varargs.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaChecking.cpp?rev=314226=314225=314226=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Sep 26 10:44:10 2017
> @@ -3943,23 +3943,33 @@ bool Sema::SemaBuiltinVAStartARM(CallExp
>if (checkVAStartIsInVariadicFunction(*this, Func))
>  return true;
>
> -  const struct {
> -unsigned ArgNo;
> -QualType Type;
> -  } ArgumentTypes[] = {
> -{ 1, Context.getPointerType(Context.CharTy.withConst()) },
> -{ 2, Context.getSizeType() },
> -  };
> -
> -  for (const auto  : ArgumentTypes) {
> -const Expr *Arg = Call->getArg(AT.ArgNo)->IgnoreParens();
> -if (Arg->getType().getCanonicalType() == AT.Type.getCanonicalType())
> -  continue;
> -Diag(Arg->getLocStart(), diag::err_typecheck_convert_incompatible)
> -  << Arg->getType() << AT.Type << 1 /* different class */
> -  << 0 /* qualifier difference */ << 3 /* parameter mismatch */
> -  << AT.ArgNo + 1 << Arg->getType() << AT.Type;
> -  }
> +  // __va_start on Windows does not validate the parameter qualifiers
> +
> +  const Expr *Arg1 = Call->getArg(1)->IgnoreParens();
> +  const Type *Arg1Ty = Arg1->getType().getCanonicalType().getTypePtr();
> +
> +  const Expr *Arg2 = Call->getArg(2)->IgnoreParens();
> +  const Type *Arg2Ty = Arg2->getType().getCanonicalType().getTypePtr();
> +
> +  const QualType  =
> +  Context.getPointerType(Context.CharTy.withConst());
> +  if (!Arg1Ty->isPointerType() ||
> +  Arg1Ty->getPointeeType().withoutLocalFastQualifiers() !=
> Context.CharTy)
> +Diag(Arg1->getLocStart(), diag::err_typecheck_convert_incompatible)
> +<< Arg1->getType() << ConstCharPtrTy
> +<< 1 /* different class */
> +<< 0 /* qualifier difference */
> +<< 3 /* parameter mismatch */
> +<< 2 << Arg1->getType() << ConstCharPtrTy;
> +
> +  const QualType SizeTy = Context.getSizeType();
> +  if (Arg2Ty->getCanonicalTypeInternal().withoutLocalFastQualifiers() !=
> SizeTy)
> +Diag(Arg2->getLocStart(), diag::err_typecheck_convert_incompatible)
> +<< Arg2->getType() << SizeTy
> +<< 1 /* different class */
> +<< 0 /* qualifier difference */
> +<< 3 /* parameter mismatch */
> +<< 3 << Arg2->getType() << SizeTy;
>
>return false;
>  }
>
> Modified: cfe/trunk/test/SemaCXX/microsoft-varargs.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> SemaCXX/microsoft-varargs.cpp?rev=314226=314225=314226=diff
> 
> ==
> --- cfe/trunk/test/SemaCXX/microsoft-varargs.cpp (original)
> +++ cfe/trunk/test/SemaCXX/microsoft-varargs.cpp Tue Sep 26 10:44:10 2017
> @@ -20,3 +20,8 @@ int builtin(int i, ...) {
>return __builtin_va_arg(ap, int);
>  }
>
> +void test___va_start_ignore_const(const char *format, ...) {
> +  va_list args;
> +  ((void)(__va_start(, (_cast(reinterpret_cast volatile char &>(format))), ((sizeof(format) + 4 - 1) & ~(4 - 1)),
> (_cast(reinterpret_cast(format));
> +}
> +
>
>
> ___
> 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: r309058 - [CodeGen] Correctly model std::byte's aliasing properties

2017-07-25 Thread David Majnemer via cfe-commits
Should this go into 5.0 ?

On Tue, Jul 25, 2017 at 4:33 PM, David Majnemer via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: majnemer
> Date: Tue Jul 25 16:33:58 2017
> New Revision: 309058
>
> URL: http://llvm.org/viewvc/llvm-project?rev=309058=rev
> Log:
> [CodeGen] Correctly model std::byte's aliasing properties
>
> std::byte, when defined as an enum, needs to be given special treatment
> with regards to its aliasing properties. An array of std::byte is
> allowed to be used as storage for other types.
>
> This fixes PR33916.
>
> Differential Revision: https://reviews.llvm.org/D35824
>
> Added:
> cfe/trunk/test/CodeGenCXX/std-byte.cpp
> Modified:
> cfe/trunk/include/clang/AST/Type.h
> cfe/trunk/lib/AST/Type.cpp
> cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
>
> Modified: cfe/trunk/include/clang/AST/Type.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/Type.h?rev=309058=309057=309058=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/Type.h (original)
> +++ cfe/trunk/include/clang/AST/Type.h Tue Jul 25 16:33:58 2017
> @@ -1752,6 +1752,7 @@ public:
>bool isTemplateTypeParmType() const;  // C++ template type
> parameter
>bool isNullPtrType() const;   // C++11 std::nullptr_t
>bool isAlignValT() const; // C++17 std::align_val_t
> +  bool isStdByteType() const;   // C++17 std::byte
>bool isAtomicType() const;// C11 _Atomic()
>
>  #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
>
> Modified: cfe/trunk/lib/AST/Type.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> Type.cpp?rev=309058=309057=309058=diff
> 
> ==
> --- cfe/trunk/lib/AST/Type.cpp (original)
> +++ cfe/trunk/lib/AST/Type.cpp Tue Jul 25 16:33:58 2017
> @@ -2313,6 +2313,15 @@ bool Type::isAlignValT() const {
>return false;
>  }
>
> +bool Type::isStdByteType() const {
> +  if (auto *ET = getAs()) {
> +auto *II = ET->getDecl()->getIdentifier();
> +if (II && II->isStr("byte") && ET->getDecl()->isInStdNamespace())
> +  return true;
> +  }
> +  return false;
> +}
> +
>  bool Type::isPromotableIntegerType() const {
>if (const BuiltinType *BT = getAs())
>  switch (BT->getKind()) {
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/
> CodeGenTBAA.cpp?rev=309058=309057=309058=diff
> 
> ==
> --- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Tue Jul 25 16:33:58 2017
> @@ -139,6 +139,12 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) {
>  }
>}
>
> +  // C++1z [basic.lval]p10: "If a program attempts to access the stored
> value of
> +  // an object through a glvalue of other than one of the following types
> the
> +  // behavior is undefined: [...] a char, unsigned char, or std::byte
> type."
> +  if (Ty->isStdByteType())
> +return MetadataCache[Ty] = getChar();
> +
>// Handle pointers.
>// TODO: Implement C++'s type "similarity" and consider dis-"similar"
>// pointers distinct.
>
> Added: cfe/trunk/test/CodeGenCXX/std-byte.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> CodeGenCXX/std-byte.cpp?rev=309058=auto
> 
> ==
> --- cfe/trunk/test/CodeGenCXX/std-byte.cpp (added)
> +++ cfe/trunk/test/CodeGenCXX/std-byte.cpp Tue Jul 25 16:33:58 2017
> @@ -0,0 +1,41 @@
> +// RUN: %clang_cc1 -std=c++1z -Werror -triple i386-unknown-unknown
> -emit-llvm -O1 -disable-llvm-passes -o - %s | FileCheck %s
> +
> +// std::byte should be considered equivalent to char for aliasing.
> +
> +namespace std {
> +enum byte : unsigned char {};
> +}
> +
> +// CHECK-LABEL: define void @test0(
> +extern "C" void test0(std::byte *sb, int *i) {
> +  // CHECK: store i8 0, i8* %{{.*}} !tbaa [[TAG_CHAR:!.*]]
> +  *sb = std::byte{0};
> +
> +  // CHECK: store i32 1, i32* %{{.*}} !tbaa [[TAG_INT:!.*]]
> +  *i = 1;
> +}
> +
> +enum byte : unsigned char {};
> +namespace my {
> +enum byte : unsigned char {};
> +namespace std {
> +enum byte : unsigned char {};
> +} // namespace std
> +} // namespace my
> +
> +// Make sure we don't get confused with other enums named 'byte'.
> +
> +// CHECK-LABEL: define void @t

r309058 - [CodeGen] Correctly model std::byte's aliasing properties

2017-07-25 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Tue Jul 25 16:33:58 2017
New Revision: 309058

URL: http://llvm.org/viewvc/llvm-project?rev=309058=rev
Log:
[CodeGen] Correctly model std::byte's aliasing properties

std::byte, when defined as an enum, needs to be given special treatment
with regards to its aliasing properties. An array of std::byte is
allowed to be used as storage for other types.

This fixes PR33916.

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

Added:
cfe/trunk/test/CodeGenCXX/std-byte.cpp
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=309058=309057=309058=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Jul 25 16:33:58 2017
@@ -1752,6 +1752,7 @@ public:
   bool isTemplateTypeParmType() const;  // C++ template type parameter
   bool isNullPtrType() const;   // C++11 std::nullptr_t
   bool isAlignValT() const; // C++17 std::align_val_t
+  bool isStdByteType() const;   // C++17 std::byte
   bool isAtomicType() const;// C11 _Atomic()
 
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \

Modified: cfe/trunk/lib/AST/Type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=309058=309057=309058=diff
==
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Tue Jul 25 16:33:58 2017
@@ -2313,6 +2313,15 @@ bool Type::isAlignValT() const {
   return false;
 }
 
+bool Type::isStdByteType() const {
+  if (auto *ET = getAs()) {
+auto *II = ET->getDecl()->getIdentifier();
+if (II && II->isStr("byte") && ET->getDecl()->isInStdNamespace())
+  return true;
+  }
+  return false;
+}
+
 bool Type::isPromotableIntegerType() const {
   if (const BuiltinType *BT = getAs())
 switch (BT->getKind()) {

Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=309058=309057=309058=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Tue Jul 25 16:33:58 2017
@@ -139,6 +139,12 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) {
 }
   }
 
+  // C++1z [basic.lval]p10: "If a program attempts to access the stored value 
of
+  // an object through a glvalue of other than one of the following types the
+  // behavior is undefined: [...] a char, unsigned char, or std::byte type."
+  if (Ty->isStdByteType())
+return MetadataCache[Ty] = getChar();
+
   // Handle pointers.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.

Added: cfe/trunk/test/CodeGenCXX/std-byte.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/std-byte.cpp?rev=309058=auto
==
--- cfe/trunk/test/CodeGenCXX/std-byte.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/std-byte.cpp Tue Jul 25 16:33:58 2017
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++1z -Werror -triple i386-unknown-unknown -emit-llvm 
-O1 -disable-llvm-passes -o - %s | FileCheck %s
+
+// std::byte should be considered equivalent to char for aliasing.
+
+namespace std {
+enum byte : unsigned char {};
+}
+
+// CHECK-LABEL: define void @test0(
+extern "C" void test0(std::byte *sb, int *i) {
+  // CHECK: store i8 0, i8* %{{.*}} !tbaa [[TAG_CHAR:!.*]]
+  *sb = std::byte{0};
+
+  // CHECK: store i32 1, i32* %{{.*}} !tbaa [[TAG_INT:!.*]]
+  *i = 1;
+}
+
+enum byte : unsigned char {};
+namespace my {
+enum byte : unsigned char {};
+namespace std {
+enum byte : unsigned char {};
+} // namespace std
+} // namespace my
+
+// Make sure we don't get confused with other enums named 'byte'.
+
+// CHECK-LABEL: define void @test1(
+extern "C" void test1(::byte *b, ::my::byte *mb, ::my::std::byte *msb) {
+  *b = ::byte{0};
+  *mb = ::my::byte{0};
+  *msb = ::my::std::byte{0};
+  // CHECK-NOT: store i8 0, i8* %{{.*}} !tbaa [[TAG_CHAR]]
+}
+
+// CHECK:  !"any pointer", [[TYPE_CHAR:!.*]],
+// CHECK: [[TYPE_CHAR]] = !{!"omnipotent char", [[TAG_CXX_TBAA:!.*]],
+// CHECK: [[TAG_CXX_TBAA]] = !{!"Simple C++ TBAA"}
+// CHECK: [[TAG_CHAR]] = !{[[TYPE_CHAR:!.*]], [[TYPE_CHAR]], i64 0}
+// CHECK: [[TAG_INT]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0}
+// CHECK: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR]]


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


Re: [libcxx] r307751 - Fix unrepresentable enum for clang-cl unstable ABI

2017-07-11 Thread David Majnemer via cfe-commits
FWIW, I think you could just give the enum an explicit underlying type of
size_type.

On Tue, Jul 11, 2017 at 6:45 PM, Ben Craig via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: bcraig
> Date: Tue Jul 11 18:45:13 2017
> New Revision: 307751
>
> URL: http://llvm.org/viewvc/llvm-project?rev=307751=rev
> Log:
> Fix unrepresentable enum for clang-cl unstable ABI
>
> When using LIBCXX_ABI_UNSTABLE=YES, clang-cl gave the following warning:
>
> P:\llvm_master\src\llvm\projects\libcxx\include\string(683,51):
> warning: enumerator value is not representable in the underlying type
> 'int' [-Wmicrosoft-enum-value]
>
> Fixed by switching from enums to static const size_type.
>
> https://reviews.llvm.org/D35174
>
> Modified:
> libcxx/trunk/include/string
>
> Modified: libcxx/trunk/include/string
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/
> string?rev=307751=307750=307751=diff
> 
> ==
> --- libcxx/trunk/include/string (original)
> +++ libcxx/trunk/include/string Tue Jul 11 18:45:13 2017
> @@ -676,11 +676,11 @@ private:
>  };
>
>  #if _LIBCPP_BIG_ENDIAN
> -enum {__short_mask = 0x01};
> -enum {__long_mask  = 0x1ul};
> +static const size_type __short_mask = 0x01;
> +static const size_type __long_mask  = 0x1ul;
>  #else  // _LIBCPP_BIG_ENDIAN
> -enum {__short_mask = 0x80};
> -enum {__long_mask  = ~(size_type(~0) >> 1)};
> +static const size_type __short_mask = 0x80;
> +static const size_type __long_mask  = ~(size_type(~0) >> 1);
>  #endif  // _LIBCPP_BIG_ENDIAN
>
>  enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
> @@ -706,11 +706,11 @@ private:
>  };
>
>  #if _LIBCPP_BIG_ENDIAN
> -enum {__short_mask = 0x80};
> -enum {__long_mask  = ~(size_type(~0) >> 1)};
> +static const size_type __short_mask = 0x80;
> +static const size_type __long_mask  = ~(size_type(~0) >> 1);
>  #else  // _LIBCPP_BIG_ENDIAN
> -enum {__short_mask = 0x01};
> -enum {__long_mask  = 0x1ul};
> +static const size_type __short_mask = 0x01;
> +static const size_type __long_mask  = 0x1ul;
>  #endif  // _LIBCPP_BIG_ENDIAN
>
>  enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
>
>
> ___
> 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] D31022: Implement P0298R3: `std::byte`

2017-07-05 Thread David Majnemer via cfe-commits
FWIW, doesn't this just need a may_alias attribute on the definition?
On Wed, Jul 5, 2017 at 2:39 PM James Y Knight via Phabricator via
cfe-commits  wrote:

> jyknight added a comment.
>
> Ping. I don't think this got resolved, and I really wouldn't like to see
> released in this state...can you either revert this from the library, or
> implement the compiler support, before the 5.0 release branch?
>
> In https://reviews.llvm.org/D31022#716702, @jyknight wrote:
>
> > I believe this needs compiler support, too, in order to treat
> >
> >   namespace std { enum class byte : unsigned char {}; }
> >
> > as directly having tbaa type "omnipotent char" instead of a subtype.
> >
> > That is, given:
> >
> >   void foo(char* x, int *y) {
> > x[1] = char(y[0] & 0xff);
> > x[0] = char((y[0] & 0xff00) >> 8);
> >   }
> >
> > the compiler assumes that x and y might alias each-other, and thus must
> have two loads of y[0]. If you replace "char" with "std::byte", the same
> should happen, but as of now does not.
>
>
>
>
>
> https://reviews.llvm.org/D31022
>
>
>
> ___
> 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] D34972: [CodeGen] Propagate dllexport to thunks

2017-07-05 Thread David Majnemer via cfe-commits
If the thinks are not imported, why would it make sense to export them?

Maybe devirtualization could trigger this?

On Wed, Jul 5, 2017 at 1:17 PM Shoaib Meenai <smee...@fb.com> wrote:

> The thunks are (as far as I know, at least) only referenced from vtables,
> so
> there's no opportunity to perform indirect calls via the IAT for them. The
> vtable would just end up referencing the linker-generated import thunk
> instead.
>
> I can play around with marking the thunks as dllimport if the function
> being
> thunked is dllimport, but I was curious if you had any specific scenarios
> in
> mind where you thought it would make a difference.
>
> From: cfe-commits <cfe-commits-boun...@lists.llvm.org> on behalf of David
> Majnemer via cfe-commits <cfe-commits@lists.llvm.org>
> Reply-To: David Majnemer <david.majne...@gmail.com>
> Date: Tuesday, July 4, 2017 at 8:42 AM
> To: Shoaib Meenai via Phabricator <revi...@reviews.llvm.org>, "
> compn...@compnerd.org" <compn...@compnerd.org>, "
> reviews+d34972+public+8a22767368a5b...@reviews.llvm.org" <
> reviews+d34972+public+8a22767368a5b...@reviews.llvm.org>, "r...@google.com"
> <r...@google.com>
> Cc: "ztur...@google.com" <ztur...@google.com>, "cfe-commits@lists.llvm.org"
> <cfe-commits@lists.llvm.org>
> Subject: Re: [PATCH] D34972: [CodeGen] Propagate dllexport to thunks
>
> What about the import side?
>
> On Mon, Jul 3, 2017 at 10:37 PM Shoaib Meenai via Phabricator via
> cfe-commits <cfe-commits@lists.llvm.org> wrote:
> smeenai created this revision.
>
> Under Windows Itanium, we need to export virtual and non-virtual thunks
> if the functions being thunked are exported. These thunks would
> previously inherit their dllexport attribute from the declaration, but
> r298330 changed declarations to not have dllexport attributes. We
> therefore need to add the dllexport attribute to the definition
> ourselves now. This is consistent with MinGW GCC's behavior.
>
> This redoes r306770 but limits the logic to Itanium. MicrosoftCXXABI's
> setThunkLinkage ensures that thunks aren't exported under that ABI, so
> I'm handling this in ItaniumCXXABI's setThunkLinkage for symmetry.
>
>
> https://reviews.llvm.org/D34972
>
> Files:
>   lib/CodeGen/ItaniumCXXABI.cpp
>   test/CodeGenCXX/dllexport-vtable-thunks.cpp
>
>
> Index: test/CodeGenCXX/dllexport-vtable-thunks.cpp
> ===
> --- /dev/null
> +++ test/CodeGenCXX/dllexport-vtable-thunks.cpp
> @@ -0,0 +1,23 @@
> +// RUN: %clang_cc1 -triple x86_64-windows-gnu -fdeclspec -emit-llvm -o -
> %s | FileCheck %s
> +// RUN: %clang_cc1 -triple x86_64-windows-itanium -fdeclspec -emit-llvm
> -o - %s | FileCheck %s
> +
> +struct __declspec(dllexport) A {
> +  virtual void m();
> +};
> +struct __declspec(dllexport) B {
> +  virtual void m();
> +};
> +struct __declspec(dllexport) C : A, B {
> +  virtual void m();
> +};
> +void C::m() {}
> +// CHECK: define dllexport void @_ZThn8_N1C1mEv
> +
> +struct Base {
> +  virtual void m();
> +};
> +struct __declspec(dllexport) Derived : virtual Base {
> +  virtual void m();
> +};
> +void Derived::m() {}
> +// CHECK: define dllexport void @_ZTv0_n24_N7Derived1mEv
> Index: lib/CodeGen/ItaniumCXXABI.cpp
> ===
> --- lib/CodeGen/ItaniumCXXABI.cpp
> +++ lib/CodeGen/ItaniumCXXABI.cpp
> @@ -284,6 +284,11 @@
>  // linkage together with vtables when needed.
>  if (ForVTable && !Thunk->hasLocalLinkage())
>Thunk->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
> +
> +// Propagate dllexport storage.
> +const CXXMethodDecl *MD = cast(GD.getDecl());
> +if (MD->hasAttr())
> +  Thunk->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
>}
>
>llvm::Value *performThisAdjustment(CodeGenFunction , Address This,
>
>
> ___
> 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] D34992: Emit static constexpr member as available_externally definition

2017-07-05 Thread David Majnemer via cfe-commits
On Wed, Jul 5, 2017 at 12:22 PM Mehdi AMINI  wrote:

> The LLVM verifier is complaining that dllimport have to be external
> linkage and isn't happy with available_externally, is the verifier wrong?
>

IMO, yes. I imagine that it is fine with dllimport available_externally
functions already.


> 2017-07-05 9:12 GMT-07:00 David Majnemer :
>
>> I don't think you need the dllimport restriction.
>>
>> On Wed, Jul 5, 2017 at 12:05 PM Alex Lorenz via Phabricator via
>> cfe-commits  wrote:
>>
>>> arphaman added a comment.
>>>
>>> Does this apply to all constexpr global variables? It could potentially
>>> fix https://bugs.llvm.org/show_bug.cgi?id=31860 .
>>>
>>>
>>> https://reviews.llvm.org/D34992
>>>
>>>
>>>
>>> ___
>>> 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] D34992: Emit static constexpr member as available_externally definition

2017-07-05 Thread David Majnemer via cfe-commits
I don't think you need the dllimport restriction.

On Wed, Jul 5, 2017 at 12:05 PM Alex Lorenz via Phabricator via cfe-commits
 wrote:

> arphaman added a comment.
>
> Does this apply to all constexpr global variables? It could potentially
> fix https://bugs.llvm.org/show_bug.cgi?id=31860 .
>
>
> https://reviews.llvm.org/D34992
>
>
>
> ___
> 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] D34972: [CodeGen] Propagate dllexport to thunks

2017-07-05 Thread David Majnemer via cfe-commits
What about the import side?

On Mon, Jul 3, 2017 at 10:37 PM Shoaib Meenai via Phabricator via
cfe-commits  wrote:

> smeenai created this revision.
>
> Under Windows Itanium, we need to export virtual and non-virtual thunks
> if the functions being thunked are exported. These thunks would
> previously inherit their dllexport attribute from the declaration, but
> r298330 changed declarations to not have dllexport attributes. We
> therefore need to add the dllexport attribute to the definition
> ourselves now. This is consistent with MinGW GCC's behavior.
>
> This redoes r306770 but limits the logic to Itanium. MicrosoftCXXABI's
> setThunkLinkage ensures that thunks aren't exported under that ABI, so
> I'm handling this in ItaniumCXXABI's setThunkLinkage for symmetry.
>
>
> https://reviews.llvm.org/D34972
>
> Files:
>   lib/CodeGen/ItaniumCXXABI.cpp
>   test/CodeGenCXX/dllexport-vtable-thunks.cpp
>
>
> Index: test/CodeGenCXX/dllexport-vtable-thunks.cpp
> ===
> --- /dev/null
> +++ test/CodeGenCXX/dllexport-vtable-thunks.cpp
> @@ -0,0 +1,23 @@
> +// RUN: %clang_cc1 -triple x86_64-windows-gnu -fdeclspec -emit-llvm -o -
> %s | FileCheck %s
> +// RUN: %clang_cc1 -triple x86_64-windows-itanium -fdeclspec -emit-llvm
> -o - %s | FileCheck %s
> +
> +struct __declspec(dllexport) A {
> +  virtual void m();
> +};
> +struct __declspec(dllexport) B {
> +  virtual void m();
> +};
> +struct __declspec(dllexport) C : A, B {
> +  virtual void m();
> +};
> +void C::m() {}
> +// CHECK: define dllexport void @_ZThn8_N1C1mEv
> +
> +struct Base {
> +  virtual void m();
> +};
> +struct __declspec(dllexport) Derived : virtual Base {
> +  virtual void m();
> +};
> +void Derived::m() {}
> +// CHECK: define dllexport void @_ZTv0_n24_N7Derived1mEv
> Index: lib/CodeGen/ItaniumCXXABI.cpp
> ===
> --- lib/CodeGen/ItaniumCXXABI.cpp
> +++ lib/CodeGen/ItaniumCXXABI.cpp
> @@ -284,6 +284,11 @@
>  // linkage together with vtables when needed.
>  if (ForVTable && !Thunk->hasLocalLinkage())
>Thunk->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
> +
> +// Propagate dllexport storage.
> +const CXXMethodDecl *MD = cast(GD.getDecl());
> +if (MD->hasAttr())
> +  Thunk->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
>}
>
>llvm::Value *performThisAdjustment(CodeGenFunction , Address This,
>
>
> ___
> 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] D32435: clang-cl: Add support for /permissive-

2017-04-25 Thread David Majnemer via cfe-commits
On Tue, Apr 25, 2017 at 2:12 PM, Nico Weber  wrote:

> On Tue, Apr 25, 2017 at 4:14 PM, David Majnemer 
> wrote:
>
>>
>>
>> On Tue, Apr 25, 2017 at 11:42 AM, Nico Weber  wrote:
>>
>>> On Tue, Apr 25, 2017 at 2:06 PM, David Majnemer <
>>> david.majne...@gmail.com> wrote:
>>>


 On Tue, Apr 25, 2017 at 8:46 AM, Nico Weber 
 wrote:

> On Mon, Apr 24, 2017 at 10:00 PM, David Majnemer <
> david.majne...@gmail.com> wrote:
>
>>
>>
>> On Mon, Apr 24, 2017 at 11:56 AM, Nico Weber 
>> wrote:
>>
>>> "Opting into the conforming mode, /permissive-, during the series of
>>> VS 2017 update is a commitment to keeping your code base clean and to
>>> fixing non-conforming constructs we fix conformance issues in Visual 
>>> C++."
>>> [...] "By contrast /permissive- offers a useful conformance mode where
>>> input C++ code is interpreted according to ISO C++ rules but also allows
>>> conforming extensions necessary to compile C++ on targets supported by
>>> Visual C++."
>>>
>>> I guess the second quote agrees with your interpretation.
>>>
>>> We already diag most of the things they already mention. The one
>>> thing we don't diag by default is Wmicrosoft-enum-forward-reference
>>> since that's only an Extension and not an ExtWarn. We don't expose
>>> -pedantic from clang-cl, so this seemed like a somewhat natural mapping 
>>> to
>>> me.
>>>
>>> Should /permissive- map to -Wmicrosoft instead and turn on the parts
>>> of -Wmicrosoft that are Extensions?
>>>
>>
>> Did you mean on or off?
>>
>
> On.
>
>
>> I think that their intent is that things like __declspec remain OK.
>>
>
> Nothing in -Wmicrosoft warns on __declspec.
>
>
>> They want to diagnose non-conforming extensions like crazy template
>> stuff, bogus typedef syntax, bad main function definitions, etc.
>>
>
> Right. The only thing it currently makes cl warn on that clang-cl
> doesn't warn on by default is Wmicrosoft-enum-forward-reference,
> which is an Extension warning, not an ExtWarn. So mapping /permissive- to
> -Wmicrosoft would make clang-cl diagnose forward-declared enums like it
> does with 2017 cl.
>

 Ok, sounds like it diagnoses the same sorts of things. They diagnose as
 error though, I think we should too. What about -fdelayed-template-parsing?
 Shouldn't that be disabled?

>>>
>>> CL has added a /Zc:twoPhase for that (not yet released anywhere), and
>>> Hans added support for that to clang-cl a while ago. Some blog post (maybe
>>> the one I linked to?) says that they're thinking of possibly
>>> enabling /Zc:twoPhase when /permissive- is passed, but at the moment it's
>>> independent. (In part because /permissive- ships in VC2017 and /Zc:twoPhase
>>> hasn't been shipped yet).
>>>
>>
>> Ok.
>>
>>
>>>
>>> What's the advantage of making it an error?
>>>
>>
>> All the diagnostics they show in https://blogs.msdn.microsof
>> t.com/vcblog/2016/11/16/permissive-switch/ diagnose as errors.
>>
>
> But why should we match that? Having them be warnings seems like a better
> user experience to me.
>

I think the thinking behind the flag is that they want folks to be able to
make their code more standards compliant. I imagine that anybody who turns
the flag on understands what they are getting themselves into.

IMO, the biggest reason why it should match their diagnostic level is
because builds could otherwise break if a project has /permissive- but
clang-cl allows a build to continue while cl would not.


>
>
>>
>>
>>> If it's a warning, you can pass -Werror separately if you want. And
>>> SFINAE'ing on this seems like asking for trouble.
>>>
>>
>> I said nothing about permitting SFINAE on these errors.
>>
>>
>>>
>>>


>
>
>>
>>
>>> Should we just ignore /permissive- and possibly make some of our
>>> -Wmicrosoft Extensions ExtWarns instead?
>>>
>>> On Mon, Apr 24, 2017 at 2:10 PM, David Majnemer <
>>> david.majne...@gmail.com> wrote:
>>>
 -pedantic means "Issue all the warnings demanded by strict ISO C
 and ISO C++; reject all programs that use forbidden extensions, and 
 some
 other programs that do not follow ISO C and ISO C++."
 I believe it is more akin to -fno-ms-compatibility as it disables
 compatibility hacks.

 On Mon, Apr 24, 2017 at 11:02 AM, Nico Weber 
 wrote:

> It does sound pretty similar to me from the blog post. I think
> this is a decent place to start from.
>
> On Apr 24, 2017 11:55 AM, "David Majnemer via Phabricator via
> cfe-commits"  wrote:
>
>> majnemer requested 

Re: [PATCH] D32435: clang-cl: Add support for /permissive-

2017-04-25 Thread David Majnemer via cfe-commits
On Tue, Apr 25, 2017 at 11:42 AM, Nico Weber  wrote:

> On Tue, Apr 25, 2017 at 2:06 PM, David Majnemer 
> wrote:
>
>>
>>
>> On Tue, Apr 25, 2017 at 8:46 AM, Nico Weber  wrote:
>>
>>> On Mon, Apr 24, 2017 at 10:00 PM, David Majnemer <
>>> david.majne...@gmail.com> wrote:
>>>


 On Mon, Apr 24, 2017 at 11:56 AM, Nico Weber 
 wrote:

> "Opting into the conforming mode, /permissive-, during the series of
> VS 2017 update is a commitment to keeping your code base clean and to
> fixing non-conforming constructs we fix conformance issues in Visual C++."
> [...] "By contrast /permissive- offers a useful conformance mode where
> input C++ code is interpreted according to ISO C++ rules but also allows
> conforming extensions necessary to compile C++ on targets supported by
> Visual C++."
>
> I guess the second quote agrees with your interpretation.
>
> We already diag most of the things they already mention. The one thing
> we don't diag by default is Wmicrosoft-enum-forward-reference since
> that's only an Extension and not an ExtWarn. We don't expose -pedantic 
> from
> clang-cl, so this seemed like a somewhat natural mapping to me.
>
> Should /permissive- map to -Wmicrosoft instead and turn on the parts
> of -Wmicrosoft that are Extensions?
>

 Did you mean on or off?

>>>
>>> On.
>>>
>>>
 I think that their intent is that things like __declspec remain OK.

>>>
>>> Nothing in -Wmicrosoft warns on __declspec.
>>>
>>>
 They want to diagnose non-conforming extensions like crazy template
 stuff, bogus typedef syntax, bad main function definitions, etc.

>>>
>>> Right. The only thing it currently makes cl warn on that clang-cl
>>> doesn't warn on by default is Wmicrosoft-enum-forward-reference, which
>>> is an Extension warning, not an ExtWarn. So mapping /permissive- to
>>> -Wmicrosoft would make clang-cl diagnose forward-declared enums like it
>>> does with 2017 cl.
>>>
>>
>> Ok, sounds like it diagnoses the same sorts of things. They diagnose as
>> error though, I think we should too. What about -fdelayed-template-parsing?
>> Shouldn't that be disabled?
>>
>
> CL has added a /Zc:twoPhase for that (not yet released anywhere), and Hans
> added support for that to clang-cl a while ago. Some blog post (maybe the
> one I linked to?) says that they're thinking of possibly
> enabling /Zc:twoPhase when /permissive- is passed, but at the moment it's
> independent. (In part because /permissive- ships in VC2017 and /Zc:twoPhase
> hasn't been shipped yet).
>

Ok.


>
> What's the advantage of making it an error?
>

All the diagnostics they show in
https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/
diagnose as errors.


> If it's a warning, you can pass -Werror separately if you want. And
> SFINAE'ing on this seems like asking for trouble.
>

I said nothing about permitting SFINAE on these errors.


>
>
>>
>>
>>>
>>>


> Should we just ignore /permissive- and possibly make some of our
> -Wmicrosoft Extensions ExtWarns instead?
>
> On Mon, Apr 24, 2017 at 2:10 PM, David Majnemer <
> david.majne...@gmail.com> wrote:
>
>> -pedantic means "Issue all the warnings demanded by strict ISO C and
>> ISO C++; reject all programs that use forbidden extensions, and some 
>> other
>> programs that do not follow ISO C and ISO C++."
>> I believe it is more akin to -fno-ms-compatibility as it disables
>> compatibility hacks.
>>
>> On Mon, Apr 24, 2017 at 11:02 AM, Nico Weber 
>> wrote:
>>
>>> It does sound pretty similar to me from the blog post. I think this
>>> is a decent place to start from.
>>>
>>> On Apr 24, 2017 11:55 AM, "David Majnemer via Phabricator via
>>> cfe-commits"  wrote:
>>>
 majnemer requested changes to this revision.
 majnemer added a comment.
 This revision now requires changes to proceed.

 I don't think this is correct. GDR (of Microsoft) says the behavior
 is different: https://www.reddit.com/r/cpp/comm
 
   LOG(INFO) << "n_window_index: " << n_window_index;
 ents/5dh7j5/visual_c_introduces_permissive_for_conformance/da5fxjj/
 


 https://reviews.llvm.org/D32435



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

>>>
>>
>

>>>
>>
>

Re: [PATCH] D32435: clang-cl: Add support for /permissive-

2017-04-25 Thread David Majnemer via cfe-commits
On Tue, Apr 25, 2017 at 8:46 AM, Nico Weber  wrote:

> On Mon, Apr 24, 2017 at 10:00 PM, David Majnemer  > wrote:
>
>>
>>
>> On Mon, Apr 24, 2017 at 11:56 AM, Nico Weber  wrote:
>>
>>> "Opting into the conforming mode, /permissive-, during the series of VS
>>> 2017 update is a commitment to keeping your code base clean and to fixing
>>> non-conforming constructs we fix conformance issues in Visual C++." [...]
>>> "By contrast /permissive- offers a useful conformance mode where input C++
>>> code is interpreted according to ISO C++ rules but also allows conforming
>>> extensions necessary to compile C++ on targets supported by Visual C++."
>>>
>>> I guess the second quote agrees with your interpretation.
>>>
>>> We already diag most of the things they already mention. The one thing
>>> we don't diag by default is Wmicrosoft-enum-forward-reference since
>>> that's only an Extension and not an ExtWarn. We don't expose -pedantic from
>>> clang-cl, so this seemed like a somewhat natural mapping to me.
>>>
>>> Should /permissive- map to -Wmicrosoft instead and turn on the parts of
>>> -Wmicrosoft that are Extensions?
>>>
>>
>> Did you mean on or off?
>>
>
> On.
>
>
>> I think that their intent is that things like __declspec remain OK.
>>
>
> Nothing in -Wmicrosoft warns on __declspec.
>
>
>> They want to diagnose non-conforming extensions like crazy template
>> stuff, bogus typedef syntax, bad main function definitions, etc.
>>
>
> Right. The only thing it currently makes cl warn on that clang-cl doesn't
> warn on by default is Wmicrosoft-enum-forward-reference, which is an
> Extension warning, not an ExtWarn. So mapping /permissive- to -Wmicrosoft
> would make clang-cl diagnose forward-declared enums like it does with 2017
> cl.
>

Ok, sounds like it diagnoses the same sorts of things. They diagnose as
error though, I think we should too. What about -fdelayed-template-parsing?
Shouldn't that be disabled?


>
>
>>
>>
>>> Should we just ignore /permissive- and possibly make some of our
>>> -Wmicrosoft Extensions ExtWarns instead?
>>>
>>> On Mon, Apr 24, 2017 at 2:10 PM, David Majnemer <
>>> david.majne...@gmail.com> wrote:
>>>
 -pedantic means "Issue all the warnings demanded by strict ISO C and
 ISO C++; reject all programs that use forbidden extensions, and some other
 programs that do not follow ISO C and ISO C++."
 I believe it is more akin to -fno-ms-compatibility as it disables
 compatibility hacks.

 On Mon, Apr 24, 2017 at 11:02 AM, Nico Weber 
 wrote:

> It does sound pretty similar to me from the blog post. I think this is
> a decent place to start from.
>
> On Apr 24, 2017 11:55 AM, "David Majnemer via Phabricator via
> cfe-commits"  wrote:
>
>> majnemer requested changes to this revision.
>> majnemer added a comment.
>> This revision now requires changes to proceed.
>>
>> I don't think this is correct. GDR (of Microsoft) says the behavior
>> is different: https://www.reddit.com/r/cpp/comm
>> 
>>   LOG(INFO) << "n_window_index: " << n_window_index;
>> ents/5dh7j5/visual_c_introduces_permissive_for_conformance/da5fxjj/
>> 
>>
>>
>> https://reviews.llvm.org/D32435
>>
>>
>>
>> ___
>> 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] D32435: clang-cl: Add support for /permissive-

2017-04-24 Thread David Majnemer via cfe-commits
On Mon, Apr 24, 2017 at 11:56 AM, Nico Weber  wrote:

> "Opting into the conforming mode, /permissive-, during the series of VS
> 2017 update is a commitment to keeping your code base clean and to fixing
> non-conforming constructs we fix conformance issues in Visual C++." [...]
> "By contrast /permissive- offers a useful conformance mode where input C++
> code is interpreted according to ISO C++ rules but also allows conforming
> extensions necessary to compile C++ on targets supported by Visual C++."
>
> I guess the second quote agrees with your interpretation.
>
> We already diag most of the things they already mention. The one thing we
> don't diag by default is Wmicrosoft-enum-forward-reference since that's
> only an Extension and not an ExtWarn. We don't expose -pedantic from
> clang-cl, so this seemed like a somewhat natural mapping to me.
>
> Should /permissive- map to -Wmicrosoft instead and turn on the parts of
> -Wmicrosoft that are Extensions?
>

Did you mean on or off? I think that their intent is that things like
__declspec remain OK. They want to diagnose non-conforming extensions like
crazy template stuff, bogus typedef syntax, bad main function definitions,
etc.


> Should we just ignore /permissive- and possibly make some of our
> -Wmicrosoft Extensions ExtWarns instead?
>
> On Mon, Apr 24, 2017 at 2:10 PM, David Majnemer 
> wrote:
>
>> -pedantic means "Issue all the warnings demanded by strict ISO C and ISO
>> C++; reject all programs that use forbidden extensions, and some other
>> programs that do not follow ISO C and ISO C++."
>> I believe it is more akin to -fno-ms-compatibility as it disables
>> compatibility hacks.
>>
>> On Mon, Apr 24, 2017 at 11:02 AM, Nico Weber  wrote:
>>
>>> It does sound pretty similar to me from the blog post. I think this is a
>>> decent place to start from.
>>>
>>> On Apr 24, 2017 11:55 AM, "David Majnemer via Phabricator via
>>> cfe-commits"  wrote:
>>>
 majnemer requested changes to this revision.
 majnemer added a comment.
 This revision now requires changes to proceed.

 I don't think this is correct. GDR (of Microsoft) says the behavior is
 different: https://www.reddit.com/r/cpp/comm
 
   LOG(INFO) << "n_window_index: " << n_window_index;
 ents/5dh7j5/visual_c_introduces_permissive_for_conformance/da5fxjj/
 


 https://reviews.llvm.org/D32435



 ___
 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] D32435: clang-cl: Add support for /permissive-

2017-04-24 Thread David Majnemer via cfe-commits
-pedantic means "Issue all the warnings demanded by strict ISO C and ISO
C++; reject all programs that use forbidden extensions, and some other
programs that do not follow ISO C and ISO C++."
I believe it is more akin to -fno-ms-compatibility as it disables
compatibility hacks.

On Mon, Apr 24, 2017 at 11:02 AM, Nico Weber  wrote:

> It does sound pretty similar to me from the blog post. I think this is a
> decent place to start from.
>
> On Apr 24, 2017 11:55 AM, "David Majnemer via Phabricator via cfe-commits"
>  wrote:
>
>> majnemer requested changes to this revision.
>> majnemer added a comment.
>> This revision now requires changes to proceed.
>>
>> I don't think this is correct. GDR (of Microsoft) says the behavior is
>> different: https://www.reddit.com/r/cpp/comments/5dh7j5/visual_c_introd
>> uces_permissive_for_conformance/da5fxjj/
>>
>>
>> https://reviews.llvm.org/D32435
>>
>>
>>
>> ___
>> 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: r299774 - Sema: prevent __declspec(naked) use on x64

2017-04-07 Thread David Majnemer via cfe-commits
On Fri, Apr 7, 2017 at 8:30 AM, Aaron Ballman via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Fri, Apr 7, 2017 at 11:13 AM, Saleem Abdulrasool via cfe-commits
>  wrote:
> > Author: compnerd
> > Date: Fri Apr  7 10:13:47 2017
> > New Revision: 299774
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=299774=rev
> > Log:
> > Sema: prevent __declspec(naked) use on x64
> >
> > MSDN (https://msdn.microsoft.com/en-us/library/h5w10wxs.aspx) indicates
> > that `__declspec(naked)` is only permitted on x86 and ARM targets.
> > Testing with cl does confirm this behaviour.  Provide a warning for use
> > of `__declspec(naked)` on x64.
>
> Your patch is not providing a warning, it's providing an error, which
> seems inappropriate (to me). Why is this attribute not silently
> ignored there instead?
>

FWIW, MSVC diagnoses this with an error: https://godbolt.org/g/T5sQr5


>
> (Btw, I did not see a review thread for this, did I miss one?) More
> comments below.
>
> >
> > Added:
> > cfe/trunk/test/Sema/declspec-naked.c
> > Modified:
> > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> > cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> > cfe/trunk/test/Sema/ms-inline-asm.c
> >
> > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
> DiagnosticSemaKinds.td?rev=299774=299773=299774=diff
> > 
> ==
> > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr  7
> 10:13:47 2017
> > @@ -3231,7 +3231,8 @@ def err_attribute_regparm_invalid_number
> >"'regparm' parameter must be between 0 and %0 inclusive">;
> >  def err_attribute_not_supported_in_lang : Error<
> >"%0 attribute is not supported in %select{C|C++|Objective-C}1">;
> > -
> > +def err_attribute_not_supported_on_arch
> > +: Error<"%0 attribute is not supported on '%1'">;
> >
> >  // Clang-Specific Attributes
> >  def warn_attribute_iboutlet : Warning<
> >
> > Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaDeclAttr.cpp?rev=299774=299773=299774=diff
> > 
> ==
> > --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr  7 10:13:47 2017
> > @@ -1923,6 +1923,17 @@ static void handleNakedAttr(Sema , Dec
> >   Attr.getName()))
> >  return;
> >
> > +  if (Attr.isDeclspecAttribute()) {
> > +const auto  = S.getASTContext().getTargetInfo().getTriple();
>
> No need to have the Triple variable (which is a rather poor name given
> that it's also the type name).
> > +const auto  = Triple.getArch();
>
> Do not use auto for either of these.
>
> ~Aaron
>
> > +if (Arch != llvm::Triple::x86 &&
> > +(Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
> > +  S.Diag(Attr.getLoc(), diag::err_attribute_not_supported_on_arch)
> > +  << Attr.getName() << Triple.getArchName();
> > +  return;
> > +}
> > +  }
> > +
> >D->addAttr(::new (S.Context) NakedAttr(Attr.getRange(), S.Context,
> >   Attr.
> getAttributeSpellingListIndex()));
> >  }
> >
> > Added: cfe/trunk/test/Sema/declspec-naked.c
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/
> declspec-naked.c?rev=299774=auto
> > 
> ==
> > --- cfe/trunk/test/Sema/declspec-naked.c (added)
> > +++ cfe/trunk/test/Sema/declspec-naked.c Fri Apr  7 10:13:47 2017
> > @@ -0,0 +1,11 @@
> > +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only
> -fdeclspec -verify %s
> > +// RUN: %clang_cc1 -triple thumbv7-unknown-windows-msvc -fsyntax-only
> -fdeclspec -verify %s
> > +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only
> -fdeclspec -verify %s
> > +#if defined(_M_IX86) || defined(_M_ARM)
> > +// CHECK: expected-no-diagnostics
> > +#endif
> > +
> > +void __declspec(naked) f(void) {}
> > +#if !defined(_M_IX86) && !defined(_M_ARM)
> > +// expected-error@-2{{'naked' attribute is not supported on 'x86_64'}}
> > +#endif
> >
> > Modified: cfe/trunk/test/Sema/ms-inline-asm.c
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/
> ms-inline-asm.c?rev=299774=299773=299774=diff
> > 
> ==
> > --- cfe/trunk/test/Sema/ms-inline-asm.c (original)
> > +++ cfe/trunk/test/Sema/ms-inline-asm.c Fri Apr  7 10:13:47 2017
> > @@ -1,5 +1,5 @@
> >  // REQUIRES: x86-registered-target
> > -// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fms-extensions
> -fasm-blocks -Wno-microsoft -Wunused-label -verify -fsyntax-only
> > +// RUN: %clang_cc1 

Re: r299058 - [APInt] Remove references to integerPartWidth and integerPart outside of APFloat implentation.

2017-03-30 Thread David Majnemer via cfe-commits
On Thu, Mar 30, 2017 at 7:48 AM, Craig Topper via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ctopper
> Date: Thu Mar 30 00:48:58 2017
> New Revision: 299058
>
> URL: http://llvm.org/viewvc/llvm-project?rev=299058=rev
> Log:
> [APInt] Remove references to integerPartWidth and integerPart outside of
> APFloat implentation.
>
> Turns out integerPartWidth only explicitly defines the width of the tc
> functions in the APInt class. Functions that aren't used by APInt
> implementation itself. Many places in the code base already assume APInt is
> made up of 64-bit pieces. Explicitly assuming 64-bit here doesn't make that
> situation much worse. A full audit would need to be done if it ever changes.
>
> Modified:
> cfe/trunk/lib/AST/ItaniumMangle.cpp
>
> Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ItaniumMangle.cpp?rev=299058=299057=299058=diff
> 
> ==
> --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
> +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Thu Mar 30 00:48:58 2017
> @@ -982,9 +982,8 @@ void CXXNameMangler::mangleFloat(const l
>  unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
>
>  // Project out 4 bits starting at 'digitIndex'.
> -llvm::integerPart hexDigit
> -  = valueBits.getRawData()[digitBitIndex / llvm::integerPartWidth];
> -hexDigit >>= (digitBitIndex % llvm::integerPartWidth);
> +uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
> +hexDigit >>= (digitBitIndex % 64);
>

Would be nice to use APINT_BITS_PER_WORD to make this coupling more
explicit.


>  hexDigit &= 0xF;
>
>  // Map that over to a lowercase hex digit.
>
>
> ___
> 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: r298765 - Add the _CALL_LINUX preprocessor define for ppc linux platforms.

2017-03-25 Thread David Majnemer via cfe-commits
Shouldn't this only be defined on 64-bit PPC platforms? I think that's what
GCC does:
https://github.com/gcc-mirror/gcc/blob/700a97608cadfe8adcd1a98e6388a5cbee9d76f6/gcc/config/rs6000/linux64.h#L372

On Fri, Mar 24, 2017 at 8:33 PM, Eric Christopher via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: echristo
> Date: Fri Mar 24 22:33:59 2017
> New Revision: 298765
>
> URL: http://llvm.org/viewvc/llvm-project?rev=298765=rev
> Log:
> Add the _CALL_LINUX preprocessor define for ppc linux platforms.
>
> This typically is only for a new enough linker (bfd >= 2.16.2 or gold), but
> our ppc suppport post-dates this and it should work on all linux
> platforms. It
> is guaranteed to work on all elfv2 platforms.
>
> Modified:
> cfe/trunk/lib/Basic/Targets.cpp
> cfe/trunk/test/Preprocessor/init.c
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/
> Targets.cpp?rev=298765=298764=298765=diff
> 
> ==
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Fri Mar 24 22:33:59 2017
> @@ -1237,6 +1237,12 @@ void PPCTargetInfo::getTargetDefines(con
>if (ABI == "elfv2")
>  Builder.defineMacro("_CALL_ELF", "2");
>
> +  // This typically is only for a new enough linker (bfd >= 2.16.2 or
> gold), but
> +  // our suppport post-dates this and it should work on all linux
> platforms. It
> +  // is guaranteed to work on all elfv2 platforms.
> +  if (getTriple().getOS() == llvm::Triple::Linux)
> +Builder.defineMacro("_CALL_LINUX", "1");
> +
>// Subtarget options.
>Builder.defineMacro("__NATURAL_ALIGNMENT__");
>Builder.defineMacro("__REGISTER_PREFIX__", "");
>
> Modified: cfe/trunk/test/Preprocessor/init.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> Preprocessor/init.c?rev=298765=298764=298765=diff
> 
> ==
> --- cfe/trunk/test/Preprocessor/init.c (original)
> +++ cfe/trunk/test/Preprocessor/init.c Fri Mar 24 22:33:59 2017
> @@ -6144,6 +6144,7 @@
>  // PPC64-LINUX:#define _ARCH_PPC 1
>  // PPC64-LINUX:#define _ARCH_PPC64 1
>  // PPC64-LINUX:#define _BIG_ENDIAN 1
> +// PPC64-LINUX:#define _CALL_LINUX 1
>  // PPC64-LINUX:#define _LP64 1
>  // PPC64-LINUX:#define __BIGGEST_ALIGNMENT__ 16
>  // PPC64-LINUX:#define __BIG_ENDIAN__ 1
> @@ -6346,6 +6347,11 @@
>  // PPC64-ELFv1:#define _CALL_ELF 1
>  // PPC64-ELFv2:#define _CALL_ELF 2
>  //
> +// Most of this is encompassed in other places.
> +// RUN: %clang_cc1 -E -dM -ffreestanding 
> -triple=powerpc64le-unknown-linux-gnu
> -target-abi elfv2 < /dev/null | FileCheck -match-full-lines -check-prefix
> PPC64LE-LINUX %s
> +//
> +// PPC64LE-LINUX:#define _CALL_LINUX 1
> +//
>  // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-none-none
> -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix
> PPC %s
>  //
>  // PPC:#define _ARCH_PPC 1
>
>
> ___
> 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


r295010 - [MS ABI] Correctly mangling vbase destructors

2017-02-13 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Mon Feb 13 18:54:11 2017
New Revision: 295010

URL: http://llvm.org/viewvc/llvm-project?rev=295010=rev
Log:
[MS ABI] Correctly mangling vbase destructors

They are a little bit of a special case in the mangling. They are always
mangled without taking into account their virtual-ness of the
destructor. They are also mangled to return void, unlike the actual
destructor.

This fixes PR31931.

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

Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
cfe/trunk/test/CodeGenCXX/exceptions-cxx-new.cpp
cfe/trunk/test/CodeGenCXX/inheriting-constructor.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-throw.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
cfe/trunk/test/CodeGenCXX/regcall.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=295010=295009=295010=diff
==
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Mon Feb 13 18:54:11 2017
@@ -1890,14 +1890,18 @@ void MicrosoftCXXNameMangler::mangleFunc
   //  ::= 
   //   ::= @ # structors (they have no declared return type)
   if (IsStructor) {
-if (isa(D) && isStructorDecl(D) &&
-StructorType == Dtor_Deleting) {
-  // The scalar deleting destructor takes an extra int argument.
-  // However, the FunctionType generated has 0 arguments.
-  // FIXME: This is a temporary hack.
-  // Maybe should fix the FunctionType creation instead?
-  Out << (PointersAre64Bit ? "PEAXI@Z" : "PAXI@Z");
-  return;
+if (isa(D) && isStructorDecl(D)) {
+  // The scalar deleting destructor takes an extra int argument which is 
not
+  // reflected in the AST.
+  if (StructorType == Dtor_Deleting) {
+Out << (PointersAre64Bit ? "PEAXI@Z" : "PAXI@Z");
+return;
+  }
+  // The vbase destructor returns void which is not reflected in the AST.
+  if (StructorType == Dtor_Complete) {
+Out << "XXZ";
+return;
+  }
 }
 if (IsCtorClosure) {
   // Default constructor closure and copy constructor closure both return
@@ -2005,13 +2009,20 @@ void MicrosoftCXXNameMangler::mangleFunc
   //  ::= Y # global near
   //   ::= Z # global far
   if (const CXXMethodDecl *MD = dyn_cast(FD)) {
+bool IsVirtual = MD->isVirtual();
+// When mangling vbase destructor variants, ignore whether or not the
+// underlying destructor was defined to be virtual.
+if (isa(MD) && isStructorDecl(MD) &&
+StructorType == Dtor_Complete) {
+  IsVirtual = false;
+}
 switch (MD->getAccess()) {
   case AS_none:
 llvm_unreachable("Unsupported access specifier");
   case AS_private:
 if (MD->isStatic())
   Out << 'C';
-else if (MD->isVirtual())
+else if (IsVirtual)
   Out << 'E';
 else
   Out << 'A';
@@ -2019,7 +2030,7 @@ void MicrosoftCXXNameMangler::mangleFunc
   case AS_protected:
 if (MD->isStatic())
   Out << 'K';
-else if (MD->isVirtual())
+else if (IsVirtual)
   Out << 'M';
 else
   Out << 'I';
@@ -2027,7 +2038,7 @@ void MicrosoftCXXNameMangler::mangleFunc
   case AS_public:
 if (MD->isStatic())
   Out << 'S';
-else if (MD->isVirtual())
+else if (IsVirtual)
   Out << 'U';
 else
   Out << 'Q';

Modified: cfe/trunk/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp?rev=295010=295009=295010=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp Mon Feb 13 18:54:11 
2017
@@ -5,10 +5,10 @@ struct __declspec(dllexport) T { virtual
 struct __declspec(dllexport) U : S, T { virtual ~U(); };
 
 // CHECK-LABEL: define {{.*}} @"\01??_GS@@UAEPAXI@Z"
-// CHECK: call x86_thiscallcc void @"\01??_DS@@UAE@XZ"(%struct.S* 
%this1){{.*}}!dbg !{{[0-9]+}}
+// CHECK: call x86_thiscallcc void @"\01??_DS@@QAEXXZ"(%struct.S* 
%this1){{.*}}!dbg !{{[0-9]+}}
 
 // CHECK-LABEL: define {{.*}} @"\01??_GT@@UAEPAXI@Z"
-// CHECK: call x86_thiscallcc void @"\01??_DT@@UAE@XZ"(%struct.T* 
%this1){{.*}}!dbg !{{[0-9]+}}
+// CHECK: call x86_thiscallcc void @"\01??_DT@@QAEXXZ"(%struct.T* 
%this1){{.*}}!dbg !{{[0-9]+}}
 
 // CHECK-LABEL: define {{.*}} @"\01??_GU@@UAEPAXI@Z"
-// CHECK: call x86_thiscallcc void @"\01??_DU@@UAE@XZ"(%struct.U* 
%this1){{.*}}!dbg !{{[0-9]+}}
+// CHECK: call 

r292194 - [AST] AttributedType should derive type properties from the EquivalentType

2017-01-16 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Mon Jan 16 22:14:25 2017
New Revision: 292194

URL: http://llvm.org/viewvc/llvm-project?rev=292194=rev
Log:
[AST] AttributedType should derive type properties from the EquivalentType

Using the canonical type instead of the equivalent type can result in
insufficient template instantiations.

This fixes PR31656.

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

Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/test/CodeGenCXX/microsoft-abi-default-cc.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=292194=292193=292194=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Jan 16 22:14:25 2017
@@ -3832,13 +3832,13 @@ private:
 
   friend class ASTContext; // creates these
 
-  AttributedType(QualType canon, Kind attrKind,
- QualType modified, QualType equivalent)
-: Type(Attributed, canon, canon->isDependentType(),
-   canon->isInstantiationDependentType(),
-   canon->isVariablyModifiedType(),
-   canon->containsUnexpandedParameterPack()),
-  ModifiedType(modified), EquivalentType(equivalent) {
+  AttributedType(QualType canon, Kind attrKind, QualType modified,
+ QualType equivalent)
+  : Type(Attributed, canon, equivalent->isDependentType(),
+ equivalent->isInstantiationDependentType(),
+ equivalent->isVariablyModifiedType(),
+ equivalent->containsUnexpandedParameterPack()),
+ModifiedType(modified), EquivalentType(equivalent) {
 AttributedTypeBits.AttrKind = attrKind;
   }
 

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-default-cc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-default-cc.cpp?rev=292194=292193=292194=diff
==
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-default-cc.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-default-cc.cpp Mon Jan 16 22:14:25 
2017
@@ -45,3 +45,12 @@ void __cdecl static_baz() {}
 void static_qux() {}
 // GCABI-LABEL: define void @_Z10static_quxv
 // MSABI: define void @"\01?static_qux@@YAXXZ"
+
+namespace PR31656 {
+template 
+void __cdecl callee(int args[I]);
+// GCABI-LABEL: declare void @_ZN7PR316566calleeILi1EEEvPi(
+// MSABI: declare void @"\01??$callee@$00@PR31656@@YAXQAH@Z"(
+
+void caller() { callee<1>(0); }
+}


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


Re: [libcxx] r291192 - config_elast: fix typo (NFC)

2017-01-05 Thread David Majnemer via cfe-commits
On Thu, Jan 5, 2017 at 3:25 PM, Saleem Abdulrasool via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: compnerd
> Date: Thu Jan  5 17:25:44 2017
> New Revision: 291192
>
> URL: http://llvm.org/viewvc/llvm-project?rev=291192=rev
> Log:
> config_elast: fix typo (NFC)
>
> Missed the original typo which was duplicated.  NFC.
>
> Modified:
> libcxx/trunk/src/include/config_elast.h
>
> Modified: libcxx/trunk/src/include/config_elast.h
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/
> include/config_elast.h?rev=291192=291191=291192=diff
> 
> ==
> --- libcxx/trunk/src/include/config_elast.h (original)
> +++ libcxx/trunk/src/include/config_elast.h Thu Jan  5 17:25:44 2017
> @@ -30,7 +30,7 @@
>  // No _LIBCPP_ELAST needed on Apple
>  #elif defined(__sun__)
>  #define _LIBCPP_ELAST ESTALE
> -#elif defined(_LIBCPP_MSCVRT)
> +#elif defined(_LIBCPP_MSVCRT)
>  #define _LIBCPP_ELAST _sys_nerr
>

Isn't ELAST supposed to point to a valid error number? Shouldn't this
be _sys_nerr-1?


>  #else
>  // Warn here so that the person doing the libcxx port has an easier time:
>
>
> ___
> 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


r290509 - [MS ABI] Mangle unnamed enums correctly

2016-12-24 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Sat Dec 24 23:26:02 2016
New Revision: 290509

URL: http://llvm.org/viewvc/llvm-project?rev=290509=rev
Log:
[MS ABI] Mangle unnamed enums correctly

Unnamed enums take the name of the first enumerator they define.

Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=290509=290508=290509=diff
==
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Sat Dec 24 23:26:02 2016
@@ -863,21 +863,28 @@ void MicrosoftCXXNameMangler::mangleUnqu
 }
   }
 
-  llvm::SmallString<64> Name(" Name;
   if (DeclaratorDecl *DD =
   Context.getASTContext().getDeclaratorForUnnamedTagDecl(TD)) {
 // Anonymous types without a name for linkage purposes have their
 // declarator mangled in if they have one.
+Name += "getName();
   } else if (TypedefNameDecl *TND =
  Context.getASTContext().getTypedefNameForUnnamedTagDecl(
  TD)) {
 // Anonymous types without a name for linkage purposes have their
 // associate typedef mangled in if they have one.
+Name += "getName();
+  } else if (auto *ED = dyn_cast(TD)) {
+auto EnumeratorI = ED->enumerator_begin();
+assert(EnumeratorI != ED->enumerator_end());
+Name += "getName();
   } else {
 // Otherwise, number the types using a $S prefix.
-Name += "$S";
+Name += "

r288826 - [MS ABI] Implement more of the Itanium mangling rules

2016-12-06 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Tue Dec  6 11:01:02 2016
New Revision: 288826

URL: http://llvm.org/viewvc/llvm-project?rev=288826=rev
Log:
[MS ABI] Implement more of the Itanium mangling rules

We didn't implement handle corner cases like:
 - lambdas used to initialize a field
 - lambdas in default argument initializers

This fixes PR31197.

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

Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=288826=288825=288826=diff
==
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Tue Dec  6 11:01:02 2016
@@ -66,6 +66,16 @@ struct msvc_hashing_ostream : public llv
   }
 };
 
+static const DeclContext *
+getLambdaDefaultArgumentDeclContext(const Decl *D) {
+  if (const auto *RD = dyn_cast(D))
+if (RD->isLambda())
+  if (const auto *Parm =
+  dyn_cast_or_null(RD->getLambdaContextDecl()))
+return Parm->getDeclContext();
+  return nullptr;
+}
+
 /// \brief Retrieve the declaration context that should be used when mangling
 /// the given declaration.
 static const DeclContext *getEffectiveDeclContext(const Decl *D) {
@@ -75,12 +85,8 @@ static const DeclContext *getEffectiveDe
   // not the case: the lambda closure type ends up living in the context
   // where the function itself resides, because the function declaration itself
   // had not yet been created. Fix the context here.
-  if (const CXXRecordDecl *RD = dyn_cast(D)) {
-if (RD->isLambda())
-  if (ParmVarDecl *ContextParam =
-  dyn_cast_or_null(RD->getLambdaContextDecl()))
-return ContextParam->getDeclContext();
-  }
+  if (const auto *LDADC = getLambdaDefaultArgumentDeclContext(D))
+return LDADC;
 
   // Perform the same check for block literals.
   if (const BlockDecl *BD = dyn_cast(D)) {
@@ -112,14 +118,6 @@ static const FunctionDecl *getStructor(c
   return FD;
 }
 
-static bool isLambda(const NamedDecl *ND) {
-  const CXXRecordDecl *Record = dyn_cast(ND);
-  if (!Record)
-return false;
-
-  return Record->isLambda();
-}
-
 /// MicrosoftMangleContextImpl - Overrides the default MangleContext for the
 /// Microsoft Visual C++ ABI.
 class MicrosoftMangleContextImpl : public MicrosoftMangleContext {
@@ -200,9 +198,11 @@ public:
 
 // Lambda closure types are already numbered, give out a phony number so
 // that they demangle nicely.
-if (isLambda(ND)) {
-  disc = 1;
-  return true;
+if (const auto *RD = dyn_cast(ND)) {
+  if (RD->isLambda()) {
+disc = 1;
+return true;
+  }
 }
 
 // Use the canonical number for externally visible decls.
@@ -824,9 +824,24 @@ void MicrosoftCXXNameMangler::mangleUnqu
   if (const CXXRecordDecl *Record = dyn_cast(TD)) {
 if (Record->isLambda()) {
   llvm::SmallString<10> Name("getLambdaContextDecl();
+  unsigned LambdaManglingNumber = Record->getLambdaManglingNumber();
   unsigned LambdaId;
-  if (Record->getLambdaManglingNumber())
-LambdaId = Record->getLambdaManglingNumber();
+  const ParmVarDecl *Parm =
+  dyn_cast_or_null(LambdaContextDecl);
+  const FunctionDecl *Func =
+  Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
+
+  if (Func) {
+unsigned DefaultArgNo =
+Func->getNumParams() - Parm->getFunctionScopeIndex();
+Name += llvm::utostr(DefaultArgNo);
+Name += "_";
+  }
+
+  if (LambdaManglingNumber)
+LambdaId = LambdaManglingNumber;
   else
 LambdaId = Context.getLambdaId(Record);
 
@@ -834,6 +849,16 @@ void MicrosoftCXXNameMangler::mangleUnqu
   Name += ">";
 
   mangleSourceName(Name);
+
+  // If the context of a closure type is an initializer for a class
+  // member (static or nonstatic), it is encoded in a qualified name.
+  if (LambdaManglingNumber && LambdaContextDecl) {
+if ((isa(LambdaContextDecl) ||
+ isa(LambdaContextDecl)) &&
+LambdaContextDecl->getDeclContext()->isRecord()) {
+  mangleUnqualifiedName(cast(LambdaContextDecl));
+}
+  }
   break;
 }
   }
@@ -937,7 +962,6 @@ void MicrosoftCXXNameMangler::mangleNest
   // for how this should be done.
   Out << "__block_invoke" << Context.getBlockId(BD, false);
   Out << '@';
-  continue;
 } else if (const ObjCMethodDecl *Method = dyn_cast(DC)) {
   mangleObjCMethodName(Method);
 } else if (isa(DC)) {
@@ -945,8 +969,15 @@ void MicrosoftCXXNameMangler::mangleNest
   if (const 

Re: r288207 - Don't try to merge DLL attributes on redeclaration of invalid decl (PR31069)

2016-11-29 Thread David Majnemer via cfe-commits
On Tue, Nov 29, 2016 at 2:31 PM, Hans Wennborg via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: hans
> Date: Tue Nov 29 16:31:00 2016
> New Revision: 288207
>
> URL: http://llvm.org/viewvc/llvm-project?rev=288207=rev
> Log:
> Don't try to merge DLL attributes on redeclaration of invalid decl
> (PR31069)
>
> Modified:
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/Sema/dllimport.c
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaDecl.cpp?rev=288207=288206=288207=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 29 16:31:00 2016
> @@ -5651,6 +5651,9 @@ static void checkDLLAttributeRedeclarati
> NamedDecl *NewDecl,
> bool IsSpecialization,
> bool IsDefinition) {
> +  if(OldDecl->isInvalidDecl())
> +return;
> +
>

Formatting looks weird here.


>if (TemplateDecl *OldTD = dyn_cast(OldDecl)) {
>  OldDecl = OldTD->getTemplatedDecl();
>  if (!IsSpecialization)
>
> Modified: cfe/trunk/test/Sema/dllimport.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/
> dllimport.c?rev=288207=288206=288207=diff
> 
> ==
> --- cfe/trunk/test/Sema/dllimport.c (original)
> +++ cfe/trunk/test/Sema/dllimport.c Tue Nov 29 16:31:00 2016
> @@ -210,6 +210,10 @@ __declspec(dllimport) void redecl6();
>void redecl7();
>  __declspec(dllimport) inline void redecl7() {}
>
> +// PR31069: Don't crash trying to merge attributes for redeclaration of
> invalid decl.
> +void __declspec(dllimport) redecl8(unknowntype X); //
> expected-error{{unknown type name 'unknowntype'}}
> +void redecl8(unknowntype X) { } // expected-error{{unknown type name
> 'unknowntype'}}
> +
>  // External linkage is required.
>  __declspec(dllimport) static int staticFunc(); //
> expected-error{{'staticFunc' must have external linkage when declared
> 'dllimport'}}
>
>
>
> ___
> 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


[PATCH] D26846: __uuidof() and declspec(uuid("...")) should be allowed on enumeration types

2016-11-18 Thread David Majnemer via cfe-commits
majnemer added a comment.

Do we have a testcase where the declspec is applied to something inappropriate 
like an int?




Comment at: lib/Sema/SemaDeclAttr.cpp:4669-4673
+  if (!(isa(D) || isa(D))) {
 S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
-  << Attr.getName() << ExpectedClass;
+  << Attr.getName() << ExpectedEnumOrClass;
 return;
   }

I don't think you need this now that you've got this in Attr.td



Comment at: lib/Sema/SemaExprCXX.cpp:523
 
-  const auto *RD = Ty->getAsCXXRecordDecl();
+  const auto *RD = Ty->getAsTagDecl();
   if (!RD)

Please renamed `RD` to something more appropriate like `TD`.


Repository:
  rL LLVM

https://reviews.llvm.org/D26846



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


[PATCH] D22334: Fix for Bug 28172 : clang crashes on invalid code (with too few arguments to __builtin_signbit) without any proper diagnostics.

2016-11-17 Thread David Majnemer via cfe-commits
majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM with nits




Comment at: lib/Sema/SemaChecking.cpp:110
+S.Diag(ValArg->getLocStart(), diag::err_typecheck_cond_expect_float)
+  << ValArg->getType() << ValArg->getSourceRange();
+return true;

Can you change this `ValArg->getType()` to `Ty`?


https://reviews.llvm.org/D22334



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


[PATCH] D26657: [Sema] Respect DLL attributes more faithfully

2016-11-16 Thread David Majnemer via cfe-commits
majnemer added inline comments.



Comment at: lib/Sema/SemaTemplate.cpp:7683-7685
+// or implicit instantiation. MinGW doesn't allow this. In the implicit
+// instantiation case, we limit clang to only adding dllexport; see the
+// discussion in https://reviews.llvm.org/D26657 for details.

Please do not do this. The canonical location for comments in LLVM are the 
comments themselves.

We have moved the location of the review system and I can easily believe that 
it will move yet again.


https://reviews.llvm.org/D26657



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


r285612 - Add a warning flag for warn_alloca_align_alignof

2016-10-31 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Mon Oct 31 13:23:02 2016
New Revision: 285612

URL: http://llvm.org/viewvc/llvm-project?rev=285612=rev
Log:
Add a warning flag for warn_alloca_align_alignof

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=285612=285611=285612=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 31 13:23:02 
2016
@@ -2441,7 +2441,8 @@ def error_cannot_find_suitable_accessor
   "cannot find suitable %select{getter|setter}0 for property %1">;
 
 def warn_alloca_align_alignof : Warning<
-  "second argument to __builtin_alloca_with_align is supposed to be in bits">;
+  "second argument to __builtin_alloca_with_align is supposed to be in bits">,
+  InGroup>;
 
 def err_alignment_too_small : Error<
   "requested alignment must be %0 or greater">;


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


Re: r285544 - Add support for __builtin_alloca_with_align

2016-10-31 Thread David Majnemer via cfe-commits
Added in r285609.

On Mon, Oct 31, 2016 at 9:21 AM, Hal Finkel <hfin...@anl.gov> wrote:

> Hi David,
>
> On Reid's patch for this (D25581), Richard said, "This takes the alignment
> in bits? That's so ridiculously dumb that I would feel bad about accepting
> this patch unless it comes with a warning for people writing the
> obvious-but-wrong __builtin_alloca_with_align(sizeof(T), alignof(T))". We
> should add the warning.
>
> Thanks again,
> Hal
>
> ----- Original Message -
> > From: "David Majnemer via cfe-commits" <cfe-commits@lists.llvm.org>
> > To: cfe-commits@lists.llvm.org
> > Sent: Monday, October 31, 2016 12:37:49 AM
> > Subject: r285544 - Add support for __builtin_alloca_with_align
> >
> > Author: majnemer
> > Date: Mon Oct 31 00:37:48 2016
> > New Revision: 285544
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=285544=rev
> > Log:
> > Add support for __builtin_alloca_with_align
> >
> > __builtin_alloca always uses __BIGGEST_ALIGNMENT__ for the alignment
> > of
> > the allocation.  __builtin_alloca_with_align allows the programmer to
> > specify the alignment of the allocation.
> >
> > This fixes PR30658.
> >
> > Added:
> > cfe/trunk/test/Sema/builtin-alloca-with-align.c
> > Modified:
> > cfe/trunk/include/clang/Basic/Builtins.def
> > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> > cfe/trunk/include/clang/Sema/Sema.h
> > cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> > cfe/trunk/lib/Sema/SemaChecking.cpp
> > cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
> > cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
> > cfe/trunk/test/CodeGen/builtins-ms.c
> >
> > Modified: cfe/trunk/include/clang/Basic/Builtins.def
> > URL:
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/Builtins.def?rev=285544=285543=285544=diff
> > 
> ==
> > --- cfe/trunk/include/clang/Basic/Builtins.def (original)
> > +++ cfe/trunk/include/clang/Basic/Builtins.def Mon Oct 31 00:37:48
> > 2016
> > @@ -512,6 +512,7 @@ BUILTIN(__builtin_unreachable, "v", "nr"
> >  BUILTIN(__builtin_shufflevector, "v."   , "nc")
> >  BUILTIN(__builtin_convertvector, "v."   , "nct")
> >  BUILTIN(__builtin_alloca, "v*z"   , "Fn")
> > +BUILTIN(__builtin_alloca_with_align, "v*zIz", "Fn")
> >  BUILTIN(__builtin_call_with_static_chain, "v.", "nt")
> >
> >  // "Overloaded" Atomic operator builtins.  These are overloaded to
> >  support data
> >
> > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> > URL:
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
> DiagnosticSemaKinds.td?rev=285544=285543=285544=diff
> > 
> ==
> > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 31
> > 00:37:48 2016
> > @@ -2440,6 +2440,10 @@ def err_no_accessor_for_property : Error
> >  def error_cannot_find_suitable_accessor : Error<
> >"cannot find suitable %select{getter|setter}0 for property %1">;
> >
> > +def err_alignment_too_small : Error<
> > +  "requested alignment must be %0 or greater">;
> > +def err_alignment_too_big : Error<
> > +  "requested alignment must be %0 or smaller">;
> >  def err_alignment_not_power_of_two : Error<
> >"requested alignment is not a power of 2">;
> >  def err_alignment_dependent_typedef_name : Error<
> >
> > Modified: cfe/trunk/include/clang/Sema/Sema.h
> > URL:
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/Sema.h?rev=285544=285543=285544=diff
> > 
> ==
> > --- cfe/trunk/include/clang/Sema/Sema.h (original)
> > +++ cfe/trunk/include/clang/Sema/Sema.h Mon Oct 31 00:37:48 2016
> > @@ -9719,6 +9719,7 @@ public:
> >
> >  private:
> >bool SemaBuiltinPrefetch(CallExpr *TheCall);
> > +  bool SemaBuiltinAllocaWithAlign(CallExpr *TheCall);
> >bool SemaBuiltinAssume(CallExpr *TheCall);
> >bool SemaBuiltinAssumeAligned(CallExpr *TheCall);
> >bool SemaBuiltinLongjmp(CallExpr *TheCall);
> >
> > Modi

r285609 - [Sema] Warn when alignof is used with __builtin_alloca_with_align

2016-10-31 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Mon Oct 31 13:07:57 2016
New Revision: 285609

URL: http://llvm.org/viewvc/llvm-project?rev=285609=rev
Log:
[Sema] Warn when alignof is used with __builtin_alloca_with_align

The second argument to __builtin_alloca_with_align is supposed to be in
bits, not bytes.  Using alignof there would be indicative of a bug.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/builtin-alloca-with-align.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=285609=285608=285609=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 31 13:07:57 
2016
@@ -2440,6 +2440,9 @@ def err_no_accessor_for_property : Error
 def error_cannot_find_suitable_accessor : Error<
   "cannot find suitable %select{getter|setter}0 for property %1">;
 
+def warn_alloca_align_alignof : Warning<
+  "second argument to __builtin_alloca_with_align is supposed to be in bits">;
+
 def err_alignment_too_small : Error<
   "requested alignment must be %0 or greater">;
 def err_alignment_too_big : Error<

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=285609=285608=285609=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Oct 31 13:07:57 2016
@@ -3907,7 +3907,7 @@ bool Sema::SemaBuiltinAssume(CallExpr *T
   return false;
 }
 
-/// Handle __builtin_assume_aligned. This is declared
+/// Handle __builtin_alloca_with_align. This is declared
 /// as (size_t, size_t) where the second size_t must be a power of 2 greater
 /// than 8.
 bool Sema::SemaBuiltinAllocaWithAlign(CallExpr *TheCall) {
@@ -3916,6 +3916,12 @@ bool Sema::SemaBuiltinAllocaWithAlign(Ca
 
   // We can't check the value of a dependent argument.
   if (!Arg->isTypeDependent() && !Arg->isValueDependent()) {
+if (const auto *UE =
+dyn_cast(Arg->IgnoreParenImpCasts()))
+  if (UE->getKind() == UETT_AlignOf)
+Diag(TheCall->getLocStart(), diag::warn_alloca_align_alignof)
+  << Arg->getSourceRange();
+
 llvm::APSInt Result = Arg->EvaluateKnownConstInt(Context);
 
 if (!Result.isPowerOf2())

Modified: cfe/trunk/test/Sema/builtin-alloca-with-align.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtin-alloca-with-align.c?rev=285609=285608=285609=diff
==
--- cfe/trunk/test/Sema/builtin-alloca-with-align.c (original)
+++ cfe/trunk/test/Sema/builtin-alloca-with-align.c Mon Oct 31 13:07:57 2016
@@ -27,3 +27,7 @@ void test6(int a, int j) {
 void test7(int a) {
   __builtin_alloca_with_align(a, 2); // expected-error {{requested alignment 
must be 8 or greater}}
 }
+
+void test8() {
+  __builtin_alloca_with_align(sizeof(__INT64_TYPE__), 
__alignof__(__INT64_TYPE__)); // expected-warning {{second argument to 
__builtin_alloca_with_align is supposed to be in bits}}
+}


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


r285595 - Use toCharUnitsFromBits instead of TargetInfo::getCharWidth

2016-10-31 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Mon Oct 31 11:48:30 2016
New Revision: 285595

URL: http://llvm.org/viewvc/llvm-project?rev=285595=rev
Log:
Use toCharUnitsFromBits instead of TargetInfo::getCharWidth

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=285595=285594=285595=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Oct 31 11:48:30 2016
@@ -1142,7 +1142,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 const TargetInfo  = getContext().getTargetInfo();
 // The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
 unsigned SuitableAlignmentInBytes =
-TI.getSuitableAlign() / TI.getCharWidth();
+CGM.getContext()
+.toCharUnitsFromBits(TI.getSuitableAlign())
+.getQuantity();
 AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
 AI->setAlignment(SuitableAlignmentInBytes);
 return RValue::get(AI);
@@ -1150,11 +1152,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 
   case Builtin::BI__builtin_alloca_with_align: {
 Value *Size = EmitScalarExpr(E->getArg(0));
-Value *AlignmentValue = EmitScalarExpr(E->getArg(1));
-auto *AlignmentCI = cast(AlignmentValue);
-unsigned Alignment = AlignmentCI->getZExtValue();
-const TargetInfo  = getContext().getTargetInfo();
-unsigned AlignmentInBytes = Alignment / TI.getCharWidth();
+Value *AlignmentInBitsValue = EmitScalarExpr(E->getArg(1));
+auto *AlignmentInBitsCI = cast(AlignmentInBitsValue);
+unsigned AlignmentInBits = AlignmentInBitsCI->getZExtValue();
+unsigned AlignmentInBytes =
+CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getQuantity();
 AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
 AI->setAlignment(AlignmentInBytes);
 return RValue::get(AI);


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


r285544 - Add support for __builtin_alloca_with_align

2016-10-30 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Mon Oct 31 00:37:48 2016
New Revision: 285544

URL: http://llvm.org/viewvc/llvm-project?rev=285544=rev
Log:
Add support for __builtin_alloca_with_align

__builtin_alloca always uses __BIGGEST_ALIGNMENT__ for the alignment of
the allocation.  __builtin_alloca_with_align allows the programmer to
specify the alignment of the allocation.

This fixes PR30658.

Added:
cfe/trunk/test/Sema/builtin-alloca-with-align.c
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
cfe/trunk/test/CodeGen/builtins-ms.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=285544=285543=285544=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Mon Oct 31 00:37:48 2016
@@ -512,6 +512,7 @@ BUILTIN(__builtin_unreachable, "v", "nr"
 BUILTIN(__builtin_shufflevector, "v."   , "nc")
 BUILTIN(__builtin_convertvector, "v."   , "nct")
 BUILTIN(__builtin_alloca, "v*z"   , "Fn")
+BUILTIN(__builtin_alloca_with_align, "v*zIz", "Fn")
 BUILTIN(__builtin_call_with_static_chain, "v.", "nt")
 
 // "Overloaded" Atomic operator builtins.  These are overloaded to support data

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=285544=285543=285544=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 31 00:37:48 
2016
@@ -2440,6 +2440,10 @@ def err_no_accessor_for_property : Error
 def error_cannot_find_suitable_accessor : Error<
   "cannot find suitable %select{getter|setter}0 for property %1">;
 
+def err_alignment_too_small : Error<
+  "requested alignment must be %0 or greater">;
+def err_alignment_too_big : Error<
+  "requested alignment must be %0 or smaller">;
 def err_alignment_not_power_of_two : Error<
   "requested alignment is not a power of 2">;
 def err_alignment_dependent_typedef_name : Error<

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=285544=285543=285544=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Oct 31 00:37:48 2016
@@ -9719,6 +9719,7 @@ public:
 
 private:
   bool SemaBuiltinPrefetch(CallExpr *TheCall);
+  bool SemaBuiltinAllocaWithAlign(CallExpr *TheCall);
   bool SemaBuiltinAssume(CallExpr *TheCall);
   bool SemaBuiltinAssumeAligned(CallExpr *TheCall);
   bool SemaBuiltinLongjmp(CallExpr *TheCall);

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=285544=285543=285544=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Oct 31 00:37:48 2016
@@ -1147,6 +1147,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 AI->setAlignment(SuitableAlignmentInBytes);
 return RValue::get(AI);
   }
+
+  case Builtin::BI__builtin_alloca_with_align: {
+Value *Size = EmitScalarExpr(E->getArg(0));
+Value *AlignmentValue = EmitScalarExpr(E->getArg(1));
+auto *AlignmentCI = cast(AlignmentValue);
+unsigned Alignment = AlignmentCI->getZExtValue();
+const TargetInfo  = getContext().getTargetInfo();
+unsigned AlignmentInBytes = Alignment / TI.getCharWidth();
+AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
+AI->setAlignment(AlignmentInBytes);
+return RValue::get(AI);
+  }
+
   case Builtin::BIbzero:
   case Builtin::BI__builtin_bzero: {
 Address Dest = EmitPointerWithAlignment(E->getArg(0));

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=285544=285543=285544=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Oct 31 00:37:48 2016
@@ -791,6 +791,10 @@ Sema::CheckBuiltinFunctionCall(FunctionD
 if (SemaBuiltinPrefetch(TheCall))
   return ExprError();
 break;
+  case Builtin::BI__builtin_alloca_with_align:
+if (SemaBuiltinAllocaWithAlign(TheCall))
+  return ExprError();
+break;
   case Builtin::BI__assume:
   case 

[PATCH] D13330: Implement __attribute__((unique_instantiation))

2016-10-27 Thread David Majnemer via cfe-commits
majnemer added a comment.

I think this looks good but I'd like @rsmith to take a look.


https://reviews.llvm.org/D13330



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-27 Thread David Majnemer via cfe-commits
majnemer added a comment.

The __ namespace is reserved for us and I can't imagine how __regcall would 
upset any existing code out there.


https://reviews.llvm.org/D25204



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


[PATCH] D24378: [CodeGen] Provide an appropriate alignment for dynamic allocas

2016-10-27 Thread David Majnemer via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285316: [CodeGen] Provide an appropriate alignment for 
dynamic allocas (authored by majnemer).

Changed prior to commit:
  https://reviews.llvm.org/D24378?vs=70789=76060#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24378

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/builtins-ms.c


Index: cfe/trunk/test/CodeGen/builtins-ms.c
===
--- cfe/trunk/test/CodeGen/builtins-ms.c
+++ cfe/trunk/test/CodeGen/builtins-ms.c
@@ -4,6 +4,6 @@
 void capture(void *);
 void test_alloca(int n) {
   capture(_alloca(n));
-  // CHECK: %[[arg:.*]] = alloca i8, i32 %
+  // CHECK: %[[arg:.*]] = alloca i8, i32 %{{.*}}, align 16
   // CHECK: call void @capture(i8* %[[arg]])
 }
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -1139,7 +1139,13 @@
   case Builtin::BI_alloca:
   case Builtin::BI__builtin_alloca: {
 Value *Size = EmitScalarExpr(E->getArg(0));
-return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size));
+const TargetInfo  = getContext().getTargetInfo();
+// The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
+unsigned SuitableAlignmentInBytes =
+TI.getSuitableAlign() / TI.getCharWidth();
+AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
+AI->setAlignment(SuitableAlignmentInBytes);
+return RValue::get(AI);
   }
   case Builtin::BIbzero:
   case Builtin::BI__builtin_bzero: {


Index: cfe/trunk/test/CodeGen/builtins-ms.c
===
--- cfe/trunk/test/CodeGen/builtins-ms.c
+++ cfe/trunk/test/CodeGen/builtins-ms.c
@@ -4,6 +4,6 @@
 void capture(void *);
 void test_alloca(int n) {
   capture(_alloca(n));
-  // CHECK: %[[arg:.*]] = alloca i8, i32 %
+  // CHECK: %[[arg:.*]] = alloca i8, i32 %{{.*}}, align 16
   // CHECK: call void @capture(i8* %[[arg]])
 }
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -1139,7 +1139,13 @@
   case Builtin::BI_alloca:
   case Builtin::BI__builtin_alloca: {
 Value *Size = EmitScalarExpr(E->getArg(0));
-return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size));
+const TargetInfo  = getContext().getTargetInfo();
+// The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
+unsigned SuitableAlignmentInBytes =
+TI.getSuitableAlign() / TI.getCharWidth();
+AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
+AI->setAlignment(SuitableAlignmentInBytes);
+return RValue::get(AI);
   }
   case Builtin::BIbzero:
   case Builtin::BI__builtin_bzero: {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r285316 - [CodeGen] Provide an appropriate alignment for dynamic allocas

2016-10-27 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Thu Oct 27 12:18:24 2016
New Revision: 285316

URL: http://llvm.org/viewvc/llvm-project?rev=285316=rev
Log:
[CodeGen] Provide an appropriate alignment for dynamic allocas

GCC documents __builtin_alloca as aligning the storage to at least
__BIGGEST_ALIGNMENT__.

MSVC documents essentially the same for the x64 ABI:
https://msdn.microsoft.com/en-us/library/x9sx5da1.aspx

The 32-bit ABI follows the same rule: it emits a call to _alloca_probe_16

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

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins-ms.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=285316=285315=285316=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Oct 27 12:18:24 2016
@@ -1139,7 +1139,13 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   case Builtin::BI_alloca:
   case Builtin::BI__builtin_alloca: {
 Value *Size = EmitScalarExpr(E->getArg(0));
-return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size));
+const TargetInfo  = getContext().getTargetInfo();
+// The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
+unsigned SuitableAlignmentInBytes =
+TI.getSuitableAlign() / TI.getCharWidth();
+AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
+AI->setAlignment(SuitableAlignmentInBytes);
+return RValue::get(AI);
   }
   case Builtin::BIbzero:
   case Builtin::BI__builtin_bzero: {

Modified: cfe/trunk/test/CodeGen/builtins-ms.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ms.c?rev=285316=285315=285316=diff
==
--- cfe/trunk/test/CodeGen/builtins-ms.c (original)
+++ cfe/trunk/test/CodeGen/builtins-ms.c Thu Oct 27 12:18:24 2016
@@ -4,6 +4,6 @@
 void capture(void *);
 void test_alloca(int n) {
   capture(_alloca(n));
-  // CHECK: %[[arg:.*]] = alloca i8, i32 %
+  // CHECK: %[[arg:.*]] = alloca i8, i32 %{{.*}}, align 16
   // CHECK: call void @capture(i8* %[[arg]])
 }


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


[PATCH] D25895: [MS ABI] Reuse getVFPtrOffsets instead of using getClassAtVTableLocation

2016-10-27 Thread David Majnemer via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285315: [MS ABI] Reuse getVFPtrOffsets instead of using 
getClassAtVTableLocation (authored by majnemer).

Changed prior to commit:
  https://reviews.llvm.org/D25895?vs=75523=76059#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25895

Files:
  cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp


Index: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1762,42 +1762,6 @@
   return VTable;
 }
 
-// Compute the identity of the most derived class whose virtual table is 
located
-// at the given offset into RD.
-static const CXXRecordDecl *getClassAtVTableLocation(ASTContext ,
- const CXXRecordDecl *RD,
- CharUnits Offset) {
-  if (Offset.isZero())
-return RD;
-
-  const ASTRecordLayout  = Ctx.getASTRecordLayout(RD);
-  const CXXRecordDecl *MaxBase = nullptr;
-  CharUnits MaxBaseOffset;
-  for (auto & : RD->bases()) {
-const CXXRecordDecl *Base = B.getType()->getAsCXXRecordDecl();
-CharUnits BaseOffset = B.isVirtual() ? Layout.getVBaseClassOffset(Base)
- : Layout.getBaseClassOffset(Base);
-if (BaseOffset <= Offset && BaseOffset >= MaxBaseOffset) {
-  MaxBase = Base;
-  MaxBaseOffset = BaseOffset;
-}
-  }
-  assert(MaxBase);
-  return getClassAtVTableLocation(Ctx, MaxBase, Offset - MaxBaseOffset);
-}
-
-// Compute the identity of the most derived class whose virtual table is 
located
-// at the MethodVFTableLocation ML.
-static const CXXRecordDecl *
-getClassAtVTableLocation(ASTContext , GlobalDecl GD,
- MicrosoftVTableContext::MethodVFTableLocation ) {
-  const CXXRecordDecl *RD = ML.VBase;
-  if (!RD)
-RD = cast(GD.getDecl())->getParent();
-
-  return getClassAtVTableLocation(Ctx, RD, ML.VFPtrOffset);
-}
-
 CGCallee MicrosoftCXXABI::getVirtualFunctionPointer(CodeGenFunction ,
 GlobalDecl GD,
 Address This,
@@ -1813,18 +1777,30 @@
   auto *MethodDecl = cast(GD.getDecl());
   llvm::Value *VTable = CGF.GetVTablePtr(VPtr, Ty, MethodDecl->getParent());
 
+  MicrosoftVTableContext  = CGM.getMicrosoftVTableContext();
   MicrosoftVTableContext::MethodVFTableLocation ML =
-  CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
+  VFTContext.getMethodVFTableLocation(GD);
+
+  // Compute the identity of the most derived class whose virtual table is
+  // located at the MethodVFTableLocation ML.
+  auto getObjectWithVPtr = [&] {
+return llvm::find_if(VFTContext.getVFPtrOffsets(
+ ML.VBase ? ML.VBase : MethodDecl->getParent()),
+ [&](const std::unique_ptr ) {
+   return Info->FullOffsetInMDC == ML.VFPtrOffset;
+ })
+->get()
+->ObjectWithVPtr;
+  };
 
   llvm::Value *VFunc;
   if (CGF.ShouldEmitVTableTypeCheckedLoad(MethodDecl->getParent())) {
 VFunc = CGF.EmitVTableTypeCheckedLoad(
-getClassAtVTableLocation(getContext(), GD, ML), VTable,
+getObjectWithVPtr(), VTable,
 ML.Index * CGM.getContext().getTargetInfo().getPointerWidth(0) / 8);
   } else {
 if (CGM.getCodeGenOpts().PrepareForLTO)
-  CGF.EmitTypeMetadataCodeForVCall(
-  getClassAtVTableLocation(getContext(), GD, ML), VTable, Loc);
+  CGF.EmitTypeMetadataCodeForVCall(getObjectWithVPtr(), VTable, Loc);
 
 llvm::Value *VFuncPtr =
 Builder.CreateConstInBoundsGEP1_64(VTable, ML.Index, "vfn");


Index: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1762,42 +1762,6 @@
   return VTable;
 }
 
-// Compute the identity of the most derived class whose virtual table is located
-// at the given offset into RD.
-static const CXXRecordDecl *getClassAtVTableLocation(ASTContext ,
- const CXXRecordDecl *RD,
- CharUnits Offset) {
-  if (Offset.isZero())
-return RD;
-
-  const ASTRecordLayout  = Ctx.getASTRecordLayout(RD);
-  const CXXRecordDecl *MaxBase = nullptr;
-  CharUnits MaxBaseOffset;
-  for (auto & : RD->bases()) {
-const CXXRecordDecl *Base = B.getType()->getAsCXXRecordDecl();
-CharUnits BaseOffset = B.isVirtual() ? Layout.getVBaseClassOffset(Base)
- : Layout.getBaseClassOffset(Base);
-if (BaseOffset <= Offset && BaseOffset >= MaxBaseOffset) {
-  MaxBase = Base;
-  MaxBaseOffset = BaseOffset;
-}
-  }
-  

r285315 - [MS ABI] Reuse getVFPtrOffsets instead of using getClassAtVTableLocation

2016-10-27 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Thu Oct 27 12:11:51 2016
New Revision: 285315

URL: http://llvm.org/viewvc/llvm-project?rev=285315=rev
Log:
[MS ABI] Reuse getVFPtrOffsets instead of using getClassAtVTableLocation

getClassAtVTableLocation hunts through virtual bases without using the
MDC layout which is indicative of a bug.

Instead, reuse the getVFPtrOffsets machinery to calculate which
subobject within the MDC is responsible for the vfptr.

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

Modified:
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=285315=285314=285315=diff
==
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Thu Oct 27 12:11:51 2016
@@ -1762,42 +1762,6 @@ llvm::GlobalVariable *MicrosoftCXXABI::g
   return VTable;
 }
 
-// Compute the identity of the most derived class whose virtual table is 
located
-// at the given offset into RD.
-static const CXXRecordDecl *getClassAtVTableLocation(ASTContext ,
- const CXXRecordDecl *RD,
- CharUnits Offset) {
-  if (Offset.isZero())
-return RD;
-
-  const ASTRecordLayout  = Ctx.getASTRecordLayout(RD);
-  const CXXRecordDecl *MaxBase = nullptr;
-  CharUnits MaxBaseOffset;
-  for (auto & : RD->bases()) {
-const CXXRecordDecl *Base = B.getType()->getAsCXXRecordDecl();
-CharUnits BaseOffset = B.isVirtual() ? Layout.getVBaseClassOffset(Base)
- : Layout.getBaseClassOffset(Base);
-if (BaseOffset <= Offset && BaseOffset >= MaxBaseOffset) {
-  MaxBase = Base;
-  MaxBaseOffset = BaseOffset;
-}
-  }
-  assert(MaxBase);
-  return getClassAtVTableLocation(Ctx, MaxBase, Offset - MaxBaseOffset);
-}
-
-// Compute the identity of the most derived class whose virtual table is 
located
-// at the MethodVFTableLocation ML.
-static const CXXRecordDecl *
-getClassAtVTableLocation(ASTContext , GlobalDecl GD,
- MicrosoftVTableContext::MethodVFTableLocation ) {
-  const CXXRecordDecl *RD = ML.VBase;
-  if (!RD)
-RD = cast(GD.getDecl())->getParent();
-
-  return getClassAtVTableLocation(Ctx, RD, ML.VFPtrOffset);
-}
-
 CGCallee MicrosoftCXXABI::getVirtualFunctionPointer(CodeGenFunction ,
 GlobalDecl GD,
 Address This,
@@ -1813,18 +1777,30 @@ CGCallee MicrosoftCXXABI::getVirtualFunc
   auto *MethodDecl = cast(GD.getDecl());
   llvm::Value *VTable = CGF.GetVTablePtr(VPtr, Ty, MethodDecl->getParent());
 
+  MicrosoftVTableContext  = CGM.getMicrosoftVTableContext();
   MicrosoftVTableContext::MethodVFTableLocation ML =
-  CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
+  VFTContext.getMethodVFTableLocation(GD);
+
+  // Compute the identity of the most derived class whose virtual table is
+  // located at the MethodVFTableLocation ML.
+  auto getObjectWithVPtr = [&] {
+return llvm::find_if(VFTContext.getVFPtrOffsets(
+ ML.VBase ? ML.VBase : MethodDecl->getParent()),
+ [&](const std::unique_ptr ) {
+   return Info->FullOffsetInMDC == ML.VFPtrOffset;
+ })
+->get()
+->ObjectWithVPtr;
+  };
 
   llvm::Value *VFunc;
   if (CGF.ShouldEmitVTableTypeCheckedLoad(MethodDecl->getParent())) {
 VFunc = CGF.EmitVTableTypeCheckedLoad(
-getClassAtVTableLocation(getContext(), GD, ML), VTable,
+getObjectWithVPtr(), VTable,
 ML.Index * CGM.getContext().getTargetInfo().getPointerWidth(0) / 8);
   } else {
 if (CGM.getCodeGenOpts().PrepareForLTO)
-  CGF.EmitTypeMetadataCodeForVCall(
-  getClassAtVTableLocation(getContext(), GD, ML), VTable, Loc);
+  CGF.EmitTypeMetadataCodeForVCall(getObjectWithVPtr(), VTable, Loc);
 
 llvm::Value *VFuncPtr =
 Builder.CreateConstInBoundsGEP1_64(VTable, ML.Index, "vfn");


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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread David Majnemer via cfe-commits
majnemer added inline comments.



Comment at: lib/AST/MicrosoftMangle.cpp:433
   Out << Prefix;
+
   mangleName(D);

Please remove this stray newline.



Comment at: lib/CodeGen/TargetInfo.cpp:
+  if (classifyArgumentType(FD->getType(),
+   std::numeric_limits::max(),
+   LocalNeededInt, LocalNeededSSE, true)

I think UINT_MAX is more popular than using `std::numeric_limits` for this 
purpose in LLVM/Clang.



Comment at: lib/CodeGen/TargetInfo.cpp:3337-3338
+NeededInt = NeededSSE = 0;
+return getIndirectReturnResult(Ty);
+  } else {
+NeededInt += LocalNeededInt;

Please avoid else after return: 
http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return


https://reviews.llvm.org/D25204



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


[PATCH] D25888: Add support for __builtin_os_log_format[_buffer_size]

2016-10-22 Thread David Majnemer via cfe-commits
majnemer added inline comments.



Comment at: clang/include/clang/Analysis/Analyses/OSLog.h:117-129
+return std::any_of(
+Items.begin(), Items.end(),
+[](const OSLogBufferItem ) { return item.getIsPrivate(); });
+  }
+
+  bool getHasPublicItems() const {
+return std::any_of(

`llvm::any_of`



Comment at: clang/include/clang/Analysis/Analyses/OSLog.h:137-140
+if (getHasPrivateItems())
+  result |= 0x01;
+if (getHasNonScalar())
+  result |= 0x02;

Magic numbers.


https://reviews.llvm.org/D25888



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


[PATCH] D25888: Add support for __builtin_os_log_format[_buffer_size]

2016-10-21 Thread David Majnemer via cfe-commits
majnemer added a comment.

You could use `llvm::any_of` instead of `std::any_of`.




Comment at: clang/include/clang/Analysis/Analyses/OSLog.h:84-86
+  result |= 0x01;
+if (getIsPublic())
+  result |= 0x02;

IsPublic/IsPrivate instead of magic numbers?



Comment at: clang/lib/Sema/SemaChecking.cpp:3493
+  Arg = Arg->IgnoreParenCasts();
+  StringLiteral *Literal = dyn_cast(Arg);
+  if (!Literal) {

`auto *`


https://reviews.llvm.org/D25888



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


[PATCH] D25895: [MS ABI] Reuse getVFPtrOffsets instead of using getClassAtVTableLocation

2016-10-21 Thread David Majnemer via cfe-commits
majnemer created this revision.
majnemer added reviewers: rnk, pcc.
majnemer added a subscriber: cfe-commits.

getClassAtVTableLocation hunts through virtual bases without using the
MDC layout which is indicative of a bug.

Instead, reuse the getVFPtrOffsets machinery to calculate which
subobject within the MDC is responsible for the vfptr.


https://reviews.llvm.org/D25895

Files:
  lib/CodeGen/MicrosoftCXXABI.cpp


Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1760,42 +1760,6 @@
   return VTable;
 }
 
-// Compute the identity of the most derived class whose virtual table is 
located
-// at the given offset into RD.
-static const CXXRecordDecl *getClassAtVTableLocation(ASTContext ,
- const CXXRecordDecl *RD,
- CharUnits Offset) {
-  if (Offset.isZero())
-return RD;
-
-  const ASTRecordLayout  = Ctx.getASTRecordLayout(RD);
-  const CXXRecordDecl *MaxBase = nullptr;
-  CharUnits MaxBaseOffset;
-  for (auto & : RD->bases()) {
-const CXXRecordDecl *Base = B.getType()->getAsCXXRecordDecl();
-CharUnits BaseOffset = B.isVirtual() ? Layout.getVBaseClassOffset(Base)
- : Layout.getBaseClassOffset(Base);
-if (BaseOffset <= Offset && BaseOffset >= MaxBaseOffset) {
-  MaxBase = Base;
-  MaxBaseOffset = BaseOffset;
-}
-  }
-  assert(MaxBase);
-  return getClassAtVTableLocation(Ctx, MaxBase, Offset - MaxBaseOffset);
-}
-
-// Compute the identity of the most derived class whose virtual table is 
located
-// at the MethodVFTableLocation ML.
-static const CXXRecordDecl *
-getClassAtVTableLocation(ASTContext , GlobalDecl GD,
- MicrosoftVTableContext::MethodVFTableLocation ) {
-  const CXXRecordDecl *RD = ML.VBase;
-  if (!RD)
-RD = cast(GD.getDecl())->getParent();
-
-  return getClassAtVTableLocation(Ctx, RD, ML.VFPtrOffset);
-}
-
 llvm::Value *MicrosoftCXXABI::getVirtualFunctionPointer(CodeGenFunction ,
 GlobalDecl GD,
 Address This,
@@ -1811,17 +1775,29 @@
   auto *MethodDecl = cast(GD.getDecl());
   llvm::Value *VTable = CGF.GetVTablePtr(VPtr, Ty, MethodDecl->getParent());
 
+  MicrosoftVTableContext  = CGM.getMicrosoftVTableContext();
   MicrosoftVTableContext::MethodVFTableLocation ML =
-  CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
+  VFTContext.getMethodVFTableLocation(GD);
+
+  // Compute the identity of the most derived class whose virtual table is
+  // located at the MethodVFTableLocation ML.
+  auto getObjectWithVPtr = [&] {
+return llvm::find_if(VFTContext.getVFPtrOffsets(
+ ML.VBase ? ML.VBase : MethodDecl->getParent()),
+ [&](const std::unique_ptr ) {
+   return Info->FullOffsetInMDC == ML.VFPtrOffset;
+ })
+->get()
+->ObjectWithVPtr;
+  };
 
   if (CGF.ShouldEmitVTableTypeCheckedLoad(MethodDecl->getParent())) {
 return CGF.EmitVTableTypeCheckedLoad(
-getClassAtVTableLocation(getContext(), GD, ML), VTable,
+getObjectWithVPtr(), VTable,
 ML.Index * CGM.getContext().getTargetInfo().getPointerWidth(0) / 8);
   } else {
 if (CGM.getCodeGenOpts().PrepareForLTO)
-  CGF.EmitTypeMetadataCodeForVCall(
-  getClassAtVTableLocation(getContext(), GD, ML), VTable, Loc);
+  CGF.EmitTypeMetadataCodeForVCall(getObjectWithVPtr(), VTable, Loc);
 
 llvm::Value *VFuncPtr =
 Builder.CreateConstInBoundsGEP1_64(VTable, ML.Index, "vfn");


Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1760,42 +1760,6 @@
   return VTable;
 }
 
-// Compute the identity of the most derived class whose virtual table is located
-// at the given offset into RD.
-static const CXXRecordDecl *getClassAtVTableLocation(ASTContext ,
- const CXXRecordDecl *RD,
- CharUnits Offset) {
-  if (Offset.isZero())
-return RD;
-
-  const ASTRecordLayout  = Ctx.getASTRecordLayout(RD);
-  const CXXRecordDecl *MaxBase = nullptr;
-  CharUnits MaxBaseOffset;
-  for (auto & : RD->bases()) {
-const CXXRecordDecl *Base = B.getType()->getAsCXXRecordDecl();
-CharUnits BaseOffset = B.isVirtual() ? Layout.getVBaseClassOffset(Base)
- : Layout.getBaseClassOffset(Base);
-if (BaseOffset <= Offset && BaseOffset >= MaxBaseOffset) {
-  MaxBase = Base;
-  MaxBaseOffset = BaseOffset;
-}
-  }
-  assert(MaxBase);
-  return 

Re: r284624 - MS ABI: Fix assert when generating virtual function call with virtual bases and -flto (PR30731)

2016-10-19 Thread David Majnemer via cfe-commits
On Wed, Oct 19, 2016 at 2:04 PM, Hans Wennborg via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: hans
> Date: Wed Oct 19 13:04:27 2016
> New Revision: 284624
>
> URL: http://llvm.org/viewvc/llvm-project?rev=284624=rev
> Log:
> MS ABI: Fix assert when generating virtual function call with virtual
> bases and -flto (PR30731)
>
> getClassAtVTableLocation() was calling
> ASTRecordLayout::getBaseClassOffset() on a virtual base, causing an
> assert.
>
> Differential Revision: https://reviews.llvm.org/D25779
>
> Added:
> cfe/trunk/test/CodeGenCXX/pr30731.cpp
> Modified:
> cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
>
> Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mi
> crosoftCXXABI.cpp?rev=284624=284623=284624=diff
> 
> ==
> --- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
> +++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Wed Oct 19 13:04:27 2016
> @@ -1773,15 +1773,8 @@ static const CXXRecordDecl *getClassAtVT
>CharUnits MaxBaseOffset;
>for (auto & : RD->bases()) {
>  const CXXRecordDecl *Base = B.getType()->getAsCXXRecordDecl();
> -CharUnits BaseOffset = Layout.getBaseClassOffset(Base);
> -if (BaseOffset <= Offset && BaseOffset >= MaxBaseOffset) {
> -  MaxBase = Base;
> -  MaxBaseOffset = BaseOffset;
> -}
> -  }
> -  for (auto & : RD->vbases()) {
> -const CXXRecordDecl *Base = B.getType()->getAsCXXRecordDecl();
> -CharUnits BaseOffset = Layout.getVBaseClassOffset(Base);
> +CharUnits BaseOffset = B.isVirtual() ? Layout.getVBaseClassOffset(Bas
> e)
> + : Layout.getBaseClassOffset(Base
> );
>  if (BaseOffset <= Offset && BaseOffset >= MaxBaseOffset) {
>MaxBase = Base;
>MaxBaseOffset = BaseOffset;
>

I don't think this code is correct.
It uses a base's layout to find virtual base offsets, that seems wrong
because the virtual base offsets can be different in a base and the most
derived class.
I think we need to do getVBaseOffset with the MDC's layout similar to how
VTableBuilder.cpp's findPathsToSubobject operates.


>
> Added: cfe/trunk/test/CodeGenCXX/pr30731.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCX
> X/pr30731.cpp?rev=284624=auto
> 
> ==
> --- cfe/trunk/test/CodeGenCXX/pr30731.cpp (added)
> +++ cfe/trunk/test/CodeGenCXX/pr30731.cpp Wed Oct 19 13:04:27 2016
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -triple i386-pc-win32 -emit-llvm -flto -std=c++11 -o -
> %s | FileCheck %s
> +
> +struct A {
> +  virtual ~A();
> +};
> +
> +struct B {};
> +
> +struct C {
> +  virtual void f();
> +};
> +
> +struct S : A, virtual B, C {
> +  void f() override;
> +};
> +
> +void f(S* s) { s->f(); }
> +
> +// CHECK-LABEL: define void @"\01?f@@YAXPAUS@@@Z"
> +// CHECK: call
> +// CHECK: ret void
>
>
> ___
> 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


[PATCH] D25779: MS ABI: Don't assert when generating virtual function call with virtual bases and -flto (PR30731)

2016-10-19 Thread David Majnemer via cfe-commits
majnemer added a comment.

Why did this only fail with -flto? Seems strange.


Repository:
  rL LLVM

https://reviews.llvm.org/D25779



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


[PATCH] D25334: Implement __stosb intrinsic as a volatile memset

2016-10-14 Thread David Majnemer via cfe-commits
majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D25334



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


[PATCH] D25579: [codeview] emit debug info for indirect virtual base classes

2016-10-13 Thread David Majnemer via cfe-commits
majnemer added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:1392
+auto *BaseTy = getOrCreateType(BI.getType(), Unit);
+if (SeenTypes.find(BaseTy) != SeenTypes.end())
+  continue;

ruiu wrote:
> zturner wrote:
> > rnk wrote:
> > > IMO `SeenTypes.count(...)` would be more idiomatic.
> > What a silly function.  I wonder why it isn't called `contains()` and 
> > return a `bool`.
> It's probably because std::set doesn't provide `contains()` but `count()` too.
You can use `is_contained` from STLExtras.h, it should be maximally idiomatic :)


https://reviews.llvm.org/D25579



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


[PATCH] D25334: Implement __stosb intrinsic as a volatile memset

2016-10-13 Thread David Majnemer via cfe-commits
majnemer added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:
+Address Dest = EmitPointerWithAlignment(E->getArg(0));
+return Builder.CreateMemSet(Dest, Ops[1], Ops[2], true);
   }

I think we should manually force the alignment to 1 instead of trying to be 
clever.


https://reviews.llvm.org/D25334



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


[PATCH] D25540: Implement MS _ReturnAddress and _AddressOfReturnAddress intrinsics

2016-10-13 Thread David Majnemer via cfe-commits
majnemer added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:1151-1152
+  case Builtin::BI_ReturnAddress: {
+Value *Depth =
+Constant::getNullValue(ConvertType(getContext().UnsignedIntTy));
+Value *F = CGM.getIntrinsic(Intrinsic::returnaddress);

I'd just use `Builder.getInt32(0)`, this will DTRT regardless of whatever 
UnsignedIntTy is.


https://reviews.llvm.org/D25540



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


[PATCH] D25264: Implement MS _BitScan intrinsics

2016-10-12 Thread David Majnemer via cfe-commits
majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

This looks right to me.


https://reviews.llvm.org/D25264



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


[PATCH] D22955: [MSVC] Improved late parsing of template functions.

2016-10-12 Thread David Majnemer via cfe-commits
majnemer added inline comments.



Comment at: lib/Sema/SemaLookup.cpp:1044-1070
+static bool isBaseClass(const CXXRecordDecl *Record, CXXRecordDecl *Base) {
+  SmallVector Queue;
+
+  while (true) {
+for (const auto  : Record->bases()) {
+  const RecordType *Ty = I.getType()->getAs();
+  if (!Ty)

This looks a lot like forallBases, any chance it could be reused?


https://reviews.llvm.org/D22955



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


[PATCH] D24669: {Sema] Gcc compatibility of vector shift.

2016-10-10 Thread David Majnemer via cfe-commits
majnemer added inline comments.



Comment at: llvm/tools/clang/lib/Sema/SemaExpr.cpp:8795-8798
+if (S.Diags.getDiagnosticLevel(
+diag::warn_typecheck_vector_element_sizes_not_equal, Loc) ==
+DiagnosticsEngine::Level::Error)
+  return QualType();

Why `return QualType()` here? Would returning `LHSType` provide confusing or 
incorrect diagnostics?


https://reviews.llvm.org/D24669



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


[PATCH] D25334: Implement __stosb intrinsic as a volatile memset

2016-10-10 Thread David Majnemer via cfe-commits
majnemer added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:7610
+Value *SizeVal = EmitScalarExpr(E->getArg(2));
+EmitNonNullArgCheck(RValue::get(Dest.getPointer()), 
E->getArg(0)->getType(),
+E->getArg(0)->getExprLoc(), FD, 0);

agutowski wrote:
> hans wrote:
> > Hmm, does the __stosb intrinsic require Dest to be non-null (e.g. would 
> > Dest=NULL, Count=0 be OK?) I'm not even sure what llvm's memset requires 
> > actually.
> I can't find any guarantee that memset accepts Dest=NULL and Count=0. So I 
> guess we can either add a branch here, checking if the pointer is NULL (and 
> that Count=0?) or assume that memset won't do anything strange. I vote for 
> the latter (the current code does it).
I think the approach you've taken here is fine, we shouldn't need a branch.


https://reviews.llvm.org/D25334



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


[PATCH] D25442: Implement MS read/write barriers and __faststorefence intrinsic

2016-10-10 Thread David Majnemer via cfe-commits
majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D25442



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


[PATCH] D25153: preprocessor supports `-dI` flag

2016-10-06 Thread David Majnemer via cfe-commits
majnemer added a comment.

The change from an algorithmic POV looks good but I can't speak to whether or 
not the approach is sound, I'll leave that to @rsmith.



> majnemer wrote in PrintPreprocessedOutput.cpp:404
> !SearchPath.empty()

This review comment was never addressed.

https://reviews.llvm.org/D25153



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


[PATCH] D25349: [coroutines] Build fallthrough and set_exception statements.

2016-10-06 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> AnalysisBasedWarnings.cpp:537
>if (const FunctionDecl *FD = dyn_cast(D)) {
> -ReturnsVoid = FD->getReturnType()->isVoidType();
> +if (const CoroutineBodyStmt *CBody = dyn_cast(Body))
> +  ReturnsVoid = CBody->getFallthroughHandler() != nullptr;

`const auto *`

https://reviews.llvm.org/D25349



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


[PATCH] D25292: [coroutines] Add diagnostics for copy/move assignment operators and functions with deduced return types.

2016-10-05 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> SemaCoroutine.cpp:140
> +  // or the function 'main' are declared as a coroutine.
> +  CXXMethodDecl *MD = dyn_cast(FD);
> +  if (MD && isa(MD))

`auto *`

https://reviews.llvm.org/D25292



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


[PATCH] D25153: preprocessor supports `-dI` flag

2016-10-05 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> PrintPreprocessedOutput.cpp:331-349
> +  const size_t N = Path.size();
> +  size_t I = 0;
> +  while (I < N) {
> +if (Path[I] == '\\' || Path[I] == '\"') {
> +  // Have to escape backslashes or double-quotes.
> +  // Send out backslash to escape the next char.
> +  Buffer.push_back('\\');

I think this loop would be easier to understand like so:

  while (!Path.empty()) {
if (Path.consume_front("\\")) {
  Buffer.push_back("");
} else if (Path.consume_front("\"")) {
  Buffer.push_back("\\\"");
} else if (Path.consume_front("*/")) {
  Buffer.push_back("*\\/");
} else {
  Buffer.push_back(Path.front());
  Path = Path.drop_front();
}
  }

The big takeaway is that we now avoid messy `I + 1 < N` type checks.

https://reviews.llvm.org/D25153



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


[PATCH] D25264: Implement MS _BitScan intrinsics

2016-10-05 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> agutowski wrote in CGBuiltin.cpp:2665
> Is this line needed? I took it from __builtin_fpclassify, but I don't know 
> what could be its purpose (it's repeated below, where the "bitscan_end" block 
> really starts).

It's needed for the call to CreatePHI to be in the correct basic block.

https://reviews.llvm.org/D25264



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


[PATCH] D25264: Implement MS _BitScan intrinsics

2016-10-05 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> agutowski wrote in CGBuiltin.cpp:2656-2684
> MSDN doesn't specify what should be put under the "Index" address when the 
> argument is zero; as I checked, VS2015 with optimizations puts undefined 
> value there, and I hope that's what I'm doing here.

Intel (https://software.intel.com/en-us/node/523362) says the following:
Sets *p to the bit index of the least significant set bit of b or leaves it 
unchanged if b is zero. The function returns a non-zero result when b is 
non-zero and returns zero when b is zero.

This seems to mesh with this Mozilla bug report: 
https://bugzilla.mozilla.org/show_bug.cgi?id=1182370

https://reviews.llvm.org/D25264



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


[PATCH] D25264: Implement MS _BitScan intrinsics

2016-10-04 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> CGBuiltin.cpp:2640-2647
> +// Many of MSVC builtins are on both x64 and ARM; to avoid repeating code, we
> +// handle them here.
> +namespace MSVC {
> +  enum {
> +_BitScanForward,
> +_BitScanReverse
> +  };

This should be in an anonymous namespace. Also, consider using an `enum class` 
instead of an `enum` nested inside a namespace.

> CGBuiltin.cpp:2656-2684
> +llvm::Type *ArgType = ArgValue->getType();
> +llvm::Type *IndexType =
> +EmitScalarExpr(E->getArg(0))->getType()->getPointerElementType();
> +llvm::Type *ResultType = ConvertType(E->getType());
> +
> +Value *ArgZero = llvm::Constant::getNullValue(ArgType);
> +Value *ResZero = llvm::Constant::getNullValue(ResultType);

Does this do the right thing if the arg is zero?  I think it would if you gave 
the call to the intrinsic an operand of false instead of true.

https://reviews.llvm.org/D25264



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


[PATCH] D25258: [coroutines] Create allocation and deallocation sub-statements.

2016-10-04 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> CGCoroutine.cpp:68-69
> +void CodeGenFunction::EmitCoroutineBody(const CoroutineBodyStmt ) {
> +  auto *NullPtr = llvm::ConstantPointerNull::get(Builder.getInt8PtrTy());
> +  // FIXME: Instead of 0, pass an equivalent of alignas(maxalign_t).
> +  auto *CoroId =

I think that's just `CGM.getContext().getTargetInfo().getSuitableAlign() / 
CGM.getContext().getTargetInfo().getCharWidth()`

https://reviews.llvm.org/D25258



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> ItaniumMangle.cpp:1234
>  
> -  mangleSourceName(II);
> +  auto FD = dyn_cast(ND);
> +  bool isRegCall = (FD != nullptr) &&

`auto *`

> ItaniumMangle.cpp:1235
> +  auto FD = dyn_cast(ND);
> +  bool isRegCall = (FD != nullptr) &&
> +FD->getType()->castAs()->getCallConv() ==

The convention is to just do `FD` instead of `(FD != nullptr)`

https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-04 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> ItaniumMangle.cpp:1413-1414
>  
> -void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
> -  //  ::=  
> +void CXXNameMangler::mangleSourceName(const IdentifierInfo *II,
> +  bool isRegCall) {
> +  //  ::=  [__regcall3__] 

I'd add an overload of `mangleSourceName` which takes a `Twine`. Then the one 
caller which passes `isRegCall` would merely concat the identifier with 
__regcall3__. The existing implementation using `IdentifierInfo` would merely 
pass in `II->getName` for the `Twine`.

https://reviews.llvm.org/D25204



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


[PATCH] D25153: preprocessor supports `-dI` flag

2016-10-04 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> majnemer wrote in PrintPreprocessedOutput.cpp:321-325
> Variables should start with uppercase characters.

Please uppercase all your other variables too.

> PrintPreprocessedOutput.cpp:344
> + */
> +bool tryGetTokenText(StringRef *text, const Token ) {
> +  if (tok.getKind() == clang::tok::identifier) {

Could this just return a StringRef? You could use an empty StringRef on failure.

https://reviews.llvm.org/D25153



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


[PATCH] D25153: preprocessor supports `-dI` flag

2016-10-03 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> PrintPreprocessedOutput.cpp:321
> + */
> +std::string sanitizePath(const StringRef& path) {
> +  std::string str(path.size() * 2, '\0');

Don't pass `StringRef` by const reference, just pass it by value.

> PrintPreprocessedOutput.cpp:321-325
> +std::string sanitizePath(const StringRef& path) {
> +  std::string str(path.size() * 2, '\0');
> +  size_t len = 0;
> +  for (size_t i = 0; i < path.size(); i++) {
> +const char c = path[i];

Variables should start with uppercase characters.

> PrintPreprocessedOutput.cpp:344
> + */
> +bool tryGetTokenText(std::string* text, const Token ) {
> +  if (tok.getKind() == clang::tok::identifier) {

This could be a StringRef instead of a std::string.

> PrintPreprocessedOutput.cpp:346
> +  if (tok.getKind() == clang::tok::identifier) {
> +const auto* idInfo = tok.getIdentifierInfo();
> +if (idInfo && idInfo->getNameStart() != nullptr) {

Pointers lean right.

> PrintPreprocessedOutput.cpp:348
> +if (idInfo && idInfo->getNameStart() != nullptr) {
> +  *text = std::string(idInfo->getNameStart(), idInfo->getLength());
> +  return true;

Why not just use `getName` ?

https://reviews.llvm.org/D25153



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


[PATCH] D24986: [MS] Implement __iso_volatile loads/stores as builtins

2016-09-30 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> mstorsjo wrote in ms-volatile-arm.c:2
> Well, originally, the point was to clarify that these volatile stores end up 
> without atomic semantics, regardless of whether -volatile:ms has been 
> specified. The original version of this patch (with an inline implementation 
> in intrin.h, just using a normal volatile pointer) wouldn't pass this test, 
> but would pass if I remove this option. But if you prefer, I can leave it out.

Makes sense.

https://reviews.llvm.org/D24986



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


[PATCH] D24986: [MS] Implement __iso_volatile loads/stores as builtins

2016-09-30 Thread David Majnemer via cfe-commits
majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM



> ms-volatile-arm.c:2
> +// REQUIRES: arm-registered-target
> +// RUN: %clang_cc1 -triple thumbv7-win32 -emit-llvm -fms-extensions 
> -fms-volatile -o - < %s | FileCheck %s
> +

You don't need -fms-volatile.

https://reviews.llvm.org/D24986



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


[PATCH] [Commented On] D24986: [MS] Implement __iso_volatile loads/stores as builtins

2016-09-30 Thread David Majnemer via cfe-commits
majnemer added inline comments.


> CGBuiltin.cpp:2597-2611
> +case ARM::BI__iso_volatile_load8:
> +case ARM::BI__iso_volatile_load16:
> +case ARM::BI__iso_volatile_load32:
> +case ARM::BI__iso_volatile_load64:
> +  return RValue::get(EmitVolatileLoad(*this, E));
> +case ARM::BI__iso_volatile_store8:
> +case ARM::BI__iso_volatile_store16:

I think you could sink this into `EmitARMBuiltinExpr`.  You don't really need 
or want the fancy CGF machinery here. I'd just return the result of 
`CreateAlignedStore`/`CreateAlignedLoad` which should handle the 
`EmitTargetBuiltinExpr` issue.

https://reviews.llvm.org/D24986



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


[PATCH] [Changed Subscribers] D25068: [coroutines] Switch to using std::experimental namespace per P0057R5

2016-09-29 Thread David Majnemer via cfe-commits
majnemer added inline comments.
View RevisionView InlineSemaDeclCXX.cpp:8287-8290
NamespaceDecl *Sema::getStdExperimentalNamespace() const {
  return cast_or_null(
 StdExperimentalNamespace.get(Context.getExternalSource()));
}

Is this clang-format'd?https://reviews.llvm.org/D25068

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


Re: [PATCH] D24998: Add a new optimization option -Og

2016-09-27 Thread David Majnemer via cfe-commits
majnemer added a subscriber: majnemer.
majnemer added a comment.

Please include full context with your diff.



Comment at: lib/Frontend/CompilerInvocation.cpp:101-103
@@ -100,1 +100,5 @@
 
+if (S == "g") {
+return 1;
+}
+

Please clang-format this.


https://reviews.llvm.org/D24998



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


Re: [PATCH] D24986: Headers: Add iso_volatile load/store intrinsics

2016-09-27 Thread David Majnemer via cfe-commits
majnemer added a comment.

IMO, this should be implemented in clang CodeGen so that we don't get extra 
acquire/release barriers with /volatile:ms but that might be overkill; feel 
free to disregard this.


https://reviews.llvm.org/D24986



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


Re: [PATCH] D24841: [asan] Fix incorrect SEH symbol mangling on win64.

2016-09-22 Thread David Majnemer via cfe-commits
majnemer added a subscriber: majnemer.
majnemer accepted this revision.
majnemer added a reviewer: majnemer.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D24841



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


Re: [PATCH] D24693: [CodeGen] Don't emit lifetime intrinsics for some local variables

2016-09-21 Thread David Majnemer via cfe-commits
majnemer added a subscriber: majnemer.
majnemer added a comment.

In https://reviews.llvm.org/D24693#548739, @ahatanak wrote:

> Do we want to remove lifetime intrinsics when we aren't doing the 
> asan-use-after-scope check? Since this isn't a mis-compile caused by 
> inaccurate lifetime intrinsics, I was wondering whether we should do this 
> only when asan-use-after-scope is on to minimize the impact on compile time.


This doesn't sound right.  Given the example in the description, we are 
accessing the memory location after end has been called: this seems like a real 
miscompile.  It would appear unsafe to only do this for asan.


https://reviews.llvm.org/D24693



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


Re: [PATCH] D24751: [cleanup] Remove excessive padding from TextTokenRetokenizer::Position

2016-09-19 Thread David Majnemer via cfe-commits
majnemer added a subscriber: majnemer.
majnemer accepted this revision.
majnemer added a reviewer: majnemer.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rL LLVM

https://reviews.llvm.org/D24751



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


Re: [PATCH] D24648: Fix unused result from sign extending an Offset.

2016-09-16 Thread David Majnemer via cfe-commits
sext should probably be marked WARN_UNUSED_RESULT

On Thursday, September 15, 2016, Stephen Hines via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> srhines created this revision.
> srhines added a reviewer: cfe-commits.
> srhines added a subscriber: meikeb.
>
> Offset was doubled in size, but the assignment was missing. We just need
> to reassign to the original variable in this case to fix it.
>
> https://reviews.llvm.org/D24648
>
> Files:
>   lib/Sema/SemaChecking.cpp
>
> Index: lib/Sema/SemaChecking.cpp
> ===
> --- lib/Sema/SemaChecking.cpp
> +++ lib/Sema/SemaChecking.cpp
> @@ -3882,7 +3882,7 @@
>// possible.
>if (Ov) {
>  assert(BitWidth <= UINT_MAX / 2 && "index (intermediate) result too
> big");
> -Offset.sext(2 * BitWidth);
> +Offset = Offset.sext(2 * BitWidth);
>  sumOffsets(Offset, Addend, BinOpKind, AddendIsRight);
>  return;
>}
>
>
>
___
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 

r281189 - [MS ABI] Add /include directives for dynamic TLS

2016-09-11 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Sun Sep 11 21:51:43 2016
New Revision: 281189

URL: http://llvm.org/viewvc/llvm-project?rev=281189=rev
Log:
[MS ABI] Add /include directives for dynamic TLS

MSVC emits /include directives in the .drective section for the
__dyn_tls_init function (decorated as ___dyn_tls_init@12 for 32-bit).

This fixes PR30347.

Modified:
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGenCXX/ms-thread_local.cpp

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=281189=281188=281189=diff
==
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Sun Sep 11 21:51:43 2016
@@ -2211,6 +2211,14 @@ void MicrosoftCXXABI::EmitThreadLocalIni
 CodeGenModule , ArrayRef CXXThreadLocals,
 ArrayRef CXXThreadLocalInits,
 ArrayRef CXXThreadLocalInitVars) {
+  if (CXXThreadLocalInits.empty())
+return;
+
+  CGM.AppendLinkerOptions(CGM.getTarget().getTriple().getArch() ==
+  llvm::Triple::x86
+  ? "/include:___dyn_tls_init@12"
+  : "/include:__dyn_tls_init");
+
   // This will create a GV in the .CRT$XDU section.  It will point to our
   // initialization function.  The CRT will call all of these function
   // pointers at start-up time and, eventually, at thread-creation time.

Modified: cfe/trunk/test/CodeGenCXX/ms-thread_local.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ms-thread_local.cpp?rev=281189=281188=281189=diff
==
--- cfe/trunk/test/CodeGenCXX/ms-thread_local.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ms-thread_local.cpp Sun Sep 11 21:51:43 2016
@@ -26,3 +26,8 @@ A f() {
   (void)b;
   return c;
 }
+
+// CHECK: !llvm.module.flags = !{{{.*}}}
+// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[link_opts:[0-9]+]]}
+// CHECK: ![[link_opts]] = !{![[dyn_tls_init:[0-9]+]]}
+// CHECK: ![[dyn_tls_init]] = !{!"/include:___dyn_tls_init@12"}


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


[PATCH] D24378: [CodeGen] Provide an appropriate alignment for dynamic allocas

2016-09-09 Thread David Majnemer via cfe-commits
majnemer created this revision.
majnemer added reviewers: rnk, rsmith, efriedma, chandlerc.
majnemer added a subscriber: cfe-commits.

GCC documents __builtin_alloca as aligning the storage to at least
__BIGGEST_ALIGNMENT__.

MSVC documents essentially the same for the x64 ABI:
https://msdn.microsoft.com/en-us/library/x9sx5da1.aspx

The 32-bit ABI follows the same rule: it emits a call to _alloca_probe_16

https://reviews.llvm.org/D24378

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtins-ms.c

Index: test/CodeGen/builtins-ms.c
===
--- test/CodeGen/builtins-ms.c
+++ test/CodeGen/builtins-ms.c
@@ -4,6 +4,6 @@
 void capture(void *);
 void test_alloca(int n) {
   capture(_alloca(n));
-  // CHECK: %[[arg:.*]] = alloca i8, i32 %
+  // CHECK: %[[arg:.*]] = alloca i8, i32 %{{.*}}, align 16
   // CHECK: call void @capture(i8* %[[arg]])
 }
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -1015,7 +1015,13 @@
   case Builtin::BI_alloca:
   case Builtin::BI__builtin_alloca: {
 Value *Size = EmitScalarExpr(E->getArg(0));
-return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size));
+const TargetInfo  = getContext().getTargetInfo();
+// The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
+unsigned SuitableAlignmentInBytes =
+TI.getSuitableAlign() / TI.getCharWidth();
+AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
+AI->setAlignment(SuitableAlignmentInBytes);
+return RValue::get(AI);
   }
   case Builtin::BIbzero:
   case Builtin::BI__builtin_bzero: {


Index: test/CodeGen/builtins-ms.c
===
--- test/CodeGen/builtins-ms.c
+++ test/CodeGen/builtins-ms.c
@@ -4,6 +4,6 @@
 void capture(void *);
 void test_alloca(int n) {
   capture(_alloca(n));
-  // CHECK: %[[arg:.*]] = alloca i8, i32 %
+  // CHECK: %[[arg:.*]] = alloca i8, i32 %{{.*}}, align 16
   // CHECK: call void @capture(i8* %[[arg]])
 }
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -1015,7 +1015,13 @@
   case Builtin::BI_alloca:
   case Builtin::BI__builtin_alloca: {
 Value *Size = EmitScalarExpr(E->getArg(0));
-return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size));
+const TargetInfo  = getContext().getTargetInfo();
+// The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
+unsigned SuitableAlignmentInBytes =
+TI.getSuitableAlign() / TI.getCharWidth();
+AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
+AI->setAlignment(SuitableAlignmentInBytes);
+return RValue::get(AI);
   }
   case Builtin::BIbzero:
   case Builtin::BI__builtin_bzero: {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24311: Implement MS _rot intrinsics

2016-09-08 Thread David Majnemer via cfe-commits
majnemer added inline comments.


Comment at: lib/AST/ExprConstant.cpp:7024-7050
@@ -7023,1 +7023,29 @@
 
+  case Builtin::BI_rotl8:
+  case Builtin::BI_rotl16:
+  case Builtin::BI_rotl:
+  case Builtin::BI_lrotl:
+  case Builtin::BI_rotl64: {
+APSInt Val, Shift;
+if (!EvaluateInteger(E->getArg(0), Val, Info) ||
+!EvaluateInteger(E->getArg(1), Shift, Info))
+  return false;
+
+APSInt BitWidth(llvm::APInt(32, Val.getBitWidth()));
+return Success(Val.rotl(Shift % BitWidth), E);
+  }
+
+  case Builtin::BI_rotr8:
+  case Builtin::BI_rotr16:
+  case Builtin::BI_rotr:
+  case Builtin::BI_lrotr:
+  case Builtin::BI_rotr64: {
+APSInt Val, Shift;
+if (!EvaluateInteger(E->getArg(0), Val, Info) ||
+!EvaluateInteger(E->getArg(1), Shift, Info))
+  return false;
+
+APSInt BitWidth(llvm::APInt(32, Val.getBitWidth()));
+return Success(Val.rotr(Shift % BitWidth), E);
+  }
+

agutowski wrote:
> majnemer wrote:
> > Any reason why we need this?
> > 
> > Given:
> >   #include 
> > 
> >   constexpr int x = _rotl8(1, 2);
> > 
> > MSVC 2015 reports:
> >   error C2131: expression did not evaluate to a constant
> Hm, I don't know. Is there any reason why we shouldn't do this? I mean, I 
> just had the feeling that if we can evaluate something during compilation 
> time, we should to it.
The best reason I can think of is that it allows people to use a 
Microsoft-specific intrinsic in ways which won't compile with Microsoft's 
compiler.


https://reviews.llvm.org/D24311



___
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-08 Thread David Majnemer via cfe-commits
majnemer added inline comments.


Comment at: include/clang/Basic/BuiltinsX86.def:304
@@ -303,2 +303,3 @@
 TARGET_BUILTIN(__builtin_ia32_ldmxcsr, "vUi", "", "sse")
+TARGET_BUILTIN(_mm_setcsr, "vUi", "", "sse")
 TARGET_BUILTIN(__builtin_ia32_stmxcsr, "Ui", "", "sse")

rnk wrote:
> Part of the idea behind the Intel *mmintrin.h headers is that they define 
> symbols outside of the implementor's namespace. Users should be able to write 
> code that uses these _mm_* names if they don't include those headers. Having 
> this builtin always be available on x86 makes that impossible.
> 
> That said, I can see that winnt.h uses these directly, rather than including 
> xmmintrin.h, so we need them to be builtins in MSVC mode, and it's annoying 
> to have them sometimes be builtins and sometimes be functions.
We could have the header file use a pragma which turns the _mm intrinsics on 
along the same lines as `#pragma intrinsic`.  For MSVC compat, we could treat 
them as-if they were enabled by some similar mechanism.


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] D24311: Implement MS _rot intrinsics

2016-09-07 Thread David Majnemer via cfe-commits
majnemer added inline comments.


Comment at: lib/AST/ExprConstant.cpp:7024-7050
@@ -7023,1 +7023,29 @@
 
+  case Builtin::BI_rotl8:
+  case Builtin::BI_rotl16:
+  case Builtin::BI_rotl:
+  case Builtin::BI_lrotl:
+  case Builtin::BI_rotl64: {
+APSInt Val, Shift;
+if (!EvaluateInteger(E->getArg(0), Val, Info) ||
+!EvaluateInteger(E->getArg(1), Shift, Info))
+  return false;
+
+APSInt BitWidth(llvm::APInt(32, Val.getBitWidth()));
+return Success(Val.rotl(Shift % BitWidth), E);
+  }
+
+  case Builtin::BI_rotr8:
+  case Builtin::BI_rotr16:
+  case Builtin::BI_rotr:
+  case Builtin::BI_lrotr:
+  case Builtin::BI_rotr64: {
+APSInt Val, Shift;
+if (!EvaluateInteger(E->getArg(0), Val, Info) ||
+!EvaluateInteger(E->getArg(1), Shift, Info))
+  return false;
+
+APSInt BitWidth(llvm::APInt(32, Val.getBitWidth()));
+return Success(Val.rotr(Shift % BitWidth), E);
+  }
+

Any reason why we need this?

Given:
  #include 

  constexpr int x = _rotl8(1, 2);

MSVC 2015 reports:
  error C2131: expression did not evaluate to a constant


https://reviews.llvm.org/D24311



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


Re: [PATCH] D24311: Implement MS _rot intrinsics

2016-09-07 Thread David Majnemer via cfe-commits
majnemer added a subscriber: majnemer.
majnemer added a comment.

In https://reviews.llvm.org/D24311#536545, @agutowski wrote:

> In https://reviews.llvm.org/D24311#536333, @rnk wrote:
>
> > You should locally verify that this generates the correct assembly when 
> > optimizations are enabled, and if it doesn't, try to make the input look 
> > more like llvm/test/CodeGen/X86/rotate.ll
>
>
> Yeah, I checked that it's optimized to ROL/ROR instruction - now, after 
> looking closer, I can see that it's optimized for all functions except for 
> the ones operating on 16-bit integers. Could that be a calculated decision, 
> or should I try to make it generate ROL/ROR whenever it can?
>
> Edit: I tried to make the code as similar to the one from rotate.ll as 
> possible, and it's still not optimized to ROL/ROR for 16-bit integers, so I 
> guess it should stay that way.


I wouldn't worry about this too much...  It is up to the backend to do the 
right thing.


https://reviews.llvm.org/D24311



___
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-07 Thread David Majnemer via cfe-commits
majnemer added a comment.

In https://reviews.llvm.org/D24153#535992, @rnk wrote:

> Looks good to me. David, do you remember any subtleties here? I seem to 
> recall there were some bugs in our intrin.h implementations, or 
> inconsistencies between us and MSVC.


I can't seem to recall anything major.  Our `_ReadBarrier` and `_WriteBarrier` 
simply map to `_ReadWriteBarrier`.  Our `__faststorefence` is just a normal 
fence instead of an interlocked operation.


https://reviews.llvm.org/D24153



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


Re: [PATCH] D23503: [clang-cl] Check that we are in clang cl mode before enabling support for the CL environment variable.

2016-09-05 Thread David Majnemer via cfe-commits
majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D23503



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


Re: [PATCH] D23938: clang-cl: Accept MSVC 2015's `/execution-charset:utf-8` flag.

2016-08-26 Thread David Majnemer via cfe-commits
majnemer added a subscriber: majnemer.


Comment at: lib/Driver/Tools.cpp:5838-5846
@@ -5837,11 +5837,11 @@
 StringRef value = inputCharset->getValue();
 if (value.lower() != "utf-8")
   D.Diag(diag::err_drv_invalid_value) << inputCharset->getAsString(Args)
   << value;
   }
 
   // -fexec_charset=UTF-8 is default. Reject others
   if (Arg *execCharset = Args.getLastArg(options::OPT_fexec_charset_EQ)) {
 StringRef value = execCharset->getValue();
-if (value != "UTF-8")
+if (value.lower() != "utf-8")
   D.Diag(diag::err_drv_invalid_value) << execCharset->getAsString(Args)

I'd use `compare_lower` because `lower` introduces a `std::string`.


https://reviews.llvm.org/D23938



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


Re: [PATCH] D23938: clang-cl: Accept MSVC 2015's `/execution-charset:utf-8` flag.

2016-08-26 Thread David Majnemer via cfe-commits
On Friday, August 26, 2016, Nico Weber via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> thakis created this revision.
> thakis added a reviewer: hans.
> thakis added a subscriber: cfe-commits.
>
> Like https://reviews.llvm.org/D23807, but for execution-charset.
>
> https://reviews.llvm.org/D23938
>
> Files:
>   include/clang/Driver/CLCompatOptions.td
>   lib/Driver/Tools.cpp
>   test/Driver/cl-options.c
>
> Index: test/Driver/cl-options.c
> ===
> --- test/Driver/cl-options.c
> +++ test/Driver/cl-options.c
> @@ -184,6 +184,10 @@
>  // RUN: %clang_cl /source-charset:utf-16 -### -- %s 2>&1 | FileCheck
> -check-prefix=source-charset-utf-16 %s
>  // source-charset-utf-16: invalid value 'utf-16'
>
> +// /execution-charset: should warn on everything except UTF-8.
> +// RUN: %clang_cl /execution-charset:utf-16 -### -- %s 2>&1 | FileCheck
> -check-prefix=execution-charset-utf-16 %s
> +// execution-charset-utf-16: invalid value 'utf-16'
> +//
>  // RUN: %clang_cl /Umymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s
>  // RUN: %clang_cl /U mymacro -### -- %s 2>&1 | FileCheck -check-prefix=U
> %s
>  // U: "-U" "mymacro"
> @@ -289,6 +293,7 @@
>  // RUN:/d2FastFail \
>  // RUN:/d2Zi+ \
>  // RUN:/errorReport:foo \
> +// RUN:/execution-charset:utf-8 \
>  // RUN:/FC \
>  // RUN:/Fdfoo \
>  // RUN:/FS \
> Index: lib/Driver/Tools.cpp
> ===
> --- lib/Driver/Tools.cpp
> +++ lib/Driver/Tools.cpp
> @@ -5843,7 +5843,7 @@
>// -fexec_charset=UTF-8 is default. Reject others
>if (Arg *execCharset = Args.getLastArg(options::OPT_fexec_charset_EQ))
> {
>  StringRef value = execCharset->getValue();
> -if (value != "UTF-8")
> +if (value.lower() != "UTF-8")


Should that be "utf-8" instead?


>D.Diag(diag::err_drv_invalid_value) <<
> execCharset->getAsString(Args)
><< value;
>}
> Index: include/clang/Driver/CLCompatOptions.td
> ===
> --- include/clang/Driver/CLCompatOptions.td
> +++ include/clang/Driver/CLCompatOptions.td
> @@ -122,6 +122,8 @@
>Alias;
>  def _SLASH_source_charset : CLCompileJoined<"source-charset:">,
>HelpText<"Source encoding, supports only UTF-8">,
> Alias;
> +def _SLASH_execution_charset : CLCompileJoined<"execution-charset:">,
> +  HelpText<"Runtime encoding, supports only UTF-8">,
> Alias;
>  def _SLASH_std : CLCompileJoined<"std:">,
>HelpText<"Language standard to compile for">;
>  def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">,
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22334: Fix for Bug 28172 : clang crashes on invalid code (with too few arguments to __builtin_signbit) without any proper diagnostics.

2016-08-26 Thread David Majnemer via cfe-commits
majnemer added a comment.

This looks much better. Please add a test that uses a template:

  template 
  int f(T t) { return __builtin_signbit(t); }



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7401-7403
@@ -7400,2 +7400,5 @@
 
+def err_builtin_signbit_wrong_argument : Error<
+  "Argument type mismatch, must be float, double or long double">;
+
 // CFString checking

Hmm, I think it would be better if you added this near 
`err_typecheck_cond_expect_int_float`, named it 
`err_typecheck_cond_expect_float`, and gave it a similar error message.


https://reviews.llvm.org/D22334



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


  1   2   3   4   5   >