[PATCH] D40925: Add option -fkeep-static-consts

2018-08-17 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 161307.
eandrews edited the summary of this revision.
eandrews added a comment.

This patch fell through the cracks earlier. I apologize. Based on Reid's and 
Erich's feedback, I am now adding the variable to @llvm.used. Additionally I 
modified the if statements to ensure only static variables are considered.

I also compared the IR when using the option -fkeep-static-consts while 
compiling the program, vs adding __attribute__((used)) to individual variables 
inside the program. The generated IR had no difference. I assume this means all 
required information to prevent the variable from being removed in later stages 
are now being emitted?


https://reviews.llvm.org/D40925

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  lib/AST/ASTContext.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/keep-static-consts.cpp


Index: test/CodeGen/keep-static-consts.cpp
===
--- /dev/null
+++ test/CodeGen/keep-static-consts.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fkeep-static-consts -emit-llvm %s -o - 
-triple=x86_64-unknown-linux-gnu | FileCheck %s
+
+// CHECK: @_ZL7srcvers = internal constant [4 x i8] c"xyz\00", align 1
+// CHECK: @llvm.used = appending global [1 x i8*] [i8* getelementptr inbounds 
([4 x i8], [4 x i8]* @_ZL7srcvers, i32 0, i32 0)], section "llvm.metadata"
+static const char srcvers[] = "xyz";
+extern const int b = 1;
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2485,6 +2485,7 @@
   Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns)
 | Opts.NativeHalfArgsAndReturns;
   Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm);
+  Opts.KeepStaticConsts = Args.hasArg(OPT_fkeep_static_consts);
 
   // __declspec is enabled by default for the PS4 by the driver, and also
   // enabled for Microsoft Extensions or Borland Extensions, here.
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3996,6 +3996,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);
+  Args.AddLastArg(CmdArgs, options::OPT_fkeep_static_consts);
 
   // AltiVec-like language extensions aren't relevant for assembling.
   if (!isa(JA) || Output.getType() != types::TY_PP_Asm)
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1350,6 +1350,12 @@
 
   if (D && D->hasAttr())
 addUsedGlobal(GV);
+
+  if (LangOpts.KeepStaticConsts && D && isa(D)) {
+const auto *VD = cast(D);
+if (VD->getType().isConstQualified() && VD->getStorageClass() == SC_Static)
+  addUsedGlobal(GV);
+  }
 }
 
 bool CodeGenModule::GetCPUAndFeaturesAttributes(const Decl *D,
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -9741,6 +9741,14 @@
   if (D->hasAttr() || D->hasAttr())
 return true;
 
+  // Emit static constants even if they are not used if KeepStaticConsts is 
set.
+  if (LangOpts.KeepStaticConsts) {
+const auto *VD = dyn_cast(D);
+if (VD && VD->getType().isConstQualified() &&
+VD->getStorageClass() == SC_Static)
+  return true;
+  }
+
   if (const auto *FD = dyn_cast(D)) {
 // Forward declarations aren't required.
 if (!FD->doesThisDeclarationHaveABody())
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -893,7 +893,8 @@
 def fno_force_enable_int128 : Flag<["-"], "fno-force-enable-int128">,
   Group, Flags<[CC1Option]>,
   HelpText<"Disable support for int128_t type">;
-
+def fkeep_static_consts : Flag<["-"], "fkeep-static-consts">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Keep static const variables even if unused">;
 def ffixed_point : Flag<["-"], "ffixed-point">, Group,
Flags<[CC1Option]>, HelpText<"Enable fixed point types">;
 def fno_fixed_point : Flag<["-"], "fno-fixed-point">, Group,
Index: include/clang/Basic/LangOptions.def
===
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -308,6 +308,8 @@
 LANGOPT(PaddingOnUnsignedFixedPoint, 1, 0,
 "unsigned fixed point types having one extra padding bit")
 
+BENIGN_LANGOPT(KeepStaticConsts  , 1, 0, "keep static const variables even 
if u

[PATCH] D40925: Add option -fkeep-static-consts

2018-08-20 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 161544.
eandrews added a comment.

Based on Reid's feedback, I changed option to CodeGenOption


https://reviews.llvm.org/D40925

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/keep-static-consts.cpp


Index: test/CodeGen/keep-static-consts.cpp
===
--- /dev/null
+++ test/CodeGen/keep-static-consts.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fkeep-static-consts -emit-llvm %s -o - 
-triple=x86_64-unknown-linux-gnu | FileCheck %s
+
+// CHECK: @_ZL7srcvers = internal constant [4 x i8] c"xyz\00", align 1
+// CHECK: @llvm.used = appending global [1 x i8*] [i8* getelementptr inbounds 
([4 x i8], [4 x i8]* @_ZL7srcvers, i32 0, i32 0)], section "llvm.metadata"
+static const char srcvers[] = "xyz";
+extern const int b = 1;
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1125,6 +1125,8 @@
 
   Opts.Addrsig = Args.hasArg(OPT_faddrsig);
 
+  Opts.KeepStaticConsts = Args.hasArg(OPT_fkeep_static_consts);
+
   return Success;
 }
 
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3996,6 +3996,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);
+  Args.AddLastArg(CmdArgs, options::OPT_fkeep_static_consts);
 
   // AltiVec-like language extensions aren't relevant for assembling.
   if (!isa(JA) || Output.getType() != types::TY_PP_Asm)
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1350,6 +1350,12 @@
 
   if (D && D->hasAttr())
 addUsedGlobal(GV);
+
+  if (CodeGenOpts.KeepStaticConsts && D && isa(D)) {
+const auto *VD = cast(D);
+if (VD->getType().isConstQualified() && VD->getStorageClass() == SC_Static)
+  addUsedGlobal(GV);
+  }
 }
 
 bool CodeGenModule::GetCPUAndFeaturesAttributes(const Decl *D,
@@ -1985,6 +1991,13 @@
   if (LangOpts.EmitAllDecls)
 return true;
 
+  if (CodeGenOpts.KeepStaticConsts) {
+const auto *VD = dyn_cast(Global);
+if (VD && VD->getType().isConstQualified() &&
+VD->getStorageClass() == SC_Static)
+  return true;
+  }
+
   return getContext().DeclMustBeEmitted(Global);
 }
 
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -339,6 +339,9 @@
 /// Whether to emit an address-significance table into the object file.
 CODEGENOPT(Addrsig, 1, 0)
 
+/// Whether to emit unused static constants.
+CODEGENOPT(KeepStaticConsts, 1, 0)
+
 
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -893,7 +893,8 @@
 def fno_force_enable_int128 : Flag<["-"], "fno-force-enable-int128">,
   Group, Flags<[CC1Option]>,
   HelpText<"Disable support for int128_t type">;
-
+def fkeep_static_consts : Flag<["-"], "fkeep-static-consts">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Keep static const variables even if unused">;
 def ffixed_point : Flag<["-"], "ffixed-point">, Group,
Flags<[CC1Option]>, HelpText<"Enable fixed point types">;
 def fno_fixed_point : Flag<["-"], "fno-fixed-point">, Group,


Index: test/CodeGen/keep-static-consts.cpp
===
--- /dev/null
+++ test/CodeGen/keep-static-consts.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fkeep-static-consts -emit-llvm %s -o - -triple=x86_64-unknown-linux-gnu | FileCheck %s
+
+// CHECK: @_ZL7srcvers = internal constant [4 x i8] c"xyz\00", align 1
+// CHECK: @llvm.used = appending global [1 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @_ZL7srcvers, i32 0, i32 0)], section "llvm.metadata"
+static const char srcvers[] = "xyz";
+extern const int b = 1;
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1125,6 +1125,8 @@
 
   Opts.Addrsig = Args.hasArg(OPT_faddrsig);
 
+  Opts.KeepStaticConsts = Args.hasArg(OPT_fkeep_static_consts);
+
   return Success;
 }
 
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolCh

[PATCH] D40925: Add option -fkeep-static-consts

2018-08-20 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews marked an inline comment as done.
eandrews added inline comments.



Comment at: include/clang/Basic/LangOptions.def:311
 
+BENIGN_LANGOPT(KeepStaticConsts  , 1, 0, "keep static const variables even 
if unused")
+

rnk wrote:
> Let's make this a CodeGenOption, since only CodeGen needs to look at it.
Thanks for the feedback Reid! I've changed it


https://reviews.llvm.org/D40925



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


[PATCH] D40925: Add option -fkeep-static-consts

2018-08-20 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews marked an inline comment as done.
eandrews added a comment.

In https://reviews.llvm.org/D40925#1206416, @rnk wrote:

> lgtm!


Thanks!


https://reviews.llvm.org/D40925



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


[PATCH] D40925: Add option -fkeep-static-consts

2018-08-22 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC340439: Currently clang does not emit unused static 
constants. GCC emits these (authored by eandrews, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D40925?vs=161544&id=162022#toc

Repository:
  rC Clang

https://reviews.llvm.org/D40925

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/keep-static-consts.cpp


Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -893,7 +893,8 @@
 def fno_force_enable_int128 : Flag<["-"], "fno-force-enable-int128">,
   Group, Flags<[CC1Option]>,
   HelpText<"Disable support for int128_t type">;
-
+def fkeep_static_consts : Flag<["-"], "fkeep-static-consts">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Keep static const variables even if unused">;
 def ffixed_point : Flag<["-"], "ffixed-point">, Group,
Flags<[CC1Option]>, HelpText<"Enable fixed point types">;
 def fno_fixed_point : Flag<["-"], "fno-fixed-point">, Group,
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -341,6 +341,9 @@
 
 ENUM_CODEGENOPT(SignReturnAddress, SignReturnAddressScope, 2, None)
 
+/// Whether to emit unused static constants.
+CODEGENOPT(KeepStaticConsts, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: test/CodeGen/keep-static-consts.cpp
===
--- test/CodeGen/keep-static-consts.cpp
+++ test/CodeGen/keep-static-consts.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fkeep-static-consts -emit-llvm %s -o - 
-triple=x86_64-unknown-linux-gnu | FileCheck %s
+
+// CHECK: @_ZL7srcvers = internal constant [4 x i8] c"xyz\00", align 1
+// CHECK: @llvm.used = appending global [1 x i8*] [i8* getelementptr inbounds 
([4 x i8], [4 x i8]* @_ZL7srcvers, i32 0, i32 0)], section "llvm.metadata"
+static const char srcvers[] = "xyz";
+extern const int b = 1;
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1145,6 +1145,8 @@
   << A->getAsString(Args) << A->getValue();
   }
 
+  Opts.KeepStaticConsts = Args.hasArg(OPT_fkeep_static_consts);
+
   return Success;
 }
 
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1350,6 +1350,12 @@
 
   if (D && D->hasAttr())
 addUsedGlobal(GV);
+
+  if (CodeGenOpts.KeepStaticConsts && D && isa(D)) {
+const auto *VD = cast(D);
+if (VD->getType().isConstQualified() && VD->getStorageClass() == SC_Static)
+  addUsedGlobal(GV);
+  }
 }
 
 bool CodeGenModule::GetCPUAndFeaturesAttributes(const Decl *D,
@@ -1985,6 +1991,13 @@
   if (LangOpts.EmitAllDecls)
 return true;
 
+  if (CodeGenOpts.KeepStaticConsts) {
+const auto *VD = dyn_cast(Global);
+if (VD && VD->getType().isConstQualified() &&
+VD->getStorageClass() == SC_Static)
+  return true;
+  }
+
   return getContext().DeclMustBeEmitted(Global);
 }
 
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4008,6 +4008,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);
+  Args.AddLastArg(CmdArgs, options::OPT_fkeep_static_consts);
 
   // AltiVec-like language extensions aren't relevant for assembling.
   if (!isa(JA) || Output.getType() != types::TY_PP_Asm)


Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -893,7 +893,8 @@
 def fno_force_enable_int128 : Flag<["-"], "fno-force-enable-int128">,
   Group, Flags<[CC1Option]>,
   HelpText<"Disable support for int128_t type">;
-
+def fkeep_static_consts : Flag<["-"], "fkeep-static-consts">, Group, Flags<[CC1Option]>,
+  HelpText<"Keep static const variables even if unused">;
 def ffixed_point : Flag<["-"], "ffixed-point">, Group,
Flags<[CC1Option]>, HelpText<"Enable fixed point types">;
 def fno_fixed_point : Flag<["-"], "fno-fixed-point">, Group,
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Fro

[PATCH] D36487: Emit section information for extern variables.

2017-09-25 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 116581.
eandrews added a comment.

I've modified the patch to emit a warning for re-declarations only. I also 
removed the isUsed check.


https://reviews.llvm.org/D36487

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGenCXX/extern-section-attribute.cpp
  test/Sema/attr-section.c


Index: test/Sema/attr-section.c
===
--- test/Sema/attr-section.c
+++ test/Sema/attr-section.c
@@ -19,3 +19,7 @@
 void __attribute__((section("bar,zed"))) test2(void) {} // expected-warning 
{{section does not match previous declaration}}
 
 enum __attribute__((section("NEAR,x"))) e { one }; // expected-error 
{{'section' attribute only applies to functions, methods, properties, and 
global variables}}
+
+extern int a; // expected-note {{previous declaration is here}}
+int *b = &a;
+extern int a __attribute__((section("foo,zed"))); // expected-warning 
{{section attribute is specified on redeclared variable}}
Index: test/CodeGenCXX/extern-section-attribute.cpp
===
--- /dev/null
+++ test/CodeGenCXX/extern-section-attribute.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux-gnu | FileCheck 
%s
+
+extern int aa __attribute__((section(".sdata")));
+// CHECK-DAG: @aa = external global i32, section ".sdata", align 4
+
+extern int bb __attribute__((section(".sdata"))) = 1;
+// CHECK-DAG: @bb = global i32 1, section ".sdata", align 4
+
+int foo() {
+  return aa + bb;
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2607,6 +2607,16 @@
 }
   }
 
+  // This redeclaration adds a section attribute.
+  if (New->hasAttr() && !Old->hasAttr()) {
+if (auto *VD = dyn_cast(New)) {
+  if (VD->isThisDeclarationADefinition() != VarDecl::Definition) {
+Diag(New->getLocation(), 
diag::warn_attribute_section_on_redeclaration);
+Diag(Old->getLocation(), diag::note_previous_declaration);
+  }
+}
+  }
+
   if (!Old->hasAttrs())
 return;
 
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2436,6 +2436,12 @@
   EmitGlobalVarDefinition(D);
 }
 
+// Emit section information for extern variables.
+if (D->hasExternalStorage()) {
+  if (const SectionAttr *SA = D->getAttr())
+GV->setSection(SA->getName());
+}
+
 // Handle XCore specific ABI requirements.
 if (getTriple().getArch() == llvm::Triple::xcore &&
 D->getLanguageLinkage() == CLanguageLinkage &&
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -2620,6 +2620,8 @@
   "argument to 'section' attribute is not valid for this target: %0">;
 def warn_mismatched_section : Warning<
   "section does not match previous declaration">, InGroup;
+def warn_attribute_section_on_redeclaration : Warning<
+  "section attribute is specified on redeclared variable">, InGroup;
 
 def err_anonymous_property: Error<
   "anonymous property is not supported">;


Index: test/Sema/attr-section.c
===
--- test/Sema/attr-section.c
+++ test/Sema/attr-section.c
@@ -19,3 +19,7 @@
 void __attribute__((section("bar,zed"))) test2(void) {} // expected-warning {{section does not match previous declaration}}
 
 enum __attribute__((section("NEAR,x"))) e { one }; // expected-error {{'section' attribute only applies to functions, methods, properties, and global variables}}
+
+extern int a; // expected-note {{previous declaration is here}}
+int *b = &a;
+extern int a __attribute__((section("foo,zed"))); // expected-warning {{section attribute is specified on redeclared variable}}
Index: test/CodeGenCXX/extern-section-attribute.cpp
===
--- /dev/null
+++ test/CodeGenCXX/extern-section-attribute.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux-gnu | FileCheck %s
+
+extern int aa __attribute__((section(".sdata")));
+// CHECK-DAG: @aa = external global i32, section ".sdata", align 4
+
+extern int bb __attribute__((section(".sdata"))) = 1;
+// CHECK-DAG: @bb = global i32 1, section ".sdata", align 4
+
+int foo() {
+  return aa + bb;
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2607,6 +2607,16 @@
 }
   }
 
+  // This redeclaration adds a section attribute.
+  if (New->hasAttr() && !Old->hasAttr()) {
+if (auto *VD = dyn_cast(New)) {
+   

[PATCH] D39210: Add default calling convention support for regcall.

2017-10-23 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.

Added support for regcall as default calling convention.  Also added code to 
exclude main when applying default calling conventions.


https://reviews.llvm.org/D39210

Files:
  include/clang/AST/ASTContext.h
  include/clang/Basic/LangOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/CLCompatOptions.td
  lib/AST/ASTContext.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenCXX/default_calling_conv.cpp
  test/Driver/cl-cc-flags.c

Index: test/Driver/cl-cc-flags.c
===
--- test/Driver/cl-cc-flags.c
+++ test/Driver/cl-cc-flags.c
@@ -13,6 +13,9 @@
 // RUN: %clang_cl --target=i686-windows-msvc /Gv -### -- %s 2>&1 | FileCheck --check-prefix=VECTORCALL %s
 // VECTORCALL: -fdefault-calling-conv=vectorcall
 
+// RUN: %clang_cl --target=i686-windows-msvc /Gregcall -### -- %s 2>&1 | FileCheck --check-prefix=REGCALL %s
+// REGCALL: -fdefault-calling-conv=regcall
+
 // Last one should win:
 
 // RUN: %clang_cl --target=i686-windows-msvc /Gd /Gv -### -- %s 2>&1 | FileCheck --check-prefix=LASTWINS_VECTOR %s
Index: test/CodeGenCXX/default_calling_conv.cpp
===
--- test/CodeGenCXX/default_calling_conv.cpp
+++ test/CodeGenCXX/default_calling_conv.cpp
@@ -3,11 +3,13 @@
 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -fdefault-calling-conv=stdcall -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s --check-prefix=VECTORCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s --check-prefix=REGCALL --check-prefix=ALL
 
 // CDECL: define void @_Z5test1v
 // FASTCALL: define x86_fastcallcc void @_Z5test1v
 // STDCALL: define x86_stdcallcc void @_Z5test1v
 // VECTORCALL: define x86_vectorcallcc void @_Z5test1v
+// REGCALL: define x86_regcallcc void @_Z17__regcall3__test1v
 void test1() {}
 
 // ALL: define void @_Z5test2v
@@ -22,6 +24,9 @@
 // ALL: define  x86_vectorcallcc void @_Z5test5v
 void __attribute__((vectorcall)) test5() {}
 
+// ALL: define x86_regcallcc void @_Z17__regcall3__test6v
+void __attribute__((regcall)) test6() {}
+
 // ALL: define linkonce_odr void @_ZN1A11test_memberEv
 class A {
 public:
@@ -32,3 +37,8 @@
   A a;
   a.test_member();
 }
+
+// ALL: define i32 @main
+int main() {
+  return 1;
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3266,8 +3266,14 @@
 }
   }
 
-  CallingConv CC = S.Context.getDefaultCallingConvention(FTI.isVariadic,
- IsCXXInstanceMethod);
+  bool IsMain = false;
+  if (D.getIdentifier() && D.getIdentifier()->isStr("main") &&
+  S.CurContext->getRedeclContext()->isTranslationUnit() &&
+  !S.getLangOpts().Freestanding)
+IsMain = true;
+
+  CallingConv CC = S.Context.getDefaultCallingConvention(
+  FTI.isVariadic, IsCXXInstanceMethod, IsMain);
 
   // Attribute AT_OpenCLKernel affects the calling convention for SPIR
   // and AMDGPU targets, hence it cannot be treated as a calling
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2299,12 +2299,12 @@
   // Check for MS default calling conventions being specified.
   if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
 LangOptions::DefaultCallingConvention DefaultCC =
-llvm::StringSwitch(
-A->getValue())
+llvm::StringSwitch(A->getValue())
 .Case("cdecl", LangOptions::DCC_CDecl)
 .Case("fastcall", LangOptions::DCC_FastCall)
 .Case("stdcall", LangOptions::DCC_StdCall)
 .Case("vectorcall", LangOptions::DCC_VectorCall)
+.Case("regcall", LangOptions::DCC_RegCall)
 .Default(LangOptions::DCC_None);
 if (DefaultCC == LangOptions::DCC_None)
   Diags.Report(diag::err_drv_invalid_value)
@@ -2315,7 +2315,8 @@
 bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
   DefaultCC == LangOptions::DCC_StdCall) &&
  Arch != llvm::Triple::x86;
-emitError |= DefaultCC == LangOptions::DCC_VectorCall &&
+emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||
+  DefaultCC == LangOptions::DCC_RegCall) &&
  !(Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64);
 if (emitError)
   Diags.Report(diag::err_drv_argument_not_allow

[PATCH] D51545: Enable -Wtautological-unsigned-zero-compare under -Wextra

2018-08-31 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: lebedev.ri, rsmith, rjmccall, rnk, mclow.lists, 
erichkeane.

GCC enables -Wtype-limits under -Wextra. Warnings under GCC's -Wtype-limits is 
covered in Clang by -Wtautological-type-limit-compare and 
-Wtautological-unsigned-zero-compare.

Since -Wtautological-type-limit-compare can fire spuriously when a type's size 
is platform-dependent (as detailed in D41512 
), I am adding only 
-Wtautological-unsigned-zero-compare to -Wextra.

I should point out that GCC does not throw warnings on pointless unsigned 
expression comparisons inside templates while 
-Wtautological-unsigned-zero-compare does. I figure this is a limitation in 
GCC's implementation and don't think this is an issue but please feel free to 
let me know if I am mistaken.


https://reviews.llvm.org/D51545

Files:
  include/clang/Basic/DiagnosticGroups.td
  test/Sema/tautological-unsigned-zero-compare.c


Index: test/Sema/tautological-unsigned-zero-compare.c
===
--- test/Sema/tautological-unsigned-zero-compare.c
+++ test/Sema/tautological-unsigned-zero-compare.c
@@ -8,6 +8,12 @@
 // RUN:-verify -x c++ %s
 // RUN: %clang_cc1 -fsyntax-only \
 // RUN:-verify=silence -x c++ %s
+// RUN: %clang_cc1 -fsyntax-only \
+// RUN:-Wextra -Wno-sign-compare\
+// RUN:-verify %s
+// RUN: %clang_cc1 -fsyntax-only \
+// RUN:-Wextra -Wno-sign-compare\
+// RUN:-verify -x c++ %s
 
 unsigned uvalue(void);
 signed int svalue(void);
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -763,7 +763,8 @@
 MissingMethodReturnType,
 SignCompare,
 UnusedParameter,
-NullPointerArithmetic
+NullPointerArithmetic,
+TautologicalUnsignedZeroCompare
   ]>;
 
 def Most : DiagGroup<"most", [


Index: test/Sema/tautological-unsigned-zero-compare.c
===
--- test/Sema/tautological-unsigned-zero-compare.c
+++ test/Sema/tautological-unsigned-zero-compare.c
@@ -8,6 +8,12 @@
 // RUN:-verify -x c++ %s
 // RUN: %clang_cc1 -fsyntax-only \
 // RUN:-verify=silence -x c++ %s
+// RUN: %clang_cc1 -fsyntax-only \
+// RUN:-Wextra -Wno-sign-compare\
+// RUN:-verify %s
+// RUN: %clang_cc1 -fsyntax-only \
+// RUN:-Wextra -Wno-sign-compare\
+// RUN:-verify -x c++ %s
 
 unsigned uvalue(void);
 signed int svalue(void);
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -763,7 +763,8 @@
 MissingMethodReturnType,
 SignCompare,
 UnusedParameter,
-NullPointerArithmetic
+NullPointerArithmetic,
+TautologicalUnsignedZeroCompare
   ]>;
 
 def Most : DiagGroup<"most", [
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51545: Enable -Wtautological-unsigned-zero-compare under -Wextra

2018-08-31 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

@lebedev.ri is there a specific reason -Wtautological-unsigned-zero-compare was 
removed? All the issues I am aware of talks about comparisons with min/max.


https://reviews.llvm.org/D51545



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


[PATCH] D51545: Enable -Wtautological-unsigned-zero-compare under -Wextra

2018-09-04 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Alright. Thanks for the review. I will abandon this patch


https://reviews.llvm.org/D51545



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


[PATCH] D43259: Implement function attribute artificial

2018-02-13 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: erichkeane, aaron.ballman.

Added support in clang for GCC function attribute 'artificial'. This attribute 
is used to control stepping behavior of debugger with respect to inline 
functions.


https://reviews.llvm.org/D43259

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/CGDebugInfo.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/artificial.c
  test/Sema/artificial.c


Index: test/Sema/artificial.c
===
--- /dev/null
+++ test/Sema/artificial.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void __attribute__((artificial)) bar() {} // expected-warning {{'artificial' 
attribute only applies to inline functions}}
Index: test/CodeGen/artificial.c
===
--- /dev/null
+++ test/CodeGen/artificial.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s
+
+extern void foo();
+// CHECK: !DISubprogram(name: "foo"
+// CHECK-SAME: flags: DIFlagArtificial
+inline void __attribute__((artificial)) foo() {}
+
+void baz() {
+  foo();
+}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6057,6 +6057,9 @@
   case AttributeList::AT_AlwaysInline:
 handleAlwaysInlineAttr(S, D, Attr);
 break;
+  case AttributeList::AT_Artificial:
+handleSimpleAttribute(S, D, Attr);
+break;
   case AttributeList::AT_AnalyzerNoReturn:
 handleAnalyzerNoReturnAttr(S, D, Attr);
 break;
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3229,7 +3229,7 @@
   if (Name.startswith("\01"))
 Name = Name.substr(1);
 
-  if (!HasDecl || D->isImplicit()) {
+  if (!HasDecl || D->isImplicit() || D->hasAttr()) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -3273,3 +3273,13 @@
 or `msvc documentation `_.
 }];
 }
+
+def ArtificialDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``artificial`` attribute is used with inline functions to treat the inline 
+function as a unit while debugging. For more information see GCC_ 
documentation.
+
+.. _GCC: https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Function-Attributes.html
+  }];
+}
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -111,6 +111,9 @@
 def GlobalVar : SubsetSubjecthasGlobalStorage()}], "global variables">;
 
+def InlineFunction : SubsetSubjectisInlineSpecified()}], "inline functions">;
+
 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node
 // type to be a class, not a definition. This makes it impossible to create an
 // attribute subject which accepts a Decl. Normally, this is not a problem,
@@ -588,6 +591,12 @@
   let Documentation = [Undocumented];
 }
 
+def Artificial : InheritableAttr {
+  let Spellings = [GCC<"artificial">];
+  let Subjects = SubjectList<[InlineFunction], WarnDiag>;
+  let Documentation = [ArtificialDocs];
+}
+
 def XRayInstrument : InheritableAttr {
   let Spellings = [Clang<"xray_always_instrument">,
Clang<"xray_never_instrument">];


Index: test/Sema/artificial.c
===
--- /dev/null
+++ test/Sema/artificial.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void __attribute__((artificial)) bar() {} // expected-warning {{'artificial' attribute only applies to inline functions}}
Index: test/CodeGen/artificial.c
===
--- /dev/null
+++ test/CodeGen/artificial.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+extern void foo();
+// CHECK: !DISubprogram(name: "foo"
+// CHECK-SAME: flags: DIFlagArtificial
+inline void __attribute__((artificial)) foo() {}
+
+void baz() {
+  foo();
+}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6057,6 +6057,9 @@
   case AttributeList::AT_AlwaysInline:
 handleAlwaysInlineAttr(S, D, Attr);
 break;
+  case AttributeList::AT_Artificial:
+handleSimpleAttribute(S, D, Attr);
+break;
   case AttributeList::AT_AnalyzerNoReturn:
   

[PATCH] D40925: Add option -fkeep-static-consts

2018-02-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

I think we can use CodeGenModule::addUsedGlobal for this purpose. I noticed 
this is what attribute 'used' calls. I need to look into it though.


https://reviews.llvm.org/D40925



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


[PATCH] D43321: Improve documentation for attribute artificial

2018-02-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: rsmith, aaron.ballman, erichkeane.

This patch is related to https://reviews.llvm.org/rC325081

The patch improves documentation for the attribute and removes reference to GCC 
documentation.


https://reviews.llvm.org/D43321

Files:
  include/clang/Basic/AttrDocs.td


Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -3277,9 +3277,9 @@
 def ArtificialDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
-The ``artificial`` attribute is used with inline functions to treat the inline 
-function as a unit while debugging. For more information see GCC_ 
documentation.
-
-.. _GCC: https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Function-Attributes.html
+The ``artificial`` attribute can be applied to an inline function. If such a
+function is inlined, the attribute indicates that debuggers should associate
+the resulting instructions with the call site, rather than with the 
+corresponding line within the inlined callee.
   }];
 }


Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -3277,9 +3277,9 @@
 def ArtificialDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
-The ``artificial`` attribute is used with inline functions to treat the inline 
-function as a unit while debugging. For more information see GCC_ documentation.
-
-.. _GCC: https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Function-Attributes.html
+The ``artificial`` attribute can be applied to an inline function. If such a
+function is inlined, the attribute indicates that debuggers should associate
+the resulting instructions with the call site, rather than with the 
+corresponding line within the inlined callee.
   }];
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40925: Add option -fkeep-static-consts

2018-01-10 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Thanks for the review Reid. Sorry for the delay in my response. I was OOO.

I am not sure if a new attribute is necessary. __ attribute __(used) is already 
supported in Clang. While this attribute can be used to retain static 
constants, it would require the user to modify the source which may not always 
be possible/practical. Its also interesting to note that GCC actually retains 
unused static constants by default.  fno-keep-static-consts is used to remove 
unused static constants in GCC.


https://reviews.llvm.org/D40925



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


[PATCH] D52998: [benchmark] Disable exceptions in Microsoft STL

2018-10-09 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Yes. I understand. At the moment, exception handling flags are generated based 
on `BENCHMARK_ENABLE_EXCEPTIONS`  in `utils/benchmark/CMakeLists.txt` .  
However, `_HAS_EXCEPTIONS` is not defined based on this (code below). The 
warnings are a result of this mismatch.

  if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
  add_cxx_compiler_flag(-EHs-)
  add_cxx_compiler_flag(-EHa-)
endif()

I think it makes most sense to add definition for `_HAS_EXCEPTIONS=0 `here as 
opposed to modifying `llvm/CMakeLists.txt`.  Please correct me if I'm wrong. 
I'm not too familiar with CMake. @kbobyrev Please let me know what you think as 
well since you had suggested `llvm/CMakeLists.txt`.


https://reviews.llvm.org/D52998



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


[PATCH] D40925: Add option -fkeep-static-consts

2018-10-25 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

I think it makes sense to include this case just to make the flag more 
complete. Also, we don't really match GCC behavior for this flag. GCC emits all 
static constants by default (when O0). When optimized, this flag has no effect 
on GCC.  The negation is used to not emit the constants.

Erich has uploaded a possible fix here - https://reviews.llvm.org/D53718


Repository:
  rC Clang

https://reviews.llvm.org/D40925



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


[PATCH] D52998: [benchmark] Disable exceptions in Microsoft STL

2018-10-29 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In https://reviews.llvm.org/D52998#1259602, @lebedev.ri wrote:

> In https://reviews.llvm.org/D52998#1258962, @eandrews wrote:
>
> > Yes. I understand. At the moment, exception handling flags are generated 
> > based on `BENCHMARK_ENABLE_EXCEPTIONS`  in `utils/benchmark/CMakeLists.txt` 
> > .  However, `_HAS_EXCEPTIONS` is not defined based on this (code below). 
> > The warnings are a result of this mismatch.
> >
> >   if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
> >   add_cxx_compiler_flag(-EHs-)
> >   add_cxx_compiler_flag(-EHa-)
> > endif()
> >
> >
> > I think it makes most sense to add definition for `_HAS_EXCEPTIONS=0 `here 
> > as opposed to modifying `llvm/CMakeLists.txt`.
>
>
> Then i'd recommend/suggest to submit this upstream 
>  first.
>
> > Please correct me if I'm wrong. I'm not too familiar with CMake. @kbobyrev 
> > Please let me know what you think as well since you had suggested 
> > `llvm/CMakeLists.txt`.


@kbobyrev Is this alright with you?


https://reviews.llvm.org/D52998



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


[PATCH] D52998: [benchmark] Disable exceptions in Microsoft STL

2018-11-01 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 172171.
eandrews added a comment.

@kbobyrev  I apologize if I was unclear in the comments. I was asking if the 
changes proposed in the comments are alright with you since they would involve 
modifying `benchmark/CMakelists.txt` (instead of `llvm/CMakeLists.txt` as 
discussed in mailing list). As Zachary mentioned in comments, `_HAS_EXCEPTIONS` 
should be set to 0 only when exceptions are disabled. Since exception handling 
for benchmarks is handled in `benchmark/CMakeLists.txt`, I think it makes most 
sense to add the definition there. I have now uploaded the proposed change for 
review.

I am still working with my company to figure out the corporate CLA Google's 
benchmark project requires for patch submissions. I can submit the patch 
upstream once that is done. If you would prefer to submit the patch upstream 
yourself, please feel free to do so.

Sorry again for the confusion!


https://reviews.llvm.org/D52998

Files:
  utils/benchmark/CMakeLists.txt


Index: utils/benchmark/CMakeLists.txt
===
--- utils/benchmark/CMakeLists.txt
+++ utils/benchmark/CMakeLists.txt
@@ -99,6 +99,7 @@
   if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
 add_cxx_compiler_flag(-EHs-)
 add_cxx_compiler_flag(-EHa-)
+add_definitions(-D_HAS_EXCEPTIONS=0)
   endif()
   # Link time optimisation
   if (BENCHMARK_ENABLE_LTO)


Index: utils/benchmark/CMakeLists.txt
===
--- utils/benchmark/CMakeLists.txt
+++ utils/benchmark/CMakeLists.txt
@@ -99,6 +99,7 @@
   if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
 add_cxx_compiler_flag(-EHs-)
 add_cxx_compiler_flag(-EHa-)
+add_definitions(-D_HAS_EXCEPTIONS=0)
   endif()
   # Link time optimisation
   if (BENCHMARK_ENABLE_LTO)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52998: [benchmark] Disable exceptions in Microsoft STL

2018-11-01 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

> Upstreaming it first might be better, especially since the change seems to be 
> trivial. Is this line addition the only change proposed for the benchmark 
> library?

Yes this line is the only change.

> Do you want me to submit the patch to the benchmark library? It seems that it 
> would help to speedup the process.

That would be helpful. Thank you!


https://reviews.llvm.org/D52998



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


[PATCH] D52998: [benchmark] Disable exceptions in Microsoft STL

2018-11-02 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Thanks!


https://reviews.llvm.org/D52998



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


[PATCH] D52998: [benchmark] Disable exceptions in Microsoft STL

2018-11-06 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL346237: [benchmark] Disable exceptions in Microsoft STL 
(authored by eandrews, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D52998?vs=172171&id=172769#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52998

Files:
  llvm/trunk/utils/benchmark/CMakeLists.txt
  llvm/trunk/utils/benchmark/README.LLVM


Index: llvm/trunk/utils/benchmark/CMakeLists.txt
===
--- llvm/trunk/utils/benchmark/CMakeLists.txt
+++ llvm/trunk/utils/benchmark/CMakeLists.txt
@@ -99,6 +99,7 @@
   if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
 add_cxx_compiler_flag(-EHs-)
 add_cxx_compiler_flag(-EHa-)
+add_definitions(-D_HAS_EXCEPTIONS=0)
   endif()
   # Link time optimisation
   if (BENCHMARK_ENABLE_LTO)
Index: llvm/trunk/utils/benchmark/README.LLVM
===
--- llvm/trunk/utils/benchmark/README.LLVM
+++ llvm/trunk/utils/benchmark/README.LLVM
@@ -19,3 +19,5 @@
   is applied to fix cross compilation with MinGW headers
 * 
https://github.com/google/benchmark/commit/439d6b1c2a6da5cb6adc4c4dfc555af235722396
   is applied to fix building with MinGW headers for ARM
+* 
https://github.com/google/benchmark/commit/a9b31c51b1ee7ec7b31438c647123c2cbac5d956
+  is applied to disable exceptions in Microsoft STL when exceptions are 
disabled


Index: llvm/trunk/utils/benchmark/CMakeLists.txt
===
--- llvm/trunk/utils/benchmark/CMakeLists.txt
+++ llvm/trunk/utils/benchmark/CMakeLists.txt
@@ -99,6 +99,7 @@
   if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
 add_cxx_compiler_flag(-EHs-)
 add_cxx_compiler_flag(-EHa-)
+add_definitions(-D_HAS_EXCEPTIONS=0)
   endif()
   # Link time optimisation
   if (BENCHMARK_ENABLE_LTO)
Index: llvm/trunk/utils/benchmark/README.LLVM
===
--- llvm/trunk/utils/benchmark/README.LLVM
+++ llvm/trunk/utils/benchmark/README.LLVM
@@ -19,3 +19,5 @@
   is applied to fix cross compilation with MinGW headers
 * https://github.com/google/benchmark/commit/439d6b1c2a6da5cb6adc4c4dfc555af235722396
   is applied to fix building with MinGW headers for ARM
+* https://github.com/google/benchmark/commit/a9b31c51b1ee7ec7b31438c647123c2cbac5d956
+  is applied to disable exceptions in Microsoft STL when exceptions are disabled
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61023: Fix crash on switch conditions of non-integer types in templates

2019-04-23 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: rnk, erichkeane.

Clang currently crashes for switch statements inside a template when the 
condition is non-integer and instantiation dependent. This is because 
contextual implicit conversion is skipped while acting on switch condition but 
this conversion is checked in an assert when acting on case statement.

This patch delays checks for dependent expressions till instantiation. Behavior 
now matches GCC.

Patch fixes Bug 40982.


https://reviews.llvm.org/D61023

Files:
  lib/Sema/SemaStmt.cpp
  test/SemaTemplate/non-integral-switch-cond.cpp


Index: test/SemaTemplate/non-integral-switch-cond.cpp
===
--- /dev/null
+++ test/SemaTemplate/non-integral-switch-cond.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct NOT_AN_INTEGRAL_TYPE {};
+
+template 
+struct foo {
+  NOT_AN_INTEGRAL_TYPE Bad;
+  void run() {
+switch (Bad) { // expected-error {{statement requires expression of 
integer type ('NOT_AN_INTEGRAL_TYPE' invalid)}}
+case 0:
+  break;
+}
+  }
+};
+
+int main() {
+  foo instance;
+  instance.run(); // expected-note {{in instantiation of member function 
'foo::run' requested here}}
+}
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -404,7 +404,8 @@
 QualType CondType = CondExpr->getType();
 
 auto CheckAndFinish = [&](Expr *E) {
-  if (CondType->isDependentType() || E->isTypeDependent())
+  if (CondType->isDependentType() || CondExpr->isInstantiationDependent() 
||
+  E->isTypeDependent())
 return ExprResult(E);
 
   if (getLangOpts().CPlusPlus11) {
@@ -695,7 +696,8 @@
   Expr *CondExpr = Cond.get().second;
   assert((Cond.isInvalid() || CondExpr) && "switch with no condition");
 
-  if (CondExpr && !CondExpr->isTypeDependent()) {
+  if (CondExpr && !CondExpr->isTypeDependent() &&
+  !CondExpr->isInstantiationDependent()) {
 // We have already converted the expression to an integral or enumeration
 // type, when we parsed the switch condition. If we don't have an
 // appropriate type now, enter the switch scope but remember that it's


Index: test/SemaTemplate/non-integral-switch-cond.cpp
===
--- /dev/null
+++ test/SemaTemplate/non-integral-switch-cond.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct NOT_AN_INTEGRAL_TYPE {};
+
+template 
+struct foo {
+  NOT_AN_INTEGRAL_TYPE Bad;
+  void run() {
+switch (Bad) { // expected-error {{statement requires expression of integer type ('NOT_AN_INTEGRAL_TYPE' invalid)}}
+case 0:
+  break;
+}
+  }
+};
+
+int main() {
+  foo instance;
+  instance.run(); // expected-note {{in instantiation of member function 'foo::run' requested here}}
+}
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -404,7 +404,8 @@
 QualType CondType = CondExpr->getType();
 
 auto CheckAndFinish = [&](Expr *E) {
-  if (CondType->isDependentType() || E->isTypeDependent())
+  if (CondType->isDependentType() || CondExpr->isInstantiationDependent() ||
+  E->isTypeDependent())
 return ExprResult(E);
 
   if (getLangOpts().CPlusPlus11) {
@@ -695,7 +696,8 @@
   Expr *CondExpr = Cond.get().second;
   assert((Cond.isInvalid() || CondExpr) && "switch with no condition");
 
-  if (CondExpr && !CondExpr->isTypeDependent()) {
+  if (CondExpr && !CondExpr->isTypeDependent() &&
+  !CondExpr->isInstantiationDependent()) {
 // We have already converted the expression to an integral or enumeration
 // type, when we parsed the switch condition. If we don't have an
 // appropriate type now, enter the switch scope but remember that it's
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61027: Fix crash on switch conditions of non-integer types in templates

2019-04-23 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: rnk, riccibruno, erichkeane.

Clang currently crashes for switch statements inside a template when the 
condition is non-integer and instantiation dependent. This is because 
contextual implicit conversion is skipped while acting on switch condition but 
this conversion is checked in an assert when acting on case statement.

This patch delays checks for dependent expressions till instantiation. Behavior 
now matches GCC.

Patch fixes Bug 40982.


https://reviews.llvm.org/D61027

Files:
  lib/Sema/SemaStmt.cpp
  test/SemaTemplate/non-integral-switch-cond.cpp


Index: test/SemaTemplate/non-integral-switch-cond.cpp
===
--- /dev/null
+++ test/SemaTemplate/non-integral-switch-cond.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct NOT_AN_INTEGRAL_TYPE {};
+
+template 
+struct foo {
+  NOT_AN_INTEGRAL_TYPE Bad;
+  void run() {
+switch (Bad) { // expected-error {{statement requires expression of 
integer type ('NOT_AN_INTEGRAL_TYPE' invalid)}}
+case 0:
+  break;
+}
+  }
+};
+
+int main() {
+  foo instance;
+  instance.run(); // expected-note {{in instantiation of member function 
'foo::run' requested here}}
+}
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -399,7 +399,8 @@
 QualType CondType = CondExpr->getType();
 
 auto CheckAndFinish = [&](Expr *E) {
-  if (CondType->isDependentType() || E->isTypeDependent())
+  if (CondType->isDependentType() || CondExpr->isInstantiationDependent() 
||
+  E->isTypeDependent())
 return ExprResult(E);
 
   if (getLangOpts().CPlusPlus11) {
@@ -690,7 +691,8 @@
   Expr *CondExpr = Cond.get().second;
   assert((Cond.isInvalid() || CondExpr) && "switch with no condition");
 
-  if (CondExpr && !CondExpr->isTypeDependent()) {
+  if (CondExpr && !CondExpr->isTypeDependent() &&
+  !CondExpr->isInstantiationDependent()) {
 // We have already converted the expression to an integral or enumeration
 // type, when we parsed the switch condition. If we don't have an
 // appropriate type now, enter the switch scope but remember that it's


Index: test/SemaTemplate/non-integral-switch-cond.cpp
===
--- /dev/null
+++ test/SemaTemplate/non-integral-switch-cond.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct NOT_AN_INTEGRAL_TYPE {};
+
+template 
+struct foo {
+  NOT_AN_INTEGRAL_TYPE Bad;
+  void run() {
+switch (Bad) { // expected-error {{statement requires expression of integer type ('NOT_AN_INTEGRAL_TYPE' invalid)}}
+case 0:
+  break;
+}
+  }
+};
+
+int main() {
+  foo instance;
+  instance.run(); // expected-note {{in instantiation of member function 'foo::run' requested here}}
+}
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -399,7 +399,8 @@
 QualType CondType = CondExpr->getType();
 
 auto CheckAndFinish = [&](Expr *E) {
-  if (CondType->isDependentType() || E->isTypeDependent())
+  if (CondType->isDependentType() || CondExpr->isInstantiationDependent() ||
+  E->isTypeDependent())
 return ExprResult(E);
 
   if (getLangOpts().CPlusPlus11) {
@@ -690,7 +691,8 @@
   Expr *CondExpr = Cond.get().second;
   assert((Cond.isInvalid() || CondExpr) && "switch with no condition");
 
-  if (CondExpr && !CondExpr->isTypeDependent()) {
+  if (CondExpr && !CondExpr->isTypeDependent() &&
+  !CondExpr->isInstantiationDependent()) {
 // We have already converted the expression to an integral or enumeration
 // type, when we parsed the switch condition. If we don't have an
 // appropriate type now, enter the switch scope but remember that it's
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61027: Fix crash on switch conditions of non-integer types in templates

2019-04-23 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

I apologize for the confusion. I was working on an incorrect branch earlier, 
and so abandoned that patch and uploaded a new revision.


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

https://reviews.llvm.org/D61027



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


[PATCH] D61027: Fix crash on switch conditions of non-integer types in templates

2019-04-24 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

I ran the test you provided and it does throw errors without instantiation

  bash-4.2$ clang -cc1 test/SemaTemplate/test2.cpp
  test/SemaTemplate/test2.cpp:3:7: error: statement requires expression of 
integer type ('int *' invalid)
switch (N) case 0:; // should be diagnosed
^   ~
  test/SemaTemplate/test2.cpp:4:23: error: value of type 'int *' is not 
implicitly convertible to 'int'
switch (0) case N:; // should be diagnosed
^
  test/SemaTemplate/test2.cpp:4:25: warning: switch statement has empty body
switch (0) case N:; // should be diagnosed
  ^
  test/SemaTemplate/test2.cpp:4:25: note: put the semicolon on a separate line 
to silence this warning
  1 warning and 2 errors generated.

However, I am surprised it does since I expected it not to :) For example the 
lit test in this patch will not throw an error without the instantiation. I 
need to debug this further to understand what's happening.  Thanks for taking a 
look!


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

https://reviews.llvm.org/D61027



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


[PATCH] D52998: [benchmark] Disable exceptions in Microsoft STL

2018-10-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: rnk, kbobyrev, omtcyfz, lebedev.ri, erichkeane.
Herald added a subscriber: mgorny.

Define _HAS_EXCEPTIONS=0, when compiling benchmark files, to disable exceptions 
in Microsoft STL.

Windows builds were failing due to C4530 warnings (C++ exception handler used, 
but unwind semantics are not enabled) thrown by MSVC standard library.


https://reviews.llvm.org/D52998

Files:
  CMakeLists.txt


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -1089,7 +1089,8 @@
   set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable Google Test in 
benchmark" FORCE)
   # Since LLVM requires C++11 it is safe to assume that std::regex is 
available.
   set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE)
-
+  # Disable exceptions in Microsoft STL to prevent warnings about exception 
handlers in STL.
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_HAS_EXCEPTIONS=0")
   add_subdirectory(utils/benchmark)
   add_subdirectory(benchmarks)
 endif()


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -1089,7 +1089,8 @@
   set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable Google Test in benchmark" FORCE)
   # Since LLVM requires C++11 it is safe to assume that std::regex is available.
   set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE)
-
+  # Disable exceptions in Microsoft STL to prevent warnings about exception handlers in STL.
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_HAS_EXCEPTIONS=0")
   add_subdirectory(utils/benchmark)
   add_subdirectory(benchmarks)
 endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52998: [benchmark] Disable exceptions in Microsoft STL

2018-10-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

I do not think defining _HAS_EXCEPTIONS=0 affects C++ exceptions in the 
application. I thought it only affected the STL. I will verify this and update 
you.


https://reviews.llvm.org/D52998



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


[PATCH] D52998: [benchmark] Disable exceptions in Microsoft STL

2018-10-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Thanks for the information Zachary.

@lebedev.ri  I do not know how benchmark library developers need/want to handle 
exceptions in MSVC STL.  If these need to be enabled when 
BENCHMARK_ENABLE_EXCEPTIONS is true,  I think we can just modify 
_HAS_EXCEPTIONS in utils/benchmark/CMakeLists.txt.


https://reviews.llvm.org/D52998



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


[PATCH] D36487: Emit section information for extern variables.

2017-08-28 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

*ping*


https://reviews.llvm.org/D36487



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


[PATCH] D36487: Emit section information for extern variables.

2017-09-21 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 116211.
eandrews added a comment.

I've updated the patch based on review comments. The changes include setting 
section unconditionally for extern variables and emitting a warning if section 
attribute is specified on a redeclaration.


https://reviews.llvm.org/D36487

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGenCXX/extern-section-attribute.cpp
  test/Sema/attr-section.c


Index: test/Sema/attr-section.c
===
--- test/Sema/attr-section.c
+++ test/Sema/attr-section.c
@@ -19,3 +19,7 @@
 void __attribute__((section("bar,zed"))) test2(void) {} // expected-warning 
{{section does not match previous declaration}}
 
 enum __attribute__((section("NEAR,x"))) e { one }; // expected-error 
{{'section' attribute only applies to functions, methods, properties, and 
global variables}}
+
+extern int a; // expected-note {{previous declaration is here}}
+int *b = &a;
+extern int a __attribute__((section("foo,zed"))); // expected-warning 
{{section attribute is specified on redeclared variable}}
Index: test/CodeGenCXX/extern-section-attribute.cpp
===
--- /dev/null
+++ test/CodeGenCXX/extern-section-attribute.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux-gnu | FileCheck 
%s
+
+extern int aa __attribute__((section(".sdata")));
+// CHECK-DAG: @aa = external global i32, section ".sdata", align 4
+
+extern int bb __attribute__((section(".sdata"))) = 1;
+// CHECK-DAG: @bb = global i32 1, section ".sdata", align 4
+
+int foo() {
+  return aa + bb;
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2607,6 +2607,14 @@
 }
   }
 
+  // This redeclaration adds a section attribute to a declaration that has
+  // already been ODR-used.
+  if (New->hasAttr() && !Old->hasAttr() &&
+  Old->isUsed()) {
+Diag(New->getLocation(), diag::warn_attribute_section_on_redeclaration);
+Diag(Old->getLocation(), diag::note_previous_declaration);
+  }
+
   if (!Old->hasAttrs())
 return;
 
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2431,6 +2431,12 @@
   EmitGlobalVarDefinition(D);
 }
 
+// Emit section information for extern variables.
+if (D->hasExternalStorage()) {
+  if (const SectionAttr *SA = D->getAttr())
+GV->setSection(SA->getName());
+}
+
 // Handle XCore specific ABI requirements.
 if (getTriple().getArch() == llvm::Triple::xcore &&
 D->getLanguageLinkage() == CLanguageLinkage &&
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -2611,6 +2611,8 @@
   "argument to 'section' attribute is not valid for this target: %0">;
 def warn_mismatched_section : Warning<
   "section does not match previous declaration">, InGroup;
+def warn_attribute_section_on_redeclaration : Warning<
+  "section attribute is specified on redeclared variable">, InGroup;
 
 def err_anonymous_property: Error<
   "anonymous property is not supported">;


Index: test/Sema/attr-section.c
===
--- test/Sema/attr-section.c
+++ test/Sema/attr-section.c
@@ -19,3 +19,7 @@
 void __attribute__((section("bar,zed"))) test2(void) {} // expected-warning {{section does not match previous declaration}}
 
 enum __attribute__((section("NEAR,x"))) e { one }; // expected-error {{'section' attribute only applies to functions, methods, properties, and global variables}}
+
+extern int a; // expected-note {{previous declaration is here}}
+int *b = &a;
+extern int a __attribute__((section("foo,zed"))); // expected-warning {{section attribute is specified on redeclared variable}}
Index: test/CodeGenCXX/extern-section-attribute.cpp
===
--- /dev/null
+++ test/CodeGenCXX/extern-section-attribute.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux-gnu | FileCheck %s
+
+extern int aa __attribute__((section(".sdata")));
+// CHECK-DAG: @aa = external global i32, section ".sdata", align 4
+
+extern int bb __attribute__((section(".sdata"))) = 1;
+// CHECK-DAG: @bb = global i32 1, section ".sdata", align 4
+
+int foo() {
+  return aa + bb;
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2607,6 +2607,14 @@
 }
   }
 
+  // This redeclaration adds a section attribute to a declaration that has
+  // already bee

[PATCH] D36487: Emit section information for extern variables.

2017-09-21 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added inline comments.



Comment at: lib/CodeGen/CodeGenModule.cpp:2434
+// Emit section information for extern variables.
+if (D->hasExternalStorage() && !D->isThisDeclarationADefinition()) {
+  if (const SectionAttr *SA = D->getAttr())

efriedma wrote:
> eandrews wrote:
> > efriedma wrote:
> > > Why do you specifically check "D->hasExternalStorage() && 
> > > !D->isThisDeclarationADefinition()", instead of just setting the section 
> > > unconditionally?
> > I noticed that you enter GetOrCreateLLVMGlobal( ) whenever the extern 
> > variable is declared as well as when it is defined. The flow of the program 
> > is different in each case. When the variable is defined, it also enters 
> > EmitGlobalVarDefinition( ). There is existing code handling section 
> > information here. I added the check in GetOrCreateLLVMGlobal( ) so the 
> > block gets skipped for variable definition, since its already handled 
> > elsewhere.
> I would rather just call setSection unconditionally here, as opposed to 
> trying to guess whether the global will eventually be defined.
> 
> I'm also sort of concerned the behavior here could be weird if a section 
> attribute is added on a redeclaration (e.g. what happens if you write `extern 
> int x; int y = &x; extern int x __attribute((section("foo")));`)... maybe we 
> should emit a warning?
@efriedma  I modified the patch to emit a warning in the scenario you 
mentioned. A warning is also emitted for the following - 

```extern int x;  int *y=&x; int x __attribute__((section("foo"))); 
```
I thought it made sense to emit the warning for the latter as well. Should I 
restrict the warning to just redeclarations (without definition) instead?


https://reviews.llvm.org/D36487



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


[PATCH] D61027: Fix crash on switch conditions of non-integer types in templates

2019-06-10 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 203854.
eandrews edited the summary of this revision.
eandrews added a reviewer: rsmith.

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

https://reviews.llvm.org/D61027

Files:
  lib/AST/Expr.cpp
  lib/Sema/SemaChecking.cpp
  test/SemaTemplate/dependent-names.cpp
  test/SemaTemplate/enum-argument.cpp
  test/SemaTemplate/member-access-expr.cpp
  test/SemaTemplate/non-integral-switch-cond.cpp


Index: test/SemaTemplate/non-integral-switch-cond.cpp
===
--- /dev/null
+++ test/SemaTemplate/non-integral-switch-cond.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct NOT_AN_INTEGRAL_TYPE {};
+
+template 
+struct foo {
+  NOT_AN_INTEGRAL_TYPE Bad;
+  void run() {
+switch (Bad) { // expected-error {{statement requires expression of 
integer type ('NOT_AN_INTEGRAL_TYPE' invalid)}}
+case 0:
+  break;
+}
+  }
+};
Index: test/SemaTemplate/member-access-expr.cpp
===
--- test/SemaTemplate/member-access-expr.cpp
+++ test/SemaTemplate/member-access-expr.cpp
@@ -156,7 +156,7 @@
 void get(B **ptr) {
   // It's okay if at some point we figure out how to diagnose this
   // at instantiation time.
-  *ptr = field;
+  *ptr = field; // expected-error {{assigning to 'test6::B *' from 
incompatible type 'test6::A *}}
 }
   };
 }
Index: test/SemaTemplate/enum-argument.cpp
===
--- test/SemaTemplate/enum-argument.cpp
+++ test/SemaTemplate/enum-argument.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 enum Enum { val = 1 };
 template  struct C {
@@ -31,7 +30,7 @@
 unsigned long long bitfield : e0;
 
 void f(int j) {
-  bitfield + j;
+  bitfield + j; // expected-warning {{expression result unused}}
 }
   };
 }
Index: test/SemaTemplate/dependent-names.cpp
===
--- test/SemaTemplate/dependent-names.cpp
+++ test/SemaTemplate/dependent-names.cpp
@@ -273,9 +273,6 @@
   }
   int e[10];
 };
-void g() {
-  S().f(); // expected-note {{here}}
-}
   }
 
   namespace A2 {
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -14125,6 +14125,8 @@
   bool AnyIsPacked = false;
   do {
 QualType BaseType = ME->getBase()->getType();
+if (BaseType->isDependentType())
+  return;
 if (ME->isArrow())
   BaseType = BaseType->getPointeeType();
 RecordDecl *RD = BaseType->getAs()->getDecl();
Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -1560,6 +1560,13 @@
   MemberExpr *E = new (Mem)
   MemberExpr(base, isarrow, OperatorLoc, memberdecl, nameinfo, ty, vk, ok);
 
+  if (!isa(memberdecl)) {
+DeclContext *DC = memberdecl->getDeclContext();
+CXXRecordDecl *RD = dyn_cast(DC);
+if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC))
+  E->setTypeDependent(ty->isDependentType());
+  }
+
   if (hasQualOrFound) {
 // FIXME: Wrong. We should be looking at the member declaration we found.
 if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) {


Index: test/SemaTemplate/non-integral-switch-cond.cpp
===
--- /dev/null
+++ test/SemaTemplate/non-integral-switch-cond.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct NOT_AN_INTEGRAL_TYPE {};
+
+template 
+struct foo {
+  NOT_AN_INTEGRAL_TYPE Bad;
+  void run() {
+switch (Bad) { // expected-error {{statement requires expression of integer type ('NOT_AN_INTEGRAL_TYPE' invalid)}}
+case 0:
+  break;
+}
+  }
+};
Index: test/SemaTemplate/member-access-expr.cpp
===
--- test/SemaTemplate/member-access-expr.cpp
+++ test/SemaTemplate/member-access-expr.cpp
@@ -156,7 +156,7 @@
 void get(B **ptr) {
   // It's okay if at some point we figure out how to diagnose this
   // at instantiation time.
-  *ptr = field;
+  *ptr = field; // expected-error {{assigning to 'test6::B *' from incompatible type 'test6::A *}}
 }
   };
 }
Index: test/SemaTemplate/enum-argument.cpp
===
--- test/SemaTemplate/enum-argument.cpp
+++ test/SemaTemplate/enum-argument.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 enum Enum { val = 1 };
 template  struct C {
@@ -31,7 +30,7 @@
 unsigned long long bitfield : e0;
 
 void f(int j) {
-  bitfield + j;
+  bitfield + j; // expected-warning {{expression result unused

[PATCH] D61027: Fix crash on switch conditions of non-integer types in templates

2019-07-17 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

ping

I just realized I modified the summary when I uploaded a new patch, but did not 
add a comment about the changes I made. Based on feedback from the bug report 
(https://bugs.llvm.org/show_bug.cgi?id=40982), I changed my approach for this 
crash. This patch changes the type dependency of the member which causes the 
crash.

Currently, when member expressions are created, their type dependency is set 
based on the class it is part of and not its own type.  I don't quite 
understand why, and changing it broke a whole lot of lit tests. So, in this 
patch I only attempted to modify the type-dependency of 'members of current 
instantiation' to set it based on it's type as opposed to the containing 
classes' type.


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

https://reviews.llvm.org/D61027



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


[PATCH] D61027: Fix crash on switch conditions of non-integer types in templates

2019-07-29 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

ping


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

https://reviews.llvm.org/D61027



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


[PATCH] D61027: Fix crash on switch conditions of non-integer types in templates

2019-08-07 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Thanks for taking a look Reid! I rebased the patch and had a conflict with one 
of Richard's patches  and so ran the lit tests again and noticed there are 
several new failures. I am taking a look at those now.


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

https://reviews.llvm.org/D61027



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


[PATCH] D61027: Fix crash on switch conditions of non-integer types in templates

2019-08-13 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368706: Fix crash on switch conditions of non-integer types 
in templates (authored by eandrews, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61027?vs=203854&id=214847#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61027

Files:
  cfe/trunk/lib/AST/Expr.cpp
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/SemaTemplate/dependent-names.cpp
  cfe/trunk/test/SemaTemplate/enum-argument.cpp
  cfe/trunk/test/SemaTemplate/member-access-expr.cpp
  cfe/trunk/test/SemaTemplate/non-integral-switch-cond.cpp


Index: cfe/trunk/test/SemaTemplate/enum-argument.cpp
===
--- cfe/trunk/test/SemaTemplate/enum-argument.cpp
+++ cfe/trunk/test/SemaTemplate/enum-argument.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 enum Enum { val = 1 };
 template  struct C {
@@ -31,7 +30,7 @@
 unsigned long long bitfield : e0;
 
 void f(int j) {
-  bitfield + j;
+  bitfield + j; // expected-warning {{expression result unused}}
 }
   };
 }
Index: cfe/trunk/test/SemaTemplate/member-access-expr.cpp
===
--- cfe/trunk/test/SemaTemplate/member-access-expr.cpp
+++ cfe/trunk/test/SemaTemplate/member-access-expr.cpp
@@ -156,7 +156,7 @@
 void get(B **ptr) {
   // It's okay if at some point we figure out how to diagnose this
   // at instantiation time.
-  *ptr = field;
+  *ptr = field; // expected-error {{assigning to 'test6::B *' from 
incompatible type 'test6::A *}}
 }
   };
 }
Index: cfe/trunk/test/SemaTemplate/non-integral-switch-cond.cpp
===
--- cfe/trunk/test/SemaTemplate/non-integral-switch-cond.cpp
+++ cfe/trunk/test/SemaTemplate/non-integral-switch-cond.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct NOT_AN_INTEGRAL_TYPE {};
+
+template 
+struct foo {
+  NOT_AN_INTEGRAL_TYPE Bad;
+  void run() {
+switch (Bad) { // expected-error {{statement requires expression of 
integer type ('NOT_AN_INTEGRAL_TYPE' invalid)}}
+case 0:
+  break;
+}
+  }
+};
Index: cfe/trunk/test/SemaTemplate/dependent-names.cpp
===
--- cfe/trunk/test/SemaTemplate/dependent-names.cpp
+++ cfe/trunk/test/SemaTemplate/dependent-names.cpp
@@ -273,9 +273,6 @@
   }
   int e[10];
 };
-void g() {
-  S().f(); // expected-note {{here}}
-}
   }
 
   namespace A2 {
Index: cfe/trunk/lib/AST/Expr.cpp
===
--- cfe/trunk/lib/AST/Expr.cpp
+++ cfe/trunk/lib/AST/Expr.cpp
@@ -1669,6 +1669,15 @@
   MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl,
NameInfo, T, VK, OK, NOUR);
 
+  if (FieldDecl *Field = dyn_cast(MemberDecl)) {
+DeclContext *DC = MemberDecl->getDeclContext();
+// dyn_cast_or_null is used to handle objC variables which do not
+// have a declaration context.
+CXXRecordDecl *RD = dyn_cast_or_null(DC);
+if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC))
+  E->setTypeDependent(T->isDependentType());
+  }
+
   if (HasQualOrFound) {
 // FIXME: Wrong. We should be looking at the member declaration we found.
 if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -14288,6 +14288,8 @@
   bool AnyIsPacked = false;
   do {
 QualType BaseType = ME->getBase()->getType();
+if (BaseType->isDependentType())
+  return;
 if (ME->isArrow())
   BaseType = BaseType->getPointeeType();
 RecordDecl *RD = BaseType->getAs()->getDecl();


Index: cfe/trunk/test/SemaTemplate/enum-argument.cpp
===
--- cfe/trunk/test/SemaTemplate/enum-argument.cpp
+++ cfe/trunk/test/SemaTemplate/enum-argument.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 enum Enum { val = 1 };
 template  struct C {
@@ -31,7 +30,7 @@
 unsigned long long bitfield : e0;
 
 void f(int j) {
-  bitfield + j;
+  bitfield + j; // expected-warning {{expression result unused}}
 }
   };
 }
Index: cfe/trunk/test/SemaTemplate/member-access-expr.cpp
===
--- cfe/trunk/test/SemaTemplate/member-access-expr.cpp
+++ cfe/trunk/test/SemaTemplate/member-access-expr.cpp
@@ -156,7 +156,7 @@

[PATCH] D61027: Fix crash on switch conditions of non-integer types in templates

2019-08-13 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D61027#1627655 , @gribozavr wrote:

> Sorry, but this change broke ClangTidy tests: 
> http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/16398. I 
> reverted it.


Yes I've been trying to reproduce it locally. Could you please let me know how 
you run clang-tidy tests? check-clang and check-all isn't showing this failure 
locally. I tried setting up clang tooling as described here - 
http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html but I don't find 
clang-tidy in builds


Repository:
  rL LLVM

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

https://reviews.llvm.org/D61027



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


[PATCH] D61027: Fix crash on switch conditions of non-integer types in templates

2019-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Thank you for letting me know. I did try reproducing the issue with check-all 
yesterday but was unable to. I do not think I build with 'clang-tools-extra' 
project enabled though.  I'll take another look today.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D61027



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


[PATCH] D40925: Add option -fkeep-static-consts

2017-12-06 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.

Currently clang does not emit unused static constants declared globally. Local 
static constants are emitted by default. -fkeep-static-consts can be used to 
emit static constants declared globally even if they are not used.

This could be useful for producing identification strings like SVN identifiers 
inside the object file even though the string isn't used by the program.


https://reviews.llvm.org/D40925

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  lib/AST/ASTContext.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/keep-static-consts.cpp


Index: test/CodeGen/keep-static-consts.cpp
===
--- /dev/null
+++ test/CodeGen/keep-static-consts.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fkeep-static-consts -emit-llvm %s -o - 
-triple=x86_64-unknown-linux-gnu | FileCheck %s
+
+// CHECK: @_ZL3var = internal constant i32 10, align 4
+static const int var = 10;
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2509,6 +2509,7 @@
   Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns)
 | Opts.NativeHalfArgsAndReturns;
   Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm);
+  Opts.KeepStaticConsts = Args.hasArg(OPT_fkeep_static_consts);
 
   // __declspec is enabled by default for the PS4 by the driver, and also
   // enabled for Microsoft Extensions or Borland Extensions, here.
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3803,6 +3803,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
+  Args.AddLastArg(CmdArgs, options::OPT_fkeep_static_consts);
   // Emulated TLS is enabled by default on Android and OpenBSD, and can be 
enabled
   // manually with -femulated-tls.
   bool EmulatedTLSDefault = Triple.isAndroid() || Triple.isOSOpenBSD() ||
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -9314,6 +9314,12 @@
   if (D->hasAttr() || D->hasAttr())
 return true;
 
+  // Emit static constants even if they are not used if KeepStaticConsts is 
set.
+  if (const VarDecl *VD = dyn_cast(D)) {
+if (LangOpts.KeepStaticConsts && VD->getType().isConstQualified())
+  return true;
+  }
+
   if (const FunctionDecl *FD = dyn_cast(D)) {
 // Forward declarations aren't required.
 if (!FD->doesThisDeclarationHaveABody())
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -835,6 +835,8 @@
 def fjump_tables : Flag<["-"], "fjump-tables">, Group;
 def fno_jump_tables : Flag<["-"], "fno-jump-tables">, Group, 
Flags<[CC1Option]>,
   HelpText<"Do not use jump tables for lowering switches">;
+def fkeep_static_consts : Flag<["-"], "fkeep-static-consts">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Keep static const variables even if unused">;
 
 // Begin sanitizer flags. These should all be core options exposed in all 
driver
 // modes.
Index: include/clang/Basic/LangOptions.def
===
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -319,6 +319,8 @@
 BENIGN_LANGOPT(AllowEditorPlaceholders, 1, 0,
"allow editor placeholders in source")
 
+BENIGN_LANGOPT(KeepStaticConsts  , 1, 0, "keep static const variables even 
if unused")
+
 #undef LANGOPT
 #undef COMPATIBLE_LANGOPT
 #undef BENIGN_LANGOPT


Index: test/CodeGen/keep-static-consts.cpp
===
--- /dev/null
+++ test/CodeGen/keep-static-consts.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fkeep-static-consts -emit-llvm %s -o - -triple=x86_64-unknown-linux-gnu | FileCheck %s
+
+// CHECK: @_ZL3var = internal constant i32 10, align 4
+static const int var = 10;
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2509,6 +2509,7 @@
   Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns)
 | Opts.NativeHalfArgsAndReturns;
   Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm);
+  Opts.KeepStaticConsts = Args.hasArg(OPT_fkeep_static_consts);
 
   // __declspec is enabled by default for the PS4 by the driver, and also
   // enabled for Microsoft Extensions or Borla

[PATCH] D40925: Add option -fkeep-static-consts

2017-12-11 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

*ping*


https://reviews.llvm.org/D40925



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


[PATCH] D119045: Fix address space for function types with AS qualifier

2022-02-04 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: rjmccall, dylanmckay, bader.
eandrews requested review of this revision.

This patch fixes a bug introduced in commit 4eaf5846d0e7 
 - 
https://reviews.llvm.org/D111566

Commit 4eaf5846d0e7 
 sets 
address space of function type as program address space unconditionally. This 
breaks types which have address space qualifiers. E.g. __ptr32.

This patch fixes the bug by using address space qualifiers if present.


https://reviews.llvm.org/D119045

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/CodeGen/address-space-ptr32.c


Index: clang/test/CodeGen/address-space-ptr32.c
===
--- /dev/null
+++ clang/test/CodeGen/address-space-ptr32.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm < %s 
| FileCheck %s
+
+int foo() {
+  int (*__ptr32 a)(int);
+  return sizeof(a);
+}
+
+// CHECK: define dso_local i32 @foo
+// CHECK: %a = alloca i32 (i32) addrspace(270)*, align 4
+// CHECK: ret i32 4
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11959,8 +11959,11 @@
 }
 
 unsigned ASTContext::getTargetAddressSpace(QualType T) const {
-  return T->isFunctionType() ? getTargetInfo().getProgramAddressSpace()
- : getTargetAddressSpace(T.getQualifiers());
+  // For function type, return program address space, unless
+  // type has address space qualifier
+  return T->isFunctionType() && !T.hasAddressSpace()
+ ? getTargetInfo().getProgramAddressSpace()
+ : getTargetAddressSpace(T.getQualifiers());
 }
 
 unsigned ASTContext::getTargetAddressSpace(Qualifiers Q) const {


Index: clang/test/CodeGen/address-space-ptr32.c
===
--- /dev/null
+++ clang/test/CodeGen/address-space-ptr32.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm < %s | FileCheck %s
+
+int foo() {
+  int (*__ptr32 a)(int);
+  return sizeof(a);
+}
+
+// CHECK: define dso_local i32 @foo
+// CHECK: %a = alloca i32 (i32) addrspace(270)*, align 4
+// CHECK: ret i32 4
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11959,8 +11959,11 @@
 }
 
 unsigned ASTContext::getTargetAddressSpace(QualType T) const {
-  return T->isFunctionType() ? getTargetInfo().getProgramAddressSpace()
- : getTargetAddressSpace(T.getQualifiers());
+  // For function type, return program address space, unless
+  // type has address space qualifier
+  return T->isFunctionType() && !T.hasAddressSpace()
+ ? getTargetInfo().getProgramAddressSpace()
+ : getTargetAddressSpace(T.getQualifiers());
 }
 
 unsigned ASTContext::getTargetAddressSpace(Qualifiers Q) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119045: Fix address space for function types with AS qualifier

2022-02-07 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGed5b42b74188: Fix address space for function pointers with 
qualifier (authored by eandrews).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D119045?vs=406124&id=406580#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119045

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/CodeGen/address-space-ptr32.c


Index: clang/test/CodeGen/address-space-ptr32.c
===
--- /dev/null
+++ clang/test/CodeGen/address-space-ptr32.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm < %s 
| FileCheck %s
+
+int foo(void) {
+  int (*__ptr32 a)(int);
+  return sizeof(a);
+}
+
+// CHECK: define dso_local i32 @foo
+// CHECK: %a = alloca i32 (i32) addrspace(270)*, align 4
+// CHECK: ret i32 4
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11959,8 +11959,13 @@
 }
 
 unsigned ASTContext::getTargetAddressSpace(QualType T) const {
-  return T->isFunctionType() ? getTargetInfo().getProgramAddressSpace()
- : getTargetAddressSpace(T.getQualifiers());
+  // Return the address space for the type. If the type is a
+  // function type without an address space qualifier, the
+  // program address space is used. Otherwise, the target picks
+  // the best address space based on the type information
+  return T->isFunctionType() && !T.hasAddressSpace()
+ ? getTargetInfo().getProgramAddressSpace()
+ : getTargetAddressSpace(T.getQualifiers());
 }
 
 unsigned ASTContext::getTargetAddressSpace(Qualifiers Q) const {


Index: clang/test/CodeGen/address-space-ptr32.c
===
--- /dev/null
+++ clang/test/CodeGen/address-space-ptr32.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm < %s | FileCheck %s
+
+int foo(void) {
+  int (*__ptr32 a)(int);
+  return sizeof(a);
+}
+
+// CHECK: define dso_local i32 @foo
+// CHECK: %a = alloca i32 (i32) addrspace(270)*, align 4
+// CHECK: ret i32 4
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11959,8 +11959,13 @@
 }
 
 unsigned ASTContext::getTargetAddressSpace(QualType T) const {
-  return T->isFunctionType() ? getTargetInfo().getProgramAddressSpace()
- : getTargetAddressSpace(T.getQualifiers());
+  // Return the address space for the type. If the type is a
+  // function type without an address space qualifier, the
+  // program address space is used. Otherwise, the target picks
+  // the best address space based on the type information
+  return T->isFunctionType() && !T.hasAddressSpace()
+ ? getTargetInfo().getProgramAddressSpace()
+ : getTargetAddressSpace(T.getQualifiers());
 }
 
 unsigned ASTContext::getTargetAddressSpace(Qualifiers Q) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119045: Fix address space for function types with AS qualifier

2022-02-07 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D119045#3302129 , @aaron.ballman 
wrote:

> LGTM aside from some nits

Thanks! Fixed the nits in commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119045

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


[PATCH] D36487: Emit section information for extern variables.

2017-08-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.

Currently, if  _attribute_((section())) is used for extern variables, section 
information is not emitted in generated IR when the variables are used. This is 
expected since sections are not generated for external linkage objects. However 
NiosII requires this information as it uses special GP-relative accesses for 
any objects that use attribute section (.sdata). GCC keeps this attribute in 
middle-end.

This change emits the section information for all targets.


https://reviews.llvm.org/D36487

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCXX/extern-section-attribute.cpp


Index: test/CodeGenCXX/extern-section-attribute.cpp
===
--- /dev/null
+++ test/CodeGenCXX/extern-section-attribute.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=i386-pc-linux-gnu 
| FileCheck %s --check-prefix=CHECK-LIN
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding 
-triple=x86_64-pc-linux-gnu | FileCheck %s --check-prefix=CHECK-LIN
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=i386-pc-win32 | 
FileCheck %s --check-prefix=CHECK-WIN
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=x86_64-pc-win32 | 
FileCheck %s  --check-prefix=CHECK-WIN
+
+extern int aa __attribute__((section(".sdata")));
+// CHECK-LIN-DAG: @aa = external global i32, section ".sdata", align 4
+// CHECK-WIN-DAG: @"\01?aa@@3HA" = external global i32, section ".sdata", 
align 4
+
+extern int bb __attribute__((section(".sdata"))) = 1;
+// CHECK-LIN-DAG: @bb = global i32 1, section ".sdata", align 4
+// CHECK-WIN-DAG: @"\01?bb@@3HA" = global i32 1, section ".sdata", align 4
+
+int foo() {
+  return aa + bb;
+}
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2430,6 +2430,12 @@
   EmitGlobalVarDefinition(D);
 }
 
+// Emit section information for extern variables.
+if (D->hasExternalStorage() && !D->isThisDeclarationADefinition()) {
+  if (const SectionAttr *SA = D->getAttr())
+GV->setSection(SA->getName());
+}
+
 // Handle XCore specific ABI requirements.
 if (getTriple().getArch() == llvm::Triple::xcore &&
 D->getLanguageLinkage() == CLanguageLinkage &&


Index: test/CodeGenCXX/extern-section-attribute.cpp
===
--- /dev/null
+++ test/CodeGenCXX/extern-section-attribute.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=i386-pc-linux-gnu | FileCheck %s --check-prefix=CHECK-LIN
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=x86_64-pc-linux-gnu | FileCheck %s --check-prefix=CHECK-LIN
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=i386-pc-win32 | FileCheck %s --check-prefix=CHECK-WIN
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=x86_64-pc-win32 | FileCheck %s  --check-prefix=CHECK-WIN
+
+extern int aa __attribute__((section(".sdata")));
+// CHECK-LIN-DAG: @aa = external global i32, section ".sdata", align 4
+// CHECK-WIN-DAG: @"\01?aa@@3HA" = external global i32, section ".sdata", align 4
+
+extern int bb __attribute__((section(".sdata"))) = 1;
+// CHECK-LIN-DAG: @bb = global i32 1, section ".sdata", align 4
+// CHECK-WIN-DAG: @"\01?bb@@3HA" = global i32 1, section ".sdata", align 4
+
+int foo() {
+  return aa + bb;
+}
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2430,6 +2430,12 @@
   EmitGlobalVarDefinition(D);
 }
 
+// Emit section information for extern variables.
+if (D->hasExternalStorage() && !D->isThisDeclarationADefinition()) {
+  if (const SectionAttr *SA = D->getAttr())
+GV->setSection(SA->getName());
+}
+
 // Handle XCore specific ABI requirements.
 if (getTriple().getArch() == llvm::Triple::xcore &&
 D->getLanguageLinkage() == CLanguageLinkage &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36487: Emit section information for extern variables.

2017-08-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added inline comments.



Comment at: lib/CodeGen/CodeGenModule.cpp:2434
+// Emit section information for extern variables.
+if (D->hasExternalStorage() && !D->isThisDeclarationADefinition()) {
+  if (const SectionAttr *SA = D->getAttr())

efriedma wrote:
> Why do you specifically check "D->hasExternalStorage() && 
> !D->isThisDeclarationADefinition()", instead of just setting the section 
> unconditionally?
I noticed that you enter GetOrCreateLLVMGlobal( ) whenever the extern variable 
is declared as well as when it is defined. The flow of the program is different 
in each case. When the variable is defined, it also enters 
EmitGlobalVarDefinition( ). There is existing code handling section information 
here. I added the check in GetOrCreateLLVMGlobal( ) so the block gets skipped 
for variable definition, since its already handled elsewhere.


https://reviews.llvm.org/D36487



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


[PATCH] D36487: Emit section information for extern variables.

2017-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 111064.
eandrews added a comment.

As per review comments, removed extra RUNS in lit test.


https://reviews.llvm.org/D36487

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCXX/extern-section-attribute.cpp


Index: test/CodeGenCXX/extern-section-attribute.cpp
===
--- /dev/null
+++ test/CodeGenCXX/extern-section-attribute.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding 
-triple=x86_64-pc-linux-gnu | FileCheck %s 
+
+extern int aa __attribute__((section(".sdata")));
+// CHECK-DAG: @aa = external global i32, section ".sdata", align 4
+
+extern int bb __attribute__((section(".sdata"))) = 1;
+// CHECK-DAG: @bb = global i32 1, section ".sdata", align 4
+
+int foo() {
+  return aa + bb;
+}
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2430,6 +2430,12 @@
   EmitGlobalVarDefinition(D);
 }
 
+// Emit section information for extern variables.
+if (D->hasExternalStorage() && !D->isThisDeclarationADefinition()) {
+  if (const SectionAttr *SA = D->getAttr())
+GV->setSection(SA->getName());
+}
+
 // Handle XCore specific ABI requirements.
 if (getTriple().getArch() == llvm::Triple::xcore &&
 D->getLanguageLinkage() == CLanguageLinkage &&


Index: test/CodeGenCXX/extern-section-attribute.cpp
===
--- /dev/null
+++ test/CodeGenCXX/extern-section-attribute.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=x86_64-pc-linux-gnu | FileCheck %s 
+
+extern int aa __attribute__((section(".sdata")));
+// CHECK-DAG: @aa = external global i32, section ".sdata", align 4
+
+extern int bb __attribute__((section(".sdata"))) = 1;
+// CHECK-DAG: @bb = global i32 1, section ".sdata", align 4
+
+int foo() {
+  return aa + bb;
+}
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2430,6 +2430,12 @@
   EmitGlobalVarDefinition(D);
 }
 
+// Emit section information for extern variables.
+if (D->hasExternalStorage() && !D->isThisDeclarationADefinition()) {
+  if (const SectionAttr *SA = D->getAttr())
+GV->setSection(SA->getName());
+}
+
 // Handle XCore specific ABI requirements.
 if (getTriple().getArch() == llvm::Triple::xcore &&
 D->getLanguageLinkage() == CLanguageLinkage &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36712: Emit section information for extern variables

2017-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.

Update IR generated to retain section information for external declarations. 
This is related to https://reviews.llvm.org/D36487


https://reviews.llvm.org/D36712

Files:
  docs/LangRef.rst


Index: docs/LangRef.rst
===
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -622,6 +622,12 @@
 Additionally, the global can placed in a comdat if the target has the necessary
 support.
 
+External declarations may have an explicit section specified. When generating 
+LLVM IR, external declarations are ignored and the variables are emitted on 
+their first use. While sections are not generated in the object file 
+corresponding to the LLVM module, section information specified in the 
+declaration is retained in LLVM IR to enable OpenCL processes.
+
 By default, global initializers are optimized by assuming that global
 variables defined within the module are not modified from their
 initial values before the start of the global initializer. This is


Index: docs/LangRef.rst
===
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -622,6 +622,12 @@
 Additionally, the global can placed in a comdat if the target has the necessary
 support.
 
+External declarations may have an explicit section specified. When generating 
+LLVM IR, external declarations are ignored and the variables are emitted on 
+their first use. While sections are not generated in the object file 
+corresponding to the LLVM module, section information specified in the 
+declaration is retained in LLVM IR to enable OpenCL processes.
+
 By default, global initializers are optimized by assuming that global
 variables defined within the module are not modified from their
 initial values before the start of the global initializer. This is
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36712: Emit section information for extern variables

2017-08-15 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 111227.
eandrews added a comment.

I updated the documentation to include Simon's comments. I wasn't sure whether 
to include the line about section information being retained in LLVM IR, since 
Eli mentioned it could vary for different front-ends. I have included it in 
this revision.


https://reviews.llvm.org/D36712

Files:
  docs/LangRef.rst


Index: docs/LangRef.rst
===
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -622,6 +622,12 @@
 Additionally, the global can placed in a comdat if the target has the necessary
 support.
 
+External declarations may have an explicit section specified. Section 
+information is retained in LLVM IR for targets that make use of this 
+information. Attaching section information to an external declaration is an 
+assertion that it's definition is located in the specified section. If the 
+definition is located in a different section, the behavior is undefined.   
+
 By default, global initializers are optimized by assuming that global
 variables defined within the module are not modified from their
 initial values before the start of the global initializer. This is


Index: docs/LangRef.rst
===
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -622,6 +622,12 @@
 Additionally, the global can placed in a comdat if the target has the necessary
 support.
 
+External declarations may have an explicit section specified. Section 
+information is retained in LLVM IR for targets that make use of this 
+information. Attaching section information to an external declaration is an 
+assertion that it's definition is located in the specified section. If the 
+definition is located in a different section, the behavior is undefined.   
+
 By default, global initializers are optimized by assuming that global
 variables defined within the module are not modified from their
 initial values before the start of the global initializer. This is
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36712: Emit section information for extern variables

2017-08-15 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added inline comments.



Comment at: docs/LangRef.rst:629
+corresponding to the LLVM module, section information specified in the 
+declaration is retained in LLVM IR to enable OpenCL processes.
+

kparzysz wrote:
> sdardis wrote:
> > efriedma wrote:
> > > This doesn't really explain the part that matters. For LangRef, it 
> > > doesn't matter how the frontend decides to generate declarations (and it 
> > > might be different for frontends other than clang).  And OpenCL might 
> > > motivate this, but it has nothing to do with the semantics.
> > > 
> > > The key question here is what it actually means.  Is it a promise the 
> > > that a definition will exist for the given symbol in the given section?  
> > > If so, what happens if the symbol is actually in a different section?  
> > > ("Undefined behavior" is probably an acceptable answer, but it needs to 
> > > be stated explicitly.)
> > > to enable OpenCL processes.
> > 
> > for targets which make use of this section information. 
> > 
> > I would also work in a sentence that says that attaching section 
> > information to a external declaration is an assertion or promise that the 
> > definition is located in that section. If the definition is actually 
> > located in a different section the behaviour is undefined.
> > 
> > I'm favouring "undefined behaviour" in the error case as behaviour is so 
> > target and environment specific.
> The other side of the problem is, what if the declarations don't have any 
> section information, but the definition does? Is that also an undefined 
> behavior? I'm in favor of considering it UB as well, but I'm not sure what 
> impact it would have on currently valid IR.
The changes I made in Clang assume that the definition is located in the same 
section specified in the declaration. If its different, the IR for the 
translation unit with the extern declaration will emit whatever section was 
specified in the declaration while the variable is actually located elsewhere. 
I am not sure what the consequences of this are.



https://reviews.llvm.org/D36712



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


[PATCH] D36712: Emit section information for extern variables

2017-08-16 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 111341.
eandrews added a comment.

Corrected spelling error.


https://reviews.llvm.org/D36712

Files:
  docs/LangRef.rst


Index: docs/LangRef.rst
===
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -622,6 +622,12 @@
 Additionally, the global can placed in a comdat if the target has the necessary
 support.
 
+External declarations may have an explicit section specified. Section 
+information is retained in LLVM IR for targets that make use of this 
+information. Attaching section information to an external declaration is an 
+assertion that its definition is located in the specified section. If the 
+definition is located in a different section, the behavior is undefined.   
+
 By default, global initializers are optimized by assuming that global
 variables defined within the module are not modified from their
 initial values before the start of the global initializer. This is


Index: docs/LangRef.rst
===
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -622,6 +622,12 @@
 Additionally, the global can placed in a comdat if the target has the necessary
 support.
 
+External declarations may have an explicit section specified. Section 
+information is retained in LLVM IR for targets that make use of this 
+information. Attaching section information to an external declaration is an 
+assertion that its definition is located in the specified section. If the 
+definition is located in a different section, the behavior is undefined.   
+
 By default, global initializers are optimized by assuming that global
 variables defined within the module are not modified from their
 initial values before the start of the global initializer. This is
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36712: Emit section information for extern variables

2017-08-16 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In https://reviews.llvm.org/D36712#842477, @kparzysz wrote:

> In the cases when the section is explicitly given on a definition, it was 
> likely imposed by something like the "section" attribute in the source. I 
> don't think it's unreasonable to expect that the declarations (in the 
> original source as well as in the generated IR) should carry that information 
> as well. However, since clang has apparently been ignoring that attribute on 
> declarations, it's been generating IR where declarations may not have 
> sections, but the corresponding definitions do.


Does this result in unexpected behavior though? Won't this just result in the 
global being defined in the specified section?

I can mention this case explicitly in the documentation. However I am not sure 
whether it's UB or if the global will be defined in specified section.


https://reviews.llvm.org/D36712



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


[PATCH] D36712: Emit section information for extern variables

2017-08-16 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 111388.
eandrews added a comment.

Updated the patch to include Krzysztof's comment about explicitly stating 
undefined behavior for section information mismatch in global variable 
declaration and definition. This should cover the case where section is 
explicitly specified in definition but not declaration.


https://reviews.llvm.org/D36712

Files:
  docs/LangRef.rst


Index: docs/LangRef.rst
===
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -579,7 +579,9 @@
 case they don't have an initializer.
 
 Either global variable definitions or declarations may have an explicit section
-to be placed in and may have an optional explicit alignment specified.
+to be placed in and may have an optional explicit alignment specified. A 
+mismatch between section information in the variable declaration and its
+definition is undefined behavior. 
 
 A variable may be defined as a global ``constant``, which indicates that
 the contents of the variable will **never** be modified (enabling better
@@ -622,6 +624,12 @@
 Additionally, the global can placed in a comdat if the target has the necessary
 support.
 
+External declarations may have an explicit section specified. Section 
+information is retained in LLVM IR for targets that make use of this 
+information. Attaching section information to an external declaration is an 
+assertion that its definition is located in the specified section. If the 
+definition is located in a different section, the behavior is undefined.   
+
 By default, global initializers are optimized by assuming that global
 variables defined within the module are not modified from their
 initial values before the start of the global initializer. This is


Index: docs/LangRef.rst
===
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -579,7 +579,9 @@
 case they don't have an initializer.
 
 Either global variable definitions or declarations may have an explicit section
-to be placed in and may have an optional explicit alignment specified.
+to be placed in and may have an optional explicit alignment specified. A 
+mismatch between section information in the variable declaration and its
+definition is undefined behavior. 
 
 A variable may be defined as a global ``constant``, which indicates that
 the contents of the variable will **never** be modified (enabling better
@@ -622,6 +624,12 @@
 Additionally, the global can placed in a comdat if the target has the necessary
 support.
 
+External declarations may have an explicit section specified. Section 
+information is retained in LLVM IR for targets that make use of this 
+information. Attaching section information to an external declaration is an 
+assertion that its definition is located in the specified section. If the 
+definition is located in a different section, the behavior is undefined.   
+
 By default, global initializers are optimized by assuming that global
 variables defined within the module are not modified from their
 initial values before the start of the global initializer. This is
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36712: Emit section information for extern variables

2017-08-16 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In https://reviews.llvm.org/D36712#843414, @kparzysz wrote:

> The problem is that the mismatch between sections does not have to lead to 
> any undesirable behavior.  Whether it does or not depends on a particular 
> case.  I think we should be consistent though---if we decide that a mismatch 
> between the section for a declaration and the section for a definition leads 
> to an undefined behavior, then it should be so regardless of whether the 
> sections were given explicitly or inferred.


Ok. That makes sense. I've updated the documentation to reflect this. Please 
let me know if it needs to be more detailed.


https://reviews.llvm.org/D36712



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


[PATCH] D36712: Emit section information for extern variables

2017-08-22 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 112172.
eandrews added a comment.

Updated the documentation to explicitly state that section information for a 
variable can be explicit or inferred.


https://reviews.llvm.org/D36712

Files:
  docs/LangRef.rst


Index: docs/LangRef.rst
===
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -579,7 +579,9 @@
 case they don't have an initializer.
 
 Either global variable definitions or declarations may have an explicit section
-to be placed in and may have an optional explicit alignment specified.
+to be placed in and may have an optional explicit alignment specified. If 
there 
+is a mismatch between the explicit or inferred section information for the 
+variable declaration and its definition the resulting behavior is undefined. 
 
 A variable may be defined as a global ``constant``, which indicates that
 the contents of the variable will **never** be modified (enabling better
@@ -622,6 +624,12 @@
 Additionally, the global can placed in a comdat if the target has the necessary
 support.
 
+External declarations may have an explicit section specified. Section 
+information is retained in LLVM IR for targets that make use of this 
+information. Attaching section information to an external declaration is an 
+assertion that its definition is located in the specified section. If the 
+definition is located in a different section, the behavior is undefined.   
+
 By default, global initializers are optimized by assuming that global
 variables defined within the module are not modified from their
 initial values before the start of the global initializer. This is


Index: docs/LangRef.rst
===
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -579,7 +579,9 @@
 case they don't have an initializer.
 
 Either global variable definitions or declarations may have an explicit section
-to be placed in and may have an optional explicit alignment specified.
+to be placed in and may have an optional explicit alignment specified. If there 
+is a mismatch between the explicit or inferred section information for the 
+variable declaration and its definition the resulting behavior is undefined. 
 
 A variable may be defined as a global ``constant``, which indicates that
 the contents of the variable will **never** be modified (enabling better
@@ -622,6 +624,12 @@
 Additionally, the global can placed in a comdat if the target has the necessary
 support.
 
+External declarations may have an explicit section specified. Section 
+information is retained in LLVM IR for targets that make use of this 
+information. Attaching section information to an external declaration is an 
+assertion that its definition is located in the specified section. If the 
+definition is located in a different section, the behavior is undefined.   
+
 By default, global initializers are optimized by assuming that global
 variables defined within the module are not modified from their
 initial values before the start of the global initializer. This is
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36487: Emit section information for extern variables.

2017-08-22 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

LangRef has been updated and accepted. You can find it here - 
https://reviews.llvm.org/rL311459


https://reviews.llvm.org/D36487



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


[PATCH] D72242: Fix crash on value dependent bitfields in if conditions in templates

2020-01-05 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: rnk, erichkeane, alexfh, alexfh_.

This patch is a follow up to D69950 , to fix a 
new crash on CXX condition expressions in templates, for value dependent 
bitfields.  Clang currently crashes when integral promotion is attempted on the 
condition. This patch adds a guard to prevent the promotion for value dependent 
bitfields. Prior to D69950 , the guard was 
unnecessary because incorrect type dependency of bitfield prevented the 
compiler from reaching this code.


https://reviews.llvm.org/D72242

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp


Index: clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template
+class a {
+  int c : b;
+  void f() {
+if (c)
+  ;
+  }
+};
+
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -2158,6 +2158,7 @@
 if (FieldDecl *MemberDecl = From->getSourceBitField()) {
   llvm::APSInt BitWidth;
   if (FromType->isIntegralType(Context) &&
+  !MemberDecl->getBitWidth()->isValueDependent() &&
   MemberDecl->getBitWidth()->isIntegerConstantExpr(BitWidth, Context)) 
{
 llvm::APSInt ToSize(BitWidth.getBitWidth(), BitWidth.isUnsigned());
 ToSize = Context.getTypeSize(ToType);


Index: clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template
+class a {
+  int c : b;
+  void f() {
+if (c)
+  ;
+  }
+};
+
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -2158,6 +2158,7 @@
 if (FieldDecl *MemberDecl = From->getSourceBitField()) {
   llvm::APSInt BitWidth;
   if (FromType->isIntegralType(Context) &&
+  !MemberDecl->getBitWidth()->isValueDependent() &&
   MemberDecl->getBitWidth()->isIntegerConstantExpr(BitWidth, Context)) {
 llvm::APSInt ToSize(BitWidth.getBitWidth(), BitWidth.isUnsigned());
 ToSize = Context.getTypeSize(ToType);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72242: Fix crash on value dependent bitfields in if conditions in templates

2020-01-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Thanks for taking a look Erich!

> I'm concerned about just making this fallthrough to 'false'. These ARE 
> integral promotions, we just don't know the type size.

In this case, when integral promotion is skipped, boolean conversion (C++ 4.12) 
is done instead when parsing the template declaration.

> What happens if you instantiate this template? Will it still give the correct 
> answer/type/diagnosis?

I stepped through the code for an instantiated template and in this case, 
integral promotion is done since 'b' is no longer value dependent and is 
whatever we instantiated it with. I'm not sure what the correct behavior here 
is, so I compared current behavior to Clang prior to D69950 
 + this patch. The only difference  I could 
see in the AST is an additional implicit cast for if(c) in template declaration 
(expected since D69950  changed the type 
dependency of c and this is the only guard).  There is no difference in IR 
generated.

> In the case of the crash, I would suspect that the expression 'if (c)' should 
> just be dependent and skipped from the semantic analysis because of it.

It turns out skipping semantic analysis for value dependent condition 
expressions is not entirely straightforward. CheckBooleanCondition has a check 
to skip semantic analysis for type-dependent expressions. Adding a value 
dependency check here however causes crashes (lit tests) because apparently 
semantic analysis for noexcept calls this as well.

  ExprResult Sema::ActOnNoexceptSpec(SourceLocation NoexceptLoc,
 Expr *NoexceptExpr,
 ExceptionSpecificationType &EST) {
// FIXME: This is bogus, a noexcept expression is not a condition.
ExprResult Converted = CheckBooleanCondition(NoexceptLoc, NoexceptExpr);

I don't really know how noexcept is handled in Clang but it looks like it 
expects the conversion of value dependent expressions. I guess I could add a 
guard in ActOnCond instead and see what happens.


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

https://reviews.llvm.org/D72242



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


[PATCH] D72242: Fix crash on value dependent bitfields in if conditions in templates

2020-01-09 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 237132.
eandrews edited the summary of this revision.
eandrews added a comment.

Semantic analysis for value dependent conditions is now skipped as per Erich's 
comment.  Patch adds an argument to CheckBooleanCondition to still do the 
required analysis for noexcept expressions.


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

https://reviews.llvm.org/D72242

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp


Index: clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -ast-dump | FileCheck %s 
--check-prefix=CHECK-AST
+// expected-no-diagnostics
+
+template 
+class A {
+  int c : b;
+
+public:
+  void f() {
+if (c)
+  ;
+  }
+};
+
+void foo() {
+
+  // CHECK-AST: ClassTemplateSpecializationDecl{{.*}}class A definition
+  // CHECK-AST: TemplateArgument integral 3
+  // CHECK-AST: FieldDecl{{.*}}c 'int'
+  // CHECK-AST-NEXT: ConstantExpr{{.*}}'int' Int: 3
+  // CHECK-AST-NEXT: SubstNonTypeTemplateParmExpr{{.*}}'int'
+  // CHECK-AST-NEXT: IntegerLiteral{{.*}}'int' 3
+  A<3> a;
+
+  // CHECK-AST: IfStmt
+  // CHECK-AST-NEXT: ImplicitCastExpr{{.*}}'bool' 
+  // CHECK-AST-NEXT: ImplicitCastExpr{{.*}}'int' 
+  // CHECK-AST-NEXT: MemberExpr{{.*}}'int' lvalue bitfield ->c
+  // CHECK-AST-NEXT: CXXThisExpr{{.*}}'A<3> *' implicit this
+  a.f();
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -17362,7 +17362,7 @@
 }
 
 ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E,
-   bool IsConstexpr) {
+   bool IsConstexpr, bool IsNoexceptExpr) {
   DiagnoseAssignmentAsCondition(E);
   if (ParenExpr *parenE = dyn_cast(E))
 DiagnoseEqualityWithExtraParens(parenE);
@@ -17372,8 +17372,11 @@
   E = result.get();
 
   if (!E->isTypeDependent()) {
-if (getLangOpts().CPlusPlus)
+if (getLangOpts().CPlusPlus) {
+  if (E->isValueDependent() && !IsNoexceptExpr)
+return E;
   return CheckCXXBooleanCondition(E, IsConstexpr); // C++ 6.4p4
+}
 
 ExprResult ERes = DefaultFunctionArrayLvalueConversion(E);
 if (ERes.isInvalid())
Index: clang/lib/Sema/SemaExceptionSpec.cpp
===
--- clang/lib/Sema/SemaExceptionSpec.cpp
+++ clang/lib/Sema/SemaExceptionSpec.cpp
@@ -80,7 +80,9 @@
Expr *NoexceptExpr,
ExceptionSpecificationType &EST) {
   // FIXME: This is bogus, a noexcept expression is not a condition.
-  ExprResult Converted = CheckBooleanCondition(NoexceptLoc, NoexceptExpr);
+  ExprResult Converted = CheckBooleanCondition(NoexceptLoc, NoexceptExpr,
+   /*IsConstexpr*/ false,
+   /*IsNoexceptExpr*/ true);
   if (Converted.isInvalid())
 return Converted;
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10885,7 +10885,8 @@
   /// 'if' keyword.
   /// \return true iff there were any errors
   ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E,
-   bool IsConstexpr = false);
+   bool IsConstexpr = false,
+   bool IsNoexceptExpr = false);
 
   /// ActOnExplicitBoolSpecifier - Build an ExplicitSpecifier from an 
expression
   /// found in an explicit(bool) specifier.


Index: clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -ast-dump | FileCheck %s --check-prefix=CHECK-AST
+// expected-no-diagnostics
+
+template 
+class A {
+  int c : b;
+
+public:
+  void f() {
+if (c)
+  ;
+  }
+};
+
+void foo() {
+
+  // CHECK-AST: ClassTemplateSpecializationDecl{{.*}}class A definition
+  // CHECK-AST: TemplateArgument integral 3
+  // CHECK-AST: FieldDecl{{.*}}c 'int'
+  // CHECK-AST-NEXT: ConstantExpr{{.*}}'int' Int: 3
+  // CHECK-AST-NEXT: SubstNonTypeTemplateParmExpr{{.*}}'int'
+  // CHECK-AST-NEXT: IntegerLiteral{{.*}}'int' 3
+  A<3> a;
+
+  // CHECK-AST: IfStmt
+  // CHECK-AST-NEXT: ImplicitCastExpr{{.*}}'bool' 
+  // CHECK-AST-NEXT: ImplicitCastExpr{{.*}}'int' 
+  // CHECK-AST-NEXT: MemberExpr{{.*}}'int' lvalue bitfield ->c
+  // CHECK-AST-NEX

[PATCH] D87701: Do not apply calling conventions to MSVC entry points

2020-09-15 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: rnk, erichkeane.
eandrews requested review of this revision.

Fix link error for MSVC entry points when calling conventions are specified. 
MSVC entry points should have default calling convention.


https://reviews.llvm.org/D87701

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/default_calling_conv.cpp


Index: clang/test/CodeGenCXX/default_calling_conv.cpp
===
--- clang/test/CodeGenCXX/default_calling_conv.cpp
+++ clang/test/CodeGenCXX/default_calling_conv.cpp
@@ -1,10 +1,14 @@
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CDECL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i786-unknown-linux-gnu -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=FASTCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i486-unknown-linux-gnu 
-fdefault-calling-conv=stdcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=STDCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | 
FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VECTORCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=REGCALL --check-prefix=ALL
-
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl 
-emit-llvm -o - %s -DMAIN | FileCheck %s --check-prefix=CDECL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i786-unknown-linux-gnu -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=FASTCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i486-unknown-linux-gnu 
-fdefault-calling-conv=stdcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=STDCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s 
-DMAIN | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=vectorcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=VECTORCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=regcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=REGCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWMAIN | FileCheck %s  
--check-prefix=WMAIN
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWINMAIN | FileCheck %s  
--check-prefix=WINMAIN
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWWINMAIN | FileCheck %s  
--check-prefix=WWINMAIN
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DDLLMAIN | FileCheck %s  
--check-prefix=DLLMAIN
+//
 // CDECL: define void @_Z5test1v
 // FASTCALL: define x86_fastcallcc void @_Z5test1v
 // STDCALL: define x86_stdcallcc void @_Z5test1v
@@ -46,7 +50,37 @@
   a.test_member();
 }
 
+#ifdef MAIN
 // ALL: define i32 @main
 int main() {
   return 1;
 }
+#endif // main
+
+#ifdef WMAIN
+// WMAIN: define dso_local i32 @wmain
+int wmain() {
+  return 1;
+}
+#endif // wmain
+
+#ifdef WINMAIN
+// WINMAIN: define dso_local i32 @WinMain
+int WinMain() {
+  return 1;
+}
+#endif // WinMain
+
+#ifdef WWINMAIN
+// WWINMAIN: define dso_local i32 @wWinMain
+int wWinMain() {
+  return 1;
+}
+#endif // wWinMain
+
+#ifdef DLLMAIN
+// DLLMAIN: define dso_local i32 @DllMain
+int DllMain() {
+  return 1;
+}
+#endif // DllMain
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11095,6 +11095,11 @@
 if (FD->getName() != "DllMain")
   FD->setHasImplicitReturnZero(true);
 
+  if (FT->getCallConv() != CC_C) {
+FT = Context.adjustFunctionType(FT, 
FT->getExtInfo().withCallingConv(CC_C));
+FD->setType(QualType(FT, 0));
+  }
+
   if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) {
 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD;
 FD->setInvalidDecl();


Index: clang/test/CodeGenCXX/default_calling_conv.cpp
===
--- clang/test/CodeGenCXX/default_calling_conv.cpp
+++ clang/test/CodeGenCXX/default_calling_conv.cpp
@@ -1,10 +1,14 @@
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl -emit-llvm -o - %s | FileCheck %s --check-prefix=CDECL --check-prefix=ALL
-// RUN: %clang_cc1 -tr

[PATCH] D87701: Do not apply calling conventions to MSVC entry points

2020-09-16 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4cff1b40dacf: Do not apply calling conventions to MSVC entry 
points (authored by eandrews).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87701

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/default_calling_conv.cpp


Index: clang/test/CodeGenCXX/default_calling_conv.cpp
===
--- clang/test/CodeGenCXX/default_calling_conv.cpp
+++ clang/test/CodeGenCXX/default_calling_conv.cpp
@@ -1,10 +1,14 @@
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CDECL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i786-unknown-linux-gnu -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=FASTCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i486-unknown-linux-gnu 
-fdefault-calling-conv=stdcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=STDCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | 
FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VECTORCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=REGCALL --check-prefix=ALL
-
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl 
-emit-llvm -o - %s -DMAIN | FileCheck %s --check-prefix=CDECL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i786-unknown-linux-gnu -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=FASTCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i486-unknown-linux-gnu 
-fdefault-calling-conv=stdcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=STDCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s 
-DMAIN | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=vectorcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=VECTORCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=regcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=REGCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWMAIN | FileCheck %s  
--check-prefix=WMAIN
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWINMAIN | FileCheck %s  
--check-prefix=WINMAIN
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWWINMAIN | FileCheck %s  
--check-prefix=WWINMAIN
+// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DDLLMAIN | FileCheck %s  
--check-prefix=DLLMAIN
+//
 // CDECL: define void @_Z5test1v
 // FASTCALL: define x86_fastcallcc void @_Z5test1v
 // STDCALL: define x86_stdcallcc void @_Z5test1v
@@ -46,7 +50,37 @@
   a.test_member();
 }
 
+#ifdef MAIN
 // ALL: define i32 @main
 int main() {
   return 1;
 }
+#endif // main
+
+#ifdef WMAIN
+// WMAIN: define dso_local i32 @wmain
+int wmain() {
+  return 1;
+}
+#endif // wmain
+
+#ifdef WINMAIN
+// WINMAIN: define dso_local i32 @WinMain
+int WinMain() {
+  return 1;
+}
+#endif // WinMain
+
+#ifdef WWINMAIN
+// WWINMAIN: define dso_local i32 @wWinMain
+int wWinMain() {
+  return 1;
+}
+#endif // wWinMain
+
+#ifdef DLLMAIN
+// DLLMAIN: define dso_local i32 @DllMain
+int DllMain() {
+  return 1;
+}
+#endif // DllMain
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11095,6 +11095,11 @@
 if (FD->getName() != "DllMain")
   FD->setHasImplicitReturnZero(true);
 
+  if (FT->getCallConv() != CC_C) {
+FT = Context.adjustFunctionType(FT, 
FT->getExtInfo().withCallingConv(CC_C));
+FD->setType(QualType(FT, 0));
+  }
+
   if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) {
 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD;
 FD->setInvalidDecl();


Index: clang/test/CodeGenCXX/default_calling_conv.cpp
===
--- clang/test/CodeGenCXX/default_calling_conv.cpp
+++ clang/test/CodeGenCXX/default_calling_conv.cpp
@@ -1,10 +1,14 @@
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl -emit-llvm -o - %s | FileCheck %

[PATCH] D87701: Do not apply calling conventions to MSVC entry points

2020-09-16 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D87701#2274860 , @rnk wrote:

> lgtm, thanks.

Thanks for taking a look!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87701

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


[PATCH] D87701: Do not apply calling conventions to MSVC entry points

2020-09-17 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D87701#2280246 , @dmajor wrote:

> This broke Firefox builds too, in one of our helper binaries that uses a 
> `wWinMain`, although I'm having trouble writing a minimal reproducer for it. 
> Simply making a barebones `wWinMain` program doesn't hit the error.
>
> If the patch re-lands, please cc me and I'll re-test.

Will do.  I think MSVC applies calling conventions to entry points when it is 
specified in function signature.

  int WinMain(int argc) {return 1;}

Compiling this with /Gr generates symbol ` _WinMain@4` , meaning `/Gr` was 
ignored and fastcall was not applied to WinMain.  But,

  int __fastcall WinMain(int argc) {return 1;}

generates symbol ` @WinMain@4`, meaning __fastcall calling convention was 
applied to WinMain.

It also looks like stdcall is default calling convention for WinMain.

Anyway, I'll upload a new patch for review once I understand the required 
behavior better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87701

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


[PATCH] D96538: [SYCL] Ignore file-scope asm during device-side SYCL compilation.

2021-02-12 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews accepted this revision.
eandrews added a comment.

LGTM Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96538

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


[PATCH] D109950: [Clang] Enable IC/IF mode for __ibm128

2021-10-29 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

This has changed the behavior for -

  // Define __complex128 type corresponding to __float128 (as in GCC headers).
  typedef _Complex float __attribute__((mode(TC))) __complex128;
  
  void check() {
  // CHECK: alloca { fp128, fp128 }   <- Fails because alloca { x86_fp80, 
x86_fp80 } is generated instead
  __complex128 tmp;
  }

In TargetInfo.cpp, we used to check long double format to decide whether to 
return LongDouble or Float128. This patch doesn't, and so the return value has 
changed from FloatModeKind::Float128 to clang::FloatModeKind::LongDouble 
(ExplicitType).  Should we be checking the format?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109950

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


[PATCH] D109950: [Clang] Enable IC/IF mode for __ibm128

2021-10-29 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D109950#3097161 , @rjmccall wrote:

> Oh, yes, I think this should be preserving the old logic there and just 
> adding a new clause for explicit requests for ibm128, right?

I think the old logic should be preserved yes. However, I'm not sure if this 
patch exposes an existing bug. LongDoubleFormat here is 
llvm::semX87DoubleExtended.

In APFloat.cpp, it is defined as -

  static const fltSemantics semX87DoubleExtended = {16383, -16382, 64, 80};

i.e. 80 bit size. Is this the right format for complex type specified using 
mode 'TC'? I am not very familiar with floating point semantics, so I thought I 
would ask.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109950

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


[PATCH] D112975: Fix complex types declared using mode TC

2021-11-01 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: qiucf, rjmccall.
eandrews requested review of this revision.

This patch reverts incorrect IR - introduced in commit d11ec6f67e45 
 
(https://reviews.llvm.org/rGd11ec6f67e45c630ab87bfb6010dcc93e89542fc) - for 
complex types declared using __attribute__((mode(TC))). TC mode corresponds to 
__float128 type.


https://reviews.llvm.org/D112975

Files:
  clang/lib/Basic/TargetInfo.cpp
  clang/test/CodeGenCXX/complex128.cpp


Index: clang/test/CodeGenCXX/complex128.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/complex128.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu %s -o - | 
FileCheck %s
+
+// Define __complex128 type corresponding to __float128 (as in GCC headers).
+typedef _Complex float __attribute__((mode(TC))) __complex128;
+
+void check() {
+  // CHECK: alloca { fp128, fp128 }
+  __complex128 tmp;
+}
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -300,8 +300,11 @@
 if (ExplicitType == FloatModeKind::Ibm128)
   return hasIbm128Type() ? FloatModeKind::Ibm128
  : FloatModeKind::NoFloat;
-if (ExplicitType == FloatModeKind::LongDouble)
-  return ExplicitType;
+if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
+&getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
+  return FloatModeKind::LongDouble;
+if (hasFloat128Type())
+  return FloatModeKind::Float128;
 break;
   }
 


Index: clang/test/CodeGenCXX/complex128.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/complex128.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu %s -o - | FileCheck %s
+
+// Define __complex128 type corresponding to __float128 (as in GCC headers).
+typedef _Complex float __attribute__((mode(TC))) __complex128;
+
+void check() {
+  // CHECK: alloca { fp128, fp128 }
+  __complex128 tmp;
+}
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -300,8 +300,11 @@
 if (ExplicitType == FloatModeKind::Ibm128)
   return hasIbm128Type() ? FloatModeKind::Ibm128
  : FloatModeKind::NoFloat;
-if (ExplicitType == FloatModeKind::LongDouble)
-  return ExplicitType;
+if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
+&getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
+  return FloatModeKind::LongDouble;
+if (hasFloat128Type())
+  return FloatModeKind::Float128;
 break;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109950: [Clang] Enable IC/IF mode for __ibm128

2021-11-01 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D109950#3097652 , @rjmccall wrote:

> In D109950#3097544 , @eandrews 
> wrote:
>
>> In D109950#3097161 , @rjmccall 
>> wrote:
>>
>>> Oh, yes, I think this should be preserving the old logic there and just 
>>> adding a new clause for explicit requests for ibm128, right?
>
> I do wonder whether that's the right priority between `float128_t` and a 
> double-double `long double`.  I think that particular configuration only 
> exists on certain PPC targets; does anyone know what GCC does?

I don't know what GCC does and am not really sure how to go about figuring it 
out. I've uploaded a patch preserving old logic for review here - 
https://reviews.llvm.org/D112975. If I should do something different, please 
let me know. Thank you for your input!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109950

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


[PATCH] D112975: Fix complex types declared using mode TC

2021-11-02 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D112975#3101720 , @rjmccall wrote:

> For posterity in case someone tracks down this review: `TC` corresponds to an 
> unspecified 128-bit format, which on some targets is a double-double format 
> (like `__ibm128_t`) and on others is `float128_t`.  The bug in the previous 
> patch is that  `long double` is only safe to use when it's known to be one of 
> those formats.
>
> Patch LGTM.

Thanks for the note. I'll update the commit message when I check this in.


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

https://reviews.llvm.org/D112975

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


[PATCH] D112975: Fix complex types declared using mode TC

2021-11-02 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5c8d3053fa0c: Fix complex types declared using mode TC 
(authored by eandrews).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112975

Files:
  clang/lib/Basic/TargetInfo.cpp
  clang/test/CodeGenCXX/complex128.cpp


Index: clang/test/CodeGenCXX/complex128.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/complex128.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu %s -o - | 
FileCheck %s
+
+// Define __complex128 type corresponding to __float128 (as in GCC headers).
+typedef _Complex float __attribute__((mode(TC))) __complex128;
+
+void check() {
+  // CHECK: alloca { fp128, fp128 }
+  __complex128 tmp;
+}
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -300,8 +300,11 @@
 if (ExplicitType == FloatModeKind::Ibm128)
   return hasIbm128Type() ? FloatModeKind::Ibm128
  : FloatModeKind::NoFloat;
-if (ExplicitType == FloatModeKind::LongDouble)
-  return ExplicitType;
+if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
+&getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
+  return FloatModeKind::LongDouble;
+if (hasFloat128Type())
+  return FloatModeKind::Float128;
 break;
   }
 


Index: clang/test/CodeGenCXX/complex128.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/complex128.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu %s -o - | FileCheck %s
+
+// Define __complex128 type corresponding to __float128 (as in GCC headers).
+typedef _Complex float __attribute__((mode(TC))) __complex128;
+
+void check() {
+  // CHECK: alloca { fp128, fp128 }
+  __complex128 tmp;
+}
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -300,8 +300,11 @@
 if (ExplicitType == FloatModeKind::Ibm128)
   return hasIbm128Type() ? FloatModeKind::Ibm128
  : FloatModeKind::NoFloat;
-if (ExplicitType == FloatModeKind::LongDouble)
-  return ExplicitType;
+if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
+&getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
+  return FloatModeKind::LongDouble;
+if (hasFloat128Type())
+  return FloatModeKind::Float128;
 break;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111566: [SYCL] Fix function pointer address space

2021-11-04 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

ping


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

https://reviews.llvm.org/D111566

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


[PATCH] D98895: [X86][clang] Disable long double type for -mno-x87 option

2021-11-09 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

This patch causes a regression.

To reproduce - `clang -cc1 -fsycl-is-device -triple spir64 test.cpp`

  // expected-note@+2 {{'bar<__float128>' defined here}}
  template 
  T bar() { return T(); };
  
  void usage() {
// expected-error@+2 {{'bar<__float128>' requires 128 bit size '__float128' 
type support, but target 'spir64' does not support it}}
// expected-error@+1 {{'__float128' is not supported on this target}}
auto malAutoTemp5 = bar<__float128>();
  }
  template 
  __attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
kernelFunc(); // expected-note {{called by 'kernel_single_task([=]() {
  usage(); // expected-note {{called by 'operator()'}}
});
return 0;
  }

This test now fails due to an additional diagnostic generated at template 
definition.

  test.cpp:x:3: error: 'bar<__float128>' requires 128 bit size '__float128' 
type support, but target 'spir64' does not support it
  T bar() { return T(); };
^

I looked at it briefly, and I believe the issue is call to `checkTypeSupport()` 
in `ActOnFinishFunctionBody()`. I tried deleting the call but it breaks tests 
(E.g. L26 in x86_64-no-x87.cpp). @asavonic Please take a look. I will be 
reverting the patch if this cannot be fixed soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98895

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


[PATCH] D98895: [X86][clang] Disable long double type for -mno-x87 option

2021-11-09 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D98895#3119027 , @asavonic wrote:

> In D98895#3118821 , @eandrews wrote:
>
>> This patch causes a regression.
>>
>> To reproduce - `clang -cc1 -fsycl-is-device -triple spir64 test.cpp`
>>
>>   test.cpp:x:3: error: 'bar<__float128>' requires 128 bit size '__float128' 
>> type support, but target 'spir64' does not support it
>>   T bar() { return T(); };
>> ^
>>
>> I looked at it briefly, and I believe the issue is call to 
>> `checkTypeSupport()` in `ActOnFinishFunctionBody()`. I tried deleting the 
>> call but it breaks tests (E.g. L26 in x86_64-no-x87.cpp). @asavonic Please 
>> take a look. I will be reverting the patch if this cannot be fixed soon.
>
> The diagnostic seems to be correct - this instance of `bar` returns an 
> unsupported type. Why do you think it should not be diagnosed?

@asavonic I spoke offline with @erichkeane. I was mistaken. There are only 2 
error diagnostics generated (upstream) after this patch. The additional 
diagnostic generated at `bar ` after your patch is correct. We just need to 
remove the third diagnostic downstream. So nothing needs to be done here. I 
apologize for the confusion and trouble.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98895

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


[PATCH] D97941: [Reland] "Do not apply calling conventions to MSVC entry points"

2021-03-04 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: rnk, akhuang, dmajor.
Herald added a subscriber: mstorsjo.
eandrews requested review of this revision.

This patch is a second attempt at fixing a link error for MSVC entry points 
when calling conventions are specified using a flag.

Calling conventions specified using flags should not be applied to MSVC entry 
points. The default calling convention is set in this case. The default calling 
convention for MSVC entry points main and wmain is __cdecl. For WinMain, 
wWinMain and DllMain, the default calling convention is __stdcall.

Explicitly specified calling conventions are applied to MSVC entry points.

For MinGW, the default calling convention for all MSVC entry points is __cdecl.

First attempt: 4cff1b40dacf6 
 
(https://reviews.llvm.org/D87701)
Revert of first attempt: bebfc3b92d5e8 



https://reviews.llvm.org/D97941

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/default_calling_conv.cpp

Index: clang/test/CodeGenCXX/default_calling_conv.cpp
===
--- clang/test/CodeGenCXX/default_calling_conv.cpp
+++ clang/test/CodeGenCXX/default_calling_conv.cpp
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s --check-prefix=VECTORCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s --check-prefix=REGCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i386-pc-win32 -target-feature +sse4.2 -fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWINDOWS | FileCheck %s --check-prefix=WINDOWS
+// RUN: %clang_cc1 -triple i386-pc-win32 -target-feature +sse4.2  -emit-llvm -o - %s -DEXPLICITCC | FileCheck %s --check-prefix=EXPLICITCC
 
 // CDECL: define{{.*}} void @_Z5test1v
 // FASTCALL: define{{.*}} x86_fastcallcc void @_Z5test1v
@@ -50,3 +52,41 @@
 int main() {
   return 1;
 }
+
+#ifdef WINDOWS
+// WINDOWS: define dso_local i32 @wmain
+int wmain() {
+  return 1;
+}
+// WINDOWS: define dso_local x86_stdcallcc i32 @WinMain
+int WinMain() {
+  return 1;
+}
+// WINDOWS: define dso_local x86_stdcallcc i32 @wWinMain
+int wWinMain() {
+  return 1;
+}
+// WINDOWS: define dso_local x86_stdcallcc i32 @DllMain
+int DllMain() {
+  return 1;
+}
+#endif // Windows
+
+#ifdef EXPLICITCC
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @wmain
+int __fastcall wmain() {
+  return 1;
+}
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @WinMain
+int __fastcall WinMain() {
+  return 1;
+}
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @wWinMain
+int __fastcall wWinMain() {
+  return 1;
+}
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @DllMain
+int __fastcall DllMain() {
+  return 1;
+}
+#endif // ExplicitCC
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11169,6 +11169,17 @@
   }
 }
 
+static bool isDefaultCDecl(FunctionDecl *FD, Sema &S) {
+  // Default calling convention for MinGW is __cdecl
+  const llvm::Triple &T = S.Context.getTargetInfo().getTriple();
+  if (T.isWindowsGNUEnvironment())
+return true;
+
+  return llvm::StringSwitch(FD->getName())
+  .Cases("main", "wmain", true)
+  .Default(false);
+}
+
 void Sema::CheckMSVCRTEntryPoint(FunctionDecl *FD) {
   QualType T = FD->getType();
   assert(T->isFunctionType() && "function decl is not of function type");
@@ -11183,6 +11194,23 @@
 if (FD->getName() != "DllMain")
   FD->setHasImplicitReturnZero(true);
 
+  // Explicity specified calling conventions are applied to MSVC entry points
+  if (!hasExplicitCallingConv(T)) {
+if (isDefaultCDecl(FD, *this)) {
+  if (FT->getCallConv() != CC_C) {
+FT = Context.adjustFunctionType(FT,
+FT->getExtInfo().withCallingConv(CC_C));
+FD->setType(QualType(FT, 0));
+  }
+} else if (FT->getCallConv() != CC_X86StdCall) {
+  // Default calling convention for WinMain, wWinMain and DllMain is
+  // __stdcall
+  FT = Context.adjustFunctionType(
+  FT, FT->getExtInfo().withCallingConv(CC_X86StdCall));
+  FD->setType(QualType(FT, 0));
+}
+  }
+
   if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) {
 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD;
 FD->setInvalidDecl();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97941: [Reland] "Do not apply calling conventions to MSVC entry points"

2021-03-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 329099.
eandrews edited the summary of this revision.
eandrews added a comment.

Implemented review comment to restrict  __stdcall default calling convention 
(for WinMain, wWinMain, and DllMain) to 32 bit Windows.


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

https://reviews.llvm.org/D97941

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/default_calling_conv.cpp

Index: clang/test/CodeGenCXX/default_calling_conv.cpp
===
--- clang/test/CodeGenCXX/default_calling_conv.cpp
+++ clang/test/CodeGenCXX/default_calling_conv.cpp
@@ -4,6 +4,9 @@
 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s --check-prefix=VECTORCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s --check-prefix=REGCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i686-pc-win32 -fdefault-calling-conv=vectorcall -emit-llvm -o - %s -DWINDOWS | FileCheck %s --check-prefix=WIN32
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fdefault-calling-conv=vectorcall -emit-llvm -o - %s -DWINDOWS | FileCheck %s --check-prefix=WIN64
+// RUN: %clang_cc1 -triple i686-pc-win32 -emit-llvm -o - %s -DEXPLICITCC | FileCheck %s --check-prefix=EXPLICITCC
 
 // CDECL: define{{.*}} void @_Z5test1v
 // FASTCALL: define{{.*}} x86_fastcallcc void @_Z5test1v
@@ -50,3 +53,45 @@
 int main() {
   return 1;
 }
+
+#ifdef WINDOWS
+// WIN32: define dso_local i32 @wmain
+// WIN64: define dso_local i32 @wmain
+int wmain() {
+  return 1;
+}
+// WIN32: define dso_local x86_stdcallcc i32 @WinMain
+// WIN64: define dso_local i32 @WinMain
+int WinMain() {
+  return 1;
+}
+// WIN32: define dso_local x86_stdcallcc i32 @wWinMain
+// WIN64: define dso_local i32 @wWinMain
+int wWinMain() {
+  return 1;
+}
+// WIN32: define dso_local x86_stdcallcc i32 @DllMain
+// WIN64: define dso_local i32 @DllMain
+int DllMain() {
+  return 1;
+}
+#endif // Windows
+
+#ifdef EXPLICITCC
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @wmain
+int __fastcall wmain() {
+  return 1;
+}
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @WinMain
+int __fastcall WinMain() {
+  return 1;
+}
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @wWinMain
+int __fastcall wWinMain() {
+  return 1;
+}
+// EXPLICITCC: define dso_local x86_fastcallcc i32 @DllMain
+int __fastcall DllMain() {
+  return 1;
+}
+#endif // ExplicitCC
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11169,6 +11169,25 @@
   }
 }
 
+static bool isDefaultStdCall(FunctionDecl *FD, Sema &S) {
+
+  // Default calling convention for main and wmain is __cdecl
+  if (FD->getName() == "main" || FD->getName() == "wmain")
+return false;
+
+  // Default calling convention for MinGW is __cdecl
+  const llvm::Triple &T = S.Context.getTargetInfo().getTriple();
+  if (T.isWindowsGNUEnvironment())
+return false;
+
+  // Default calling convention for WinMain, wWinMain and DllMain
+  // is __stdcall on 32 bit Windows
+  if (T.isOSWindows() && T.getArch() == llvm::Triple::x86)
+return true;
+
+  return false;
+}
+
 void Sema::CheckMSVCRTEntryPoint(FunctionDecl *FD) {
   QualType T = FD->getType();
   assert(T->isFunctionType() && "function decl is not of function type");
@@ -11183,6 +11202,21 @@
 if (FD->getName() != "DllMain")
   FD->setHasImplicitReturnZero(true);
 
+  // Explicity specified calling conventions are applied to MSVC entry points
+  if (!hasExplicitCallingConv(T)) {
+if (isDefaultStdCall(FD, *this)) {
+  if (FT->getCallConv() != CC_X86StdCall) {
+FT = Context.adjustFunctionType(
+FT, FT->getExtInfo().withCallingConv(CC_X86StdCall));
+FD->setType(QualType(FT, 0));
+  }
+} else if (FT->getCallConv() != CC_C) {
+  FT = Context.adjustFunctionType(FT,
+  FT->getExtInfo().withCallingConv(CC_C));
+  FD->setType(QualType(FT, 0));
+}
+  }
+
   if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) {
 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD;
 FD->setInvalidDecl();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97941: [Reland] "Do not apply calling conventions to MSVC entry points"

2021-03-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:11206-11207
+} else if (FT->getCallConv() != CC_X86StdCall) {
+  // Default calling convention for WinMain, wWinMain and DllMain is
+  // __stdcall
+  FT = Context.adjustFunctionType(

rnk wrote:
> This should only be done on 32-bit x86 platforms. I think i686-window-msvc is 
> the more special case platform here, so I would recommend making the helper 
> something like `isDefaultStdCall`, which is true for i686-windows-msvc, false 
> for mingw and non-x86 triples, and false for main/wmain.
Thanks for the review @rnk! I think I made the change you requested. 


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

https://reviews.llvm.org/D97941

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


[PATCH] D112663: [clang-repl] Allow Interpreter::getSymbolAddress to take a mangled name.

2021-11-30 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added inline comments.



Comment at: clang/unittests/Interpreter/InterpreterTest.cpp:237-240
+  std::string MangledName = MangleName(TmpltSpec);
+  typedef int (*TemplateSpecFn)(void *);
+  auto fn = (TemplateSpecFn)cantFail(Interp->getSymbolAddress(MangledName));
+  EXPECT_EQ(42, fn(NewA));

v.g.vassilev wrote:
> erichkeane wrote:
> > aaron.ballman wrote:
> > > This test is broken for some of our internal build bots at Intel. I think 
> > > something suspicious is going on here, but I'm not certain of the intent 
> > > behind the test, so I'm not certain the best way to fix it. The behavior 
> > > of the test is that on an x86 Windows machine, sometimes this particular 
> > > test fails:
> > > ```
> > > [ RUN ] IncrementalProcessing.InstantiateTemplate^M
> > > unknown file: error: SEH exception with code 0x3221225477 thrown in the 
> > > test body.^M
> > > [ FAILED ] IncrementalProcessing.InstantiateTemplate (35 ms)^M
> > > ```
> > > but it's not a consistent failure (seems to happen about one out of every 
> > > three runs).
> > > 
> > > `callme` is a templated member function of `B` but here we're trying to 
> > > call it like it's a free function. That's... not good. We could either 
> > > make `callme` a `static` member function so that it can be called in this 
> > > manner, or we could try to come up with a magic incantation to call it as 
> > > a PMF.
> > > 
> > > Can you investigate, @v.g.vassilev? If it is going to take considerable 
> > > time to resolve, it might be worth reverting temporarily. Thanks!
> > To be perhaps succinct, the problem is calling Pointer-to-member-function 
> > as a free-function.  The cast on line 239 is completely invalid, and can't 
> > be done in C++ code itself without UB.
> > 
> > We believe this shows up on x86 in particular since there is ALSO a 
> > calling-convention mismatch here, but this cast to TemplateSpecFn seems 
> > completely invalid to me.
> Thanks for the ping, @aaron.ballman. Does making the function static  fixes 
> it? If it does, please go ahead and commit the fix otherwise I can do it in 
> 12 hours. 
> 
> If it does not fix it, could you share the bot logs or at least the cmake 
> configure line and the platform?
Committed here - https://reviews.llvm.org/rG3ad0c6b75ea5


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

https://reviews.llvm.org/D112663

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


[PATCH] D111566: [SYCL] Fix function pointer address space

2021-11-30 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

ping * 3

Since this patch has been accepted by one code owner, and has been under review 
for over a month, I plan to submit it by the end of the week. If anyone has 
feedback/concerns, please comment on the review.


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

https://reviews.llvm.org/D111566

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


[PATCH] D111566: [SYCL] Fix function pointer address space

2021-12-02 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Thanks for the reviews @dylanmckay and @rjmccall ! I agree that moving the 
logic for functions pointers to `getTargetAddressSpace`  makes sense. However, 
I'm not sure what the consequences are, since that increases the impact of this 
change quite a bit. I'm not sure if I will have the time to deal with any 
issues that arise before I go on vacation for Christmas. I'll take a quick look 
sometime this week, and hopefully its a simple enough change. If not, I can do 
it in a follow-up PR as suggested above, unless someone objects.


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

https://reviews.llvm.org/D111566

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


[PATCH] D141375: [SYCL][OpenMP] Fix compilation errors for unsupported __bf16 intrinsics

2023-01-10 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: mikerice, jyu2, bader, jdoerfert, aaron.ballman.
Herald added subscribers: Naghasan, Anastasia, ebevhan, guansong, yaxunl.
Herald added a project: All.
eandrews requested review of this revision.
Herald added a subscriber: sstefan1.

This patch uses existing deferred diagnostics framework to emit error for 
unsupported type __bf16 in device code. Error is not emitted in host code.


https://reviews.llvm.org/D141375

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaSYCL/bf16.cpp


Index: clang/test/SemaSYCL/bf16.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/bf16.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-unknown-linux-gnu 
-fsycl-is-device -verify -fsyntax-only %s
+
+template 
+__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
+  kernelFunc(); // expected-note {{called by 'kernel}}
+}
+
+void host_ok(void) {
+  __bf16 A;
+}
+
+int main()
+{  host_ok();
+  __bf16 var; // expected-note {{'var' defined here}}
+  kernel([=]() {
+(void)var; // expected-error {{'var' requires 16 bit size '__bf16' type 
support, but target 'spir64' does not support it}}
+int B = sizeof(__bf16);
+  });
+
+  return 0;
+}
+
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1518,9 +1518,10 @@
 break;
   case DeclSpec::TST_half:Result = Context.HalfTy; break;
   case DeclSpec::TST_BFloat16:
-if (!S.Context.getTargetInfo().hasBFloat16Type())
-  S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
-<< "__bf16";
+if (!S.Context.getTargetInfo().hasBFloat16Type() &&
+!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice) &&
+!S.getLangOpts().SYCLIsDevice)
+  S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) << "__bf16";
 Result = Context.BFloat16Ty;
 break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1974,6 +1974,8 @@
 (Ty->isIbm128Type() && !Context.getTargetInfo().hasIbm128Type()) ||
 (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
  !Context.getTargetInfo().hasInt128Type()) ||
+(Ty->isBFloat16Type() && !Context.getTargetInfo().hasBFloat16Type() &&
+ !LangOpts.CUDAIsDevice) ||
 LongDoubleMismatched) {
   PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
   if (D)
Index: clang/lib/AST/ItaniumMangle.cpp
===
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -3050,7 +3050,11 @@
 break;
   }
   case BuiltinType::BFloat16: {
-const TargetInfo *TI = &getASTContext().getTargetInfo();
+const TargetInfo *TI = ((getASTContext().getLangOpts().OpenMP &&
+ getASTContext().getLangOpts().OpenMPIsDevice) ||
+getASTContext().getLangOpts().SYCLIsDevice)
+   ? getASTContext().getAuxTargetInfo()
+   : &getASTContext().getTargetInfo();
 Out << TI->getBFloat16Mangling();
 break;
   }
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2141,6 +2141,11 @@
   if (Target->hasBFloat16Type()) {
 Width = Target->getBFloat16Width();
 Align = Target->getBFloat16Align();
+  } else if ((getLangOpts().SYCLIsDevice ||
+  (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)) &&
+ AuxTarget->hasBFloat16Type()) {
+Width = AuxTarget->getBFloat16Width();
+Align = AuxTarget->getBFloat16Align();
   }
   break;
 case BuiltinType::Float16:


Index: clang/test/SemaSYCL/bf16.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/bf16.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-unknown-linux-gnu -fsycl-is-device -verify -fsyntax-only %s
+
+template 
+__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
+  kernelFunc(); // expected-note {{called by 'kernel}}
+}
+
+void host_ok(void) {
+  __bf16 A;
+}
+
+int main()
+{  host_ok();
+  __bf16 var; // expected-note {{'var' defined here}}
+  kernel([=]() {
+(void)var; // expected-error {{'var' requires 16 bit size '__bf16' type support, but target 'spir64' does not support it}}
+int B = sizeof(__bf16);
+  });
+
+  return 0;
+}
+
Index: clang/lib/Sema/SemaType.cpp
===

[PATCH] D141375: [SYCL][OpenMP] Fix compilation errors for unsupported __bf16 intrinsics

2023-01-11 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D141375#4041360 , @bader wrote:

> LGTM.
> I expect this to be a common issue for all single-source offloading 
> programming models (i.e. CUDA and HIP in addition to SYCL and OpenMP 
> offload). Probably we can generalize the code patterns used in this patch for 
> all of them.

Looks like CUDA added support for the type  - https://reviews.llvm.org/D136311, 
https://reviews.llvm.org/rG678d8946ba2ba790c4c52e96e2134ee136e30057.

>> In addition to that, there are other built-in data types not supported 
>> either by host or device, which are handled similar way. Right?

Yes. Code added here is similar to code added for other unsupported types like 
__float128


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

https://reviews.llvm.org/D141375

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


[PATCH] D141375: [SYCL][OpenMP] Fix compilation errors for unsupported __bf16 intrinsics

2023-01-25 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf81d529f8955: [Clang] Fix compilation errors for unsupported 
__bf16 intrinsics (authored by eandrews).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141375

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaSYCL/bf16.cpp


Index: clang/test/SemaSYCL/bf16.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/bf16.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-unknown-linux-gnu 
-fsycl-is-device -verify -fsyntax-only %s
+
+template 
+__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
+  kernelFunc(); // expected-note {{called by 'kernel}}
+}
+
+void host_ok(void) {
+  __bf16 A;
+}
+
+int main()
+{  host_ok();
+  __bf16 var; // expected-note {{'var' defined here}}
+  kernel([=]() {
+(void)var; // expected-error {{'var' requires 16 bit size '__bf16' type 
support, but target 'spir64' does not support it}}
+int B = sizeof(__bf16);
+  });
+
+  return 0;
+}
+
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1518,9 +1518,10 @@
 break;
   case DeclSpec::TST_half:Result = Context.HalfTy; break;
   case DeclSpec::TST_BFloat16:
-if (!S.Context.getTargetInfo().hasBFloat16Type())
-  S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
-<< "__bf16";
+if (!S.Context.getTargetInfo().hasBFloat16Type() &&
+!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice) &&
+!S.getLangOpts().SYCLIsDevice)
+  S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) << "__bf16";
 Result = Context.BFloat16Ty;
 break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1975,6 +1975,8 @@
 (Ty->isIbm128Type() && !Context.getTargetInfo().hasIbm128Type()) ||
 (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
  !Context.getTargetInfo().hasInt128Type()) ||
+(Ty->isBFloat16Type() && !Context.getTargetInfo().hasBFloat16Type() &&
+ !LangOpts.CUDAIsDevice) ||
 LongDoubleMismatched) {
   PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
   if (D)
Index: clang/lib/AST/ItaniumMangle.cpp
===
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -3051,7 +3051,11 @@
 break;
   }
   case BuiltinType::BFloat16: {
-const TargetInfo *TI = &getASTContext().getTargetInfo();
+const TargetInfo *TI = ((getASTContext().getLangOpts().OpenMP &&
+ getASTContext().getLangOpts().OpenMPIsDevice) ||
+getASTContext().getLangOpts().SYCLIsDevice)
+   ? getASTContext().getAuxTargetInfo()
+   : &getASTContext().getTargetInfo();
 Out << TI->getBFloat16Mangling();
 break;
   }
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2140,6 +2140,11 @@
   if (Target->hasBFloat16Type()) {
 Width = Target->getBFloat16Width();
 Align = Target->getBFloat16Align();
+  } else if ((getLangOpts().SYCLIsDevice ||
+  (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)) &&
+ AuxTarget->hasBFloat16Type()) {
+Width = AuxTarget->getBFloat16Width();
+Align = AuxTarget->getBFloat16Align();
   }
   break;
 case BuiltinType::Float16:


Index: clang/test/SemaSYCL/bf16.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/bf16.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-unknown-linux-gnu -fsycl-is-device -verify -fsyntax-only %s
+
+template 
+__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
+  kernelFunc(); // expected-note {{called by 'kernel}}
+}
+
+void host_ok(void) {
+  __bf16 A;
+}
+
+int main()
+{  host_ok();
+  __bf16 var; // expected-note {{'var' defined here}}
+  kernel([=]() {
+(void)var; // expected-error {{'var' requires 16 bit size '__bf16' type support, but target 'spir64' does not support it}}
+int B = sizeof(__bf16);
+  });
+
+  return 0;
+}
+
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1518,9 +1518,10 @@
 

[PATCH] D141375: [SYCL][OpenMP] Fix compilation errors for unsupported __bf16 intrinsics

2023-01-25 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Thanks for the reviews!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141375

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


[PATCH] D157554: [NFC][Clang] Fix static analyzer concern about null pointer dereference

2023-08-10 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D157554#4577504 , @aaron.ballman 
wrote:

> In D157554#4576720 , @eandrews 
> wrote:
>
>> In D157554#4576478 , 
>> @aaron.ballman wrote:
>>
>>> This feels a bit more like a functional change than a non-functional change 
>>> because it seems like we should be able to test this case (whereas, if we 
>>> think `TC` can never be null in reality, we could add an `assert` for it 
>>> and not add test coverage). That said, I'm not certain how to induce a 
>>> failure here. Adding @erichkeane in case he has ideas.
>>
>> Yea I agree. I see that this is inside 
>> `ReturnTypeRequirement.isTypeConstraint()` so maybe `Param` should always 
>> have a type constraint? I'm just naively guessing here though
>
> As I read the code, I think an assert is sufficient -- if the param is a type 
> constraint, I believe we expect a non-null type constraint and a null one is 
> a sign of a bug.

Alright. I'll make the change then. Thanks!


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

https://reviews.llvm.org/D157554

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


[PATCH] D157454: [NFC][Clang] Fix static analyzer concern about null value dereference

2023-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Pre-merge check fails are unrelated - fatal error C1060: compiler is out of 
heap space


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

https://reviews.llvm.org/D157454

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


[PATCH] D157454: [NFC][Clang] Fix static analyzer concern about null value dereference

2023-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG421c9bbf65b7: [NFC][Clang] Fix static analyzer concern 
(authored by eandrews).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157454

Files:
  clang/lib/CodeGen/CGObjC.cpp


Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -222,6 +222,7 @@
   QualType ResultType = E->getType();
   const ObjCObjectPointerType *InterfacePointerType
 = ResultType->getAsObjCInterfacePointerType();
+  assert(InterfacePointerType && "Unexpected InterfacePointerType - null");
   ObjCInterfaceDecl *Class
 = InterfacePointerType->getObjectType()->getInterface();
   CGObjCRuntime &Runtime = CGM.getObjCRuntime();


Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -222,6 +222,7 @@
   QualType ResultType = E->getType();
   const ObjCObjectPointerType *InterfacePointerType
 = ResultType->getAsObjCInterfacePointerType();
+  assert(InterfacePointerType && "Unexpected InterfacePointerType - null");
   ObjCInterfaceDecl *Class
 = InterfacePointerType->getObjectType()->getInterface();
   CGObjCRuntime &Runtime = CGM.getObjCRuntime();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157885: [NFC][Clang] Fix static analyzer concern about null value derefence

2023-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: aaron.ballman, tahonermann.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
eandrews requested review of this revision.

https://reviews.llvm.org/D157885

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp


Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4459,7 +4459,9 @@
   if (auto *VTSD = dyn_cast(D)) {
 VTSD->setPointOfInstantiation(POI);
   } else if (auto *VD = dyn_cast(D)) {
-VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
+MemberSpecializationInfo *MSInfo = VD->getMemberSpecializationInfo();
+assert(MSInfo && "No member specialization information");
+MSInfo->setPointOfInstantiation(POI);
   } else {
 auto *FD = cast(D);
 if (auto *FTSInfo = FD->TemplateOrSpecialization


Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4459,7 +4459,9 @@
   if (auto *VTSD = dyn_cast(D)) {
 VTSD->setPointOfInstantiation(POI);
   } else if (auto *VD = dyn_cast(D)) {
-VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
+MemberSpecializationInfo *MSInfo = VD->getMemberSpecializationInfo();
+assert(MSInfo && "No member specialization information");
+MSInfo->setPointOfInstantiation(POI);
   } else {
 auto *FD = cast(D);
 if (auto *FTSInfo = FD->TemplateOrSpecialization
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157554: [NFC][Clang] Fix static analyzer concern about null pointer dereference

2023-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 549960.
eandrews added a comment.

Applied review comments


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

https://reviews.llvm.org/D157554

Files:
  clang/lib/Sema/SemaExprCXX.cpp


Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -9072,8 +9072,10 @@
 MultiLevelTemplateArgumentList MLTAL(Param, TAL.asArray(),
  /*Final=*/false);
 MLTAL.addOuterRetainedLevels(TPL->getDepth());
-Expr *IDC = Param->getTypeConstraint()->getImmediatelyDeclaredConstraint();
-ExprResult Constraint = SubstExpr(IDC, MLTAL);
+const TypeConstraint *TC = Param->getTypeConstraint();
+assert(TC && "Type Constraint cannot be null here");
+ExprResult Constraint =
+SubstExpr(TC->getImmediatelyDeclaredConstraint(), MLTAL);
 if (Constraint.isInvalid()) {
   Status = concepts::ExprRequirement::SS_ExprSubstitutionFailure;
 } else {


Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -9072,8 +9072,10 @@
 MultiLevelTemplateArgumentList MLTAL(Param, TAL.asArray(),
  /*Final=*/false);
 MLTAL.addOuterRetainedLevels(TPL->getDepth());
-Expr *IDC = Param->getTypeConstraint()->getImmediatelyDeclaredConstraint();
-ExprResult Constraint = SubstExpr(IDC, MLTAL);
+const TypeConstraint *TC = Param->getTypeConstraint();
+assert(TC && "Type Constraint cannot be null here");
+ExprResult Constraint =
+SubstExpr(TC->getImmediatelyDeclaredConstraint(), MLTAL);
 if (Constraint.isInvalid()) {
   Status = concepts::ExprRequirement::SS_ExprSubstitutionFailure;
 } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157888: [NFC][Clang] Fix static analyzer concern about null value dereference

2023-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: aaron.ballman, tahonermann.
Herald added subscribers: steakhal, abrachet, manas, ASDenysPetrov, martong, 
dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
Herald added a reviewer: NoQ.
Herald added a project: All.
eandrews requested review of this revision.

https://reviews.llvm.org/D157888

Files:
  clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
@@ -653,10 +653,11 @@
   if (Type.isSuppressOnSink()) {
 const ExplodedNode *AcquireNode = getAcquireSite(ErrorNode, Sym, C);
 if (AcquireNode) {
+  const Stmt *S = AcquireNode->getStmtForDiagnostics();
+  assert(S && "Statmement cannot be null.");
   PathDiagnosticLocation LocUsedForUniqueing =
   PathDiagnosticLocation::createBegin(
-  AcquireNode->getStmtForDiagnostics(), C.getSourceManager(),
-  AcquireNode->getLocationContext());
+  S, C.getSourceManager(), AcquireNode->getLocationContext());
 
   R = std::make_unique(
   Type, Msg, ErrorNode, LocUsedForUniqueing,


Index: clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
@@ -653,10 +653,11 @@
   if (Type.isSuppressOnSink()) {
 const ExplodedNode *AcquireNode = getAcquireSite(ErrorNode, Sym, C);
 if (AcquireNode) {
+  const Stmt *S = AcquireNode->getStmtForDiagnostics();
+  assert(S && "Statmement cannot be null.");
   PathDiagnosticLocation LocUsedForUniqueing =
   PathDiagnosticLocation::createBegin(
-  AcquireNode->getStmtForDiagnostics(), C.getSourceManager(),
-  AcquireNode->getLocationContext());
+  S, C.getSourceManager(), AcquireNode->getLocationContext());
 
   R = std::make_unique(
   Type, Msg, ErrorNode, LocUsedForUniqueing,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157554: [NFC][Clang] Fix static analyzer concern about null pointer dereference

2023-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4ada13e4b3e: [NFC][Clang] Fix static analyzer concern about 
null value dereference (authored by eandrews).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157554

Files:
  clang/lib/Sema/SemaExprCXX.cpp


Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -9072,8 +9072,10 @@
 MultiLevelTemplateArgumentList MLTAL(Param, TAL.asArray(),
  /*Final=*/false);
 MLTAL.addOuterRetainedLevels(TPL->getDepth());
-Expr *IDC = Param->getTypeConstraint()->getImmediatelyDeclaredConstraint();
-ExprResult Constraint = SubstExpr(IDC, MLTAL);
+const TypeConstraint *TC = Param->getTypeConstraint();
+assert(TC && "Type Constraint cannot be null here");
+ExprResult Constraint =
+SubstExpr(TC->getImmediatelyDeclaredConstraint(), MLTAL);
 if (Constraint.isInvalid()) {
   Status = concepts::ExprRequirement::SS_ExprSubstitutionFailure;
 } else {


Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -9072,8 +9072,10 @@
 MultiLevelTemplateArgumentList MLTAL(Param, TAL.asArray(),
  /*Final=*/false);
 MLTAL.addOuterRetainedLevels(TPL->getDepth());
-Expr *IDC = Param->getTypeConstraint()->getImmediatelyDeclaredConstraint();
-ExprResult Constraint = SubstExpr(IDC, MLTAL);
+const TypeConstraint *TC = Param->getTypeConstraint();
+assert(TC && "Type Constraint cannot be null here");
+ExprResult Constraint =
+SubstExpr(TC->getImmediatelyDeclaredConstraint(), MLTAL);
 if (Constraint.isInvalid()) {
   Status = concepts::ExprRequirement::SS_ExprSubstitutionFailure;
 } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157554: [NFC][Clang] Fix static analyzer concern about null pointer dereference

2023-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Thanks for the reviews!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157554

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


[PATCH] D157888: [NFC][Clang] Fix static analyzer concern about null value dereference

2023-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D157888#4586126 , @steakhal wrote:

> Hmm. I guess the assertion is to silence some tool. And I think actually that 
> function might very well also return null in some cases.
> Why do you think it cannot or at least should not return null in your 
> context? I couldn't infer this from the context, neither from the description 
> of this patch.
>
> Without that, I would prefer an if to guard the code, instead of asserting 
> this.

`createBegin()` has a call to `getValidSourceLocation()` which dereferences 
this Statement. So in this context Statement cannot be null.

> If getStmtForDiagnostics() in general, never returns null, then shouldn't we 
> mark the API with an appropriate attribute?

`getStmtForDiagnostics()` explicitly returns `nullptr` when none of the cases 
for `ProgramPoint` listed in the function are met. So I am not sure if we can 
just assume this function should never return null.


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

https://reviews.llvm.org/D157888

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


[PATCH] D157885: [NFC][Clang] Fix static analyzer concern about null value derefence

2023-08-14 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc70dab026d37: [NFC][Clang] Fix static analyzer concern about 
null value dereference (authored by eandrews).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157885

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp


Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4459,7 +4459,9 @@
   if (auto *VTSD = dyn_cast(D)) {
 VTSD->setPointOfInstantiation(POI);
   } else if (auto *VD = dyn_cast(D)) {
-VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
+MemberSpecializationInfo *MSInfo = VD->getMemberSpecializationInfo();
+assert(MSInfo && "No member specialization information");
+MSInfo->setPointOfInstantiation(POI);
   } else {
 auto *FD = cast(D);
 if (auto *FTSInfo = FD->TemplateOrSpecialization


Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4459,7 +4459,9 @@
   if (auto *VTSD = dyn_cast(D)) {
 VTSD->setPointOfInstantiation(POI);
   } else if (auto *VD = dyn_cast(D)) {
-VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
+MemberSpecializationInfo *MSInfo = VD->getMemberSpecializationInfo();
+assert(MSInfo && "No member specialization information");
+MSInfo->setPointOfInstantiation(POI);
   } else {
 auto *FD = cast(D);
 if (auto *FTSInfo = FD->TemplateOrSpecialization
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157888: [NFC][Clang] Fix static analyzer concern about null value dereference

2023-08-16 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe62b2fc40d11: [NFC][Clang] Fix static analyzer concern 
(authored by eandrews).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D157888?vs=549962&id=550886#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157888

Files:
  clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
@@ -653,10 +653,11 @@
   if (Type.isSuppressOnSink()) {
 const ExplodedNode *AcquireNode = getAcquireSite(ErrorNode, Sym, C);
 if (AcquireNode) {
+  const Stmt *S = AcquireNode->getStmtForDiagnostics();
+  assert(S && "Statement cannot be null.");
   PathDiagnosticLocation LocUsedForUniqueing =
   PathDiagnosticLocation::createBegin(
-  AcquireNode->getStmtForDiagnostics(), C.getSourceManager(),
-  AcquireNode->getLocationContext());
+  S, C.getSourceManager(), AcquireNode->getLocationContext());
 
   R = std::make_unique(
   Type, Msg, ErrorNode, LocUsedForUniqueing,


Index: clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
@@ -653,10 +653,11 @@
   if (Type.isSuppressOnSink()) {
 const ExplodedNode *AcquireNode = getAcquireSite(ErrorNode, Sym, C);
 if (AcquireNode) {
+  const Stmt *S = AcquireNode->getStmtForDiagnostics();
+  assert(S && "Statement cannot be null.");
   PathDiagnosticLocation LocUsedForUniqueing =
   PathDiagnosticLocation::createBegin(
-  AcquireNode->getStmtForDiagnostics(), C.getSourceManager(),
-  AcquireNode->getLocationContext());
+  S, C.getSourceManager(), AcquireNode->getLocationContext());
 
   R = std::make_unique(
   Type, Msg, ErrorNode, LocUsedForUniqueing,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157888: [NFC][Clang] Fix static analyzer concern about null value dereference

2023-08-16 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp:657
+  const Stmt *S = AcquireNode->getStmtForDiagnostics();
+  assert(S && "Statmement cannot be null.");
   PathDiagnosticLocation LocUsedForUniqueing =

steakhal wrote:
> I think there is a typo in the word statement.
Thanks for the review. I corrected this in the commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157888

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


[PATCH] D157118: [NFC][Clang] Fix static analyzer concerns

2023-08-04 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: aaron.ballman, tahonermann.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a reviewer: NoQ.
Herald added a project: All.
eandrews requested review of this revision.

Fix static analyzer concerns about dereferencing null values


https://reviews.llvm.org/D157118

Files:
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Analysis/PathDiagnostic.cpp


Index: clang/lib/Analysis/PathDiagnostic.cpp
===
--- clang/lib/Analysis/PathDiagnostic.cpp
+++ clang/lib/Analysis/PathDiagnostic.cpp
@@ -584,6 +584,7 @@
 PathDiagnosticLocation::createBegin(const Stmt *S,
 const SourceManager &SM,
 LocationOrAnalysisDeclContext LAC) {
+  assert(S && "Statement cannot be null");
   return PathDiagnosticLocation(getValidSourceLocation(S, LAC),
 SM, SingleLocK);
 }
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -175,6 +175,7 @@
 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
 /// with no newline after the }.
 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
+  assert(Node && "Compound statement cannot be null");
   OS << "{" << NL;
   PrintFPPragmas(Node);
   for (auto *I : Node->body())


Index: clang/lib/Analysis/PathDiagnostic.cpp
===
--- clang/lib/Analysis/PathDiagnostic.cpp
+++ clang/lib/Analysis/PathDiagnostic.cpp
@@ -584,6 +584,7 @@
 PathDiagnosticLocation::createBegin(const Stmt *S,
 const SourceManager &SM,
 LocationOrAnalysisDeclContext LAC) {
+  assert(S && "Statement cannot be null");
   return PathDiagnosticLocation(getValidSourceLocation(S, LAC),
 SM, SingleLocK);
 }
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -175,6 +175,7 @@
 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
 /// with no newline after the }.
 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
+  assert(Node && "Compound statement cannot be null");
   OS << "{" << NL;
   PrintFPPragmas(Node);
   for (auto *I : Node->body())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157429: [NFC] [Clang] Fix static analyzer concern

2023-08-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: aaron.ballman, tahonermann.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a reviewer: NoQ.
Herald added a project: All.
eandrews requested review of this revision.

Fix static analyzer concern about potential null value dereference. 
findBackingIvar() dereferences Prop. PR checks that Prop exists before calling 
the function.


https://reviews.llvm.org/D157429

Files:
  clang/lib/Analysis/BodyFarm.cpp


Index: clang/lib/Analysis/BodyFarm.cpp
===
--- clang/lib/Analysis/BodyFarm.cpp
+++ clang/lib/Analysis/BodyFarm.cpp
@@ -806,7 +806,7 @@
 
   if (!IVar) {
 Prop = MD->findPropertyDecl();
-IVar = findBackingIvar(Prop);
+IVar = Prop? findBackingIvar(Prop) : nullptr;
   }
 
   if (!IVar || !Prop)


Index: clang/lib/Analysis/BodyFarm.cpp
===
--- clang/lib/Analysis/BodyFarm.cpp
+++ clang/lib/Analysis/BodyFarm.cpp
@@ -806,7 +806,7 @@
 
   if (!IVar) {
 Prop = MD->findPropertyDecl();
-IVar = findBackingIvar(Prop);
+IVar = Prop? findBackingIvar(Prop) : nullptr;
   }
 
   if (!IVar || !Prop)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157429: [NFC] [Clang] Fix static analyzer concern

2023-08-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6a4779cc235c: [NFC] Fix static analyzer concern (authored by 
eandrews).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D157429?vs=548317&id=548332#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157429

Files:
  clang/lib/Analysis/BodyFarm.cpp


Index: clang/lib/Analysis/BodyFarm.cpp
===
--- clang/lib/Analysis/BodyFarm.cpp
+++ clang/lib/Analysis/BodyFarm.cpp
@@ -806,7 +806,7 @@
 
   if (!IVar) {
 Prop = MD->findPropertyDecl();
-IVar = findBackingIvar(Prop);
+IVar = Prop ? findBackingIvar(Prop) : nullptr;
   }
 
   if (!IVar || !Prop)


Index: clang/lib/Analysis/BodyFarm.cpp
===
--- clang/lib/Analysis/BodyFarm.cpp
+++ clang/lib/Analysis/BodyFarm.cpp
@@ -806,7 +806,7 @@
 
   if (!IVar) {
 Prop = MD->findPropertyDecl();
-IVar = findBackingIvar(Prop);
+IVar = Prop ? findBackingIvar(Prop) : nullptr;
   }
 
   if (!IVar || !Prop)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157429: [NFC] [Clang] Fix static analyzer concern

2023-08-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

In D157429#4570540 , @aaron.ballman 
wrote:

> LGTM with a small formatting nit.

Thanks for the review! I committed the patch after fixing the formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157429

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


[PATCH] D157454: [NFC][Clang] Fix static analyzer concern about null value dereference

2023-08-08 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: aaron.ballman, tahonermann.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
eandrews requested review of this revision.

InterfacePointerType is dereferenced and should not be null.


https://reviews.llvm.org/D157454

Files:
  clang/lib/CodeGen/CGObjC.cpp


Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -219,9 +219,8 @@
 
   // Generate a reference to the class pointer, which will be the receiver.
   Selector Sel = MethodWithObjects->getSelector();
-  QualType ResultType = E->getType();
-  const ObjCObjectPointerType *InterfacePointerType
-= ResultType->getAsObjCInterfacePointerType();
+  const ObjCObjectPointerType *InterfacePointerType =
+  cast(E->getType());
   ObjCInterfaceDecl *Class
 = InterfacePointerType->getObjectType()->getInterface();
   CGObjCRuntime &Runtime = CGM.getObjCRuntime();


Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -219,9 +219,8 @@
 
   // Generate a reference to the class pointer, which will be the receiver.
   Selector Sel = MethodWithObjects->getSelector();
-  QualType ResultType = E->getType();
-  const ObjCObjectPointerType *InterfacePointerType
-= ResultType->getAsObjCInterfacePointerType();
+  const ObjCObjectPointerType *InterfacePointerType =
+  cast(E->getType());
   ObjCInterfaceDecl *Class
 = InterfacePointerType->getObjectType()->getInterface();
   CGObjCRuntime &Runtime = CGM.getObjCRuntime();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157454: [NFC][Clang] Fix static analyzer concern about null value dereference

2023-08-09 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added inline comments.



Comment at: clang/lib/CodeGen/CGObjC.cpp:222-223
   Selector Sel = MethodWithObjects->getSelector();
-  QualType ResultType = E->getType();
-  const ObjCObjectPointerType *InterfacePointerType
-= ResultType->getAsObjCInterfacePointerType();
+  const ObjCObjectPointerType *InterfacePointerType =
+  cast(E->getType());
   ObjCInterfaceDecl *Class

tahonermann wrote:
> The previous code included a guarantee that 
> `InterfacePointerType->getInterfaceType()` is non-null and this change loses 
> that assurance. Presumably, we never ran into a violation of that guarantee 
> in the past (since a SIGSEGV would likely have occurred below otherwise), but 
> perhaps we should consider an assertion to ensure that guarantee is still met.
Hmmm... I guess in that case it was just make more sense to keep the old code 
and add an assert for InterfacePointerType?


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

https://reviews.llvm.org/D157454

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


  1   2   >