[PATCH] D106577: [clang] Define __STDC_ISO_10646__

2021-08-20 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D106577#2944086 , @aaron.ballman 
wrote:

>> I don't think that scenario is valid. MBCS-to-unicode mappings are a part of 
>> the definition of the MBCS (sometimes officially, sometimes de-facto defined 
>> by major vendors), not in the definition of Unicode.
>
> Isn't that scenario basically the one we're in today where the compiler is 
> unaware of what mappings the library provides?

What I mean is: unicode does not define the mappings of a legacy MBCS byte 
sequence to a unicode character. It's simply out of scope. Only 3 encodings are 
defined by the Unicode standard (UTF-8, UTF-16, UTF-32). Mappings for other 
encodings are defined, instead, either by their own standard, or else simply 
chosen arbitrarily by a vendor.

>> And in fact, we have a real-life example of this: the GB18030 encoding. That 
>> standard specifies 24 characters mappings to private-use-area unicode 
>> codepoints in the most recent version, GB18030-2005. (Which is down from 80 
>> PUA mappings in its predecessor encoding GBK, and 25 in GB18030-2000.) Yet, 
>> a new version of Unicode coming out will not affect that. Rather, I should 
>> say, DID NOT affect that -- all of those 24 characters mapped to PUAs in 
>> GB18030-2005 were actually assigned official unicode codepoints by 2005 
>> (some in Unicode 3.1, some in Unicode 4.1). But no matter -- GB18030 still 
>> maps those to PUA code-points. The only way that can change is if GB18030 
>> gets updated.
>>
>> I do note that some implementations (e.g. glibc) have taken it upon 
>> themselves to modify the official GB18030 character mapping table, and to 
>> decode those 24 codepoints to the newly-defined unicode characters, instead 
>> of the specified PUA codepoints. But there's no way that can be described as 
>> a requirement -- it's not even technically correct!
>
> Does that imply that an implementation supporting that encoding can't define 
> __STDC_ISO_10646__ because it doesn't meet the "has the same value as the 
> short identifier" requirement?

No. The fact that the GB18030 encoding has an unfortunate mapping of its bytes 
to unicode characters does not change anything about `__STD_ISO_10646__`. It 
does not affect, "every character in the Unicode required set, when stored in 
an object of type wchar_t, has the same value as the short identifier of that 
character" at all. All we're talking about here is differences of opinion 
between implementations as to which unicode character a given GB18030 byte 
sequence should to be translated as -- not the way in which a unicode character 
is stored in a wchar_t.

> @jyknight, are you on the WG14 reflectors btw? Would you like to carry on 
> with this discussion over there (or would you like me to convey your 
> viewpoints on your behalf)?

I'm not. I'd be happy to have you convey my viewpoints.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106577

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


[PATCH] D107394: [AIX] "aligned" attribute does not decrease alignment

2021-08-20 Thread Steven Wan via Phabricator via cfe-commits
stevewan updated this revision to Diff 367942.
stevewan added a comment.

Fix typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107394

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
  clang/test/Layout/aix-type-align-and-pack-attr.cpp

Index: clang/test/Layout/aix-type-align-and-pack-attr.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-type-align-and-pack-attr.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+namespace test1 {
+struct __attribute__((__aligned__(2))) S {
+  double d;
+};
+
+S s;
+
+// CHECK: @{{.*}}test1{{.*}}s{{.*}} = global %"struct.test1::S" zeroinitializer, align 8
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2), packed)) S {
+  double d;
+};
+
+S s;
+
+// CHECK: @{{.*}}test2{{.*}}s{{.*}} = global %"struct.test2::S" zeroinitializer, align 2
+} // namespace test2
+
+namespace test3 {
+struct __attribute__((__aligned__(16))) S {
+  double d;
+};
+
+S s;
+
+// CHECK: @{{.*}}test3{{.*}}s{{.*}} = global %"struct.test3::S" zeroinitializer, align 16
+} // namespace test3
+
+namespace test4 {
+struct __attribute__((aligned(2))) SS {
+  double d;
+};
+
+struct S {
+  struct SS ss;
+} s;
+
+// CHECK: @{{.*}}test4{{.*}}s{{.*}} = global %"struct.test4::S" zeroinitializer, align 8
+} // namespace test4
+
+namespace test5 {
+struct __attribute__((aligned(2), packed)) SS {
+  double d;
+};
+
+struct S {
+  struct SS ss;
+} s;
+
+// CHECK: @{{.*}}test5{{.*}}s{{.*}} = global %"struct.test5::S" zeroinitializer, align 2
+} // namespace test5
Index: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
===
--- clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
-// RUN:   FileCheck %s
-
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
-// RUN:   FileCheck %s
-
-namespace test1 {
-struct __attribute__((__aligned__(2))) C {
-  double x;
-} c;
-
-// CHECK: @{{.*}}test1{{.*}}c{{.*}} = global %"struct.test1::C" zeroinitializer, align 8
-} // namespace test1
-
-namespace test2 {
-struct __attribute__((__aligned__(2), packed)) C {
-  double x;
-} c;
-
-// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" zeroinitializer, align 2
-} // namespace test2
-
-namespace test3 {
-struct __attribute__((__aligned__(16))) C {
-  double x;
-} c;
-
-// CHECK: @{{.*}}test3{{.*}}c{{.*}} = global %"struct.test3::C" zeroinitializer, align 16
-} // namespace test3
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1978,7 +1978,7 @@
   // and zero-width bit-fields count as prior members; members of empty class
   // types marked `no_unique_address` are not considered to be prior members.
   CharUnits PreferredAlign = FieldAlign;
-  if (DefaultsToAIXPowerAlignment && !AlignIsRequired &&
+  if (DefaultsToAIXPowerAlignment &&
   (FoundFirstNonOverlappingEmptyFieldForAIX || IsNaturalAlign)) {
 auto performBuiltinTypeAlignmentUpgrade = [&](const BuiltinType *BTy) {
   if (BTy->getKind() == BuiltinType::Double ||
@@ -1989,16 +1989,25 @@
   }
 };
 
-const Type *Ty = D->getType()->getBaseElementTypeUnsafe();
-if (const ComplexType *CTy = Ty->getAs()) {
-  performBuiltinTypeAlignmentUpgrade(CTy->getElementType()->castAs());
-} else if (const BuiltinType *BTy = Ty->getAs()) {
-  performBuiltinTypeAlignmentUpgrade(BTy);
-} else if (const RecordType *RT = Ty->getAs()) {
-  const RecordDecl *RD = RT->getDecl();
-  assert(RD && "Expected non-null RecordDecl.");
-  const ASTRecordLayout &FieldRecord = Context.getASTRecordLayout(RD);
-  PreferredAlign = FieldRecord.getPreferredAlignment();
+const Type *Ty = D->getType().getTypePtr();
+const Type *BaseTy = Ty->getBaseElementTypeUnsafe();
+// When used as part of a typedef, or together with a 'packed' attribute,
+// the 'aligned' attribute can be used to decrease alignment. In that case,
+// it overrides any computed alignment we have, and there is no need to
+// upgrade the alignment.
+if (!(AlignIsRequired &&
+  (Ty->getTypeClass() == Type::Typedef || FieldPacked))) {
+  if (const ComplexType *CTy = BaseTy->getAs()) {
+performBuiltinTypeAlignmentUpgrade(
+CTy->getElementType()->castAs());
+  } else if (const BuiltinType *BTy = BaseTy->getAs()) {
+performBuiltinTypeAlignmentUpgrade(BT

[PATCH] D36850: [ThinLTO] Add norecurse function attribute propagation

2021-08-20 Thread Di Mo via Phabricator via cfe-commits
modimo added a comment.

@tejohnson Indirect calls are not captured in FunctionSummaries in CallGraph or 
in a flag form saying they exist. Also looks like 

 speculative candidates for ICP do make it on the graph. For this analysis we 
need to bail out on indirect calls so I think the simplest way is to add a flag 
indicating the presence of them (In FunFlags?). As for the speculative 
candidates, it's probably not too big of a deal.

In D36850#2940598 , @tejohnson wrote:

> Thanks - I know you are still working on this, but I had a few comments so 
> far. I haven't had a chance to test it yet. Unfortunately, the nounwind 
> propagation shouldn't do much on our side as we disable exceptions internally.

I've been iterating on this with Clang self-build with exceptions enabled. Once 
this gets into a good state logically I'll start testing on some of our 
internal workloads which generally enable exceptions and report back on the 
findings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D36850

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


[PATCH] D108441: [clang] Fix JSON AST output when a filter is used

2021-08-20 Thread William Woodruff via Phabricator via cfe-commits
woodruffw updated this revision to Diff 367938.
woodruffw added a comment.

Updated the AST dump tests for JSON to refute the presence of the `Dumping ` 
prefix.

Also, updated the `gen_ast_dump_json_test.py` generator to work with Python 3 
and to behave better without the presence of the `Dumping: ` sentinels.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108441

Files:
  clang/lib/Frontend/ASTConsumers.cpp
  clang/test/AST/ast-dump-comment-json.cpp
  clang/test/AST/ast-dump-decl-context-json.cpp
  clang/test/AST/ast-dump-decl-json.c
  clang/test/AST/ast-dump-decl-json.m
  clang/test/AST/ast-dump-enum-json.cpp
  clang/test/AST/ast-dump-expr-json.c
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr-json.m
  clang/test/AST/ast-dump-file-line-json.c
  clang/test/AST/ast-dump-funcs-json.cpp
  clang/test/AST/ast-dump-if-json.cpp
  clang/test/AST/ast-dump-macro-json.c
  clang/test/AST/ast-dump-namespace-json.cpp
  clang/test/AST/ast-dump-record-definition-data-json.cpp
  clang/test/AST/ast-dump-records-json.cpp
  clang/test/AST/ast-dump-stmt-json.c
  clang/test/AST/ast-dump-stmt-json.cpp
  clang/test/AST/ast-dump-stmt-json.m
  clang/test/AST/ast-dump-template-decls-json.cpp
  clang/test/AST/ast-dump-temporaries-json.cpp
  clang/test/AST/ast-dump-types-json.cpp
  clang/test/AST/gen_ast_dump_json_test.py

Index: clang/test/AST/gen_ast_dump_json_test.py
===
--- clang/test/AST/gen_ast_dump_json_test.py
+++ clang/test/AST/gen_ast_dump_json_test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from __future__ import print_function
 from collections import OrderedDict
@@ -6,7 +6,6 @@
 import argparse
 import json
 import os
-import pprint
 import re
 import subprocess
 import sys
@@ -21,20 +20,19 @@
 for e in v:
 if isinstance(e, OrderedDict):
 normalize(e)
-elif type(v) is unicode:
-st = v.encode('utf-8')
+elif type(v) is str:
 if v != "0x0" and re.match(r"0x[0-9A-Fa-f]+", v):
-dict_var[k] = u'0x{{.*}}'
+dict_var[k] = '0x{{.*}}'
 elif os.path.isfile(v):
-dict_var[k] = u'{{.*}}'
+dict_var[k] = '{{.*}}'
 else:
-splits = (v.split(u' '))
+splits = (v.split(' '))
 out_splits = []
 for split in splits:
-inner_splits = split.rsplit(u':',2)
+inner_splits = split.rsplit(':',2)
 if os.path.isfile(inner_splits[0]):
 out_splits.append(
-u'{{.*}}:%s:%s'
+'{{.*}}:%s:%s'
 %(inner_splits[1],
   inner_splits[2]))
 continue
@@ -42,11 +40,11 @@
 
 dict_var[k] = ' '.join(out_splits)
 
+
 def filter_json(dict_var, filters, out):
 for k, v in dict_var.items():
-if type(v) is unicode:
-st = v.encode('utf-8')
-if st in filters:
+if type(v) is str:
+if v in filters:
 out.append(dict_var)
 break
 elif isinstance(v, OrderedDict):
@@ -154,33 +152,39 @@
 print("Will use the following filters:", filters)
 
 try:
-json_str = subprocess.check_output(cmd)
+json_str = subprocess.check_output(cmd).decode()
 except Exception as ex:
 print("The clang command failed with %s" % ex)
 return -1
 
 out_asts = []
 if using_ast_dump_filter:
-splits = re.split('Dumping .*:\n', json_str)
-if len(splits) > 1:
-for split in splits[1:]:
-j = json.loads(split.decode('utf-8'), object_pairs_hook=OrderedDict)
+# If we're using a filter, then we might have multiple JSON objects
+# in the output. To parse each out, we use a manual JSONDecoder in
+# "raw" mode and update our location in the string based on where the
+# last document ended.
+decoder = json.JSONDecoder(object_hook=OrderedDict)
+doc_start = 0
+prev_end = 0
+while True:
+try:
+prev_end = doc_start
+(j, doc_start) = decoder.raw_decode(json_str[doc_start:])
+doc_start += prev_end + 1
 normalize(j)
 out_asts.append(j)
+except:
+break
 else:
-j = json.loads(json_str.decode('utf-8'), object_pairs_hook=OrderedDict)
+j = json.loads(json_str, object_pairs_hook=OrderedDict)
 normalize(j)
 
 if len(filters) == 0:
 out_asts.append(j)
 else:
-#assert using_ast_dump_filter is False,\
-#"Does not support using c

[PATCH] D108422: [NFC][clang] Move remaining part of X86Target.def to llvm/Support/X86TargetParser.def

2021-08-20 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke added a comment.

In D108422#2957541 , @erichkeane 
wrote:

> In D108422#2957528 , @RKSimon wrote:
>
>> There's nothing later than CannonLake here - does Intel need to at least 
>> reference up to Tiger/Rocketlake?
>
> @LuoYuanke ^^

Thanks for reminding. We've supported -march=${CPU}, but forgot to update this 
table. We will update it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108422

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


[PATCH] D36850: [ThinLTO] Add norecurse function attribute propagation

2021-08-20 Thread Di Mo via Phabricator via cfe-commits
modimo updated this revision to Diff 367937.
modimo marked 3 inline comments as done.
modimo edited the summary of this revision.
modimo added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adding more test cases and changed logic around weak linkages


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D36850

Files:
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGen/thinlto-distributed-cfi.ll
  clang/test/CodeGen/thinlto-funcattr-prop.ll
  llvm/include/llvm/AsmParser/LLToken.h
  llvm/include/llvm/IR/GlobalValue.h
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/include/llvm/LTO/LTO.h
  llvm/include/llvm/Transforms/IPO/FunctionAttrs.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/ModuleSummaryIndex.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/FunctionAttrs.cpp
  llvm/test/Assembler/thinlto-summary.ll
  llvm/test/ThinLTO/X86/deadstrip.ll
  llvm/test/ThinLTO/X86/dot-dumper.ll
  llvm/test/ThinLTO/X86/dot-dumper2.ll
  llvm/test/ThinLTO/X86/funcattrs-prop-exported-internal.ll
  llvm/test/ThinLTO/X86/funcattrs-prop-indirect.ll
  llvm/test/ThinLTO/X86/funcattrs-prop-undefined.ll
  llvm/test/ThinLTO/X86/funcattrs-prop.ll
  llvm/test/ThinLTO/X86/funcimport_alwaysinline.ll
  llvm/test/ThinLTO/X86/function_entry_count.ll
  llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll
  llvm/test/ThinLTO/X86/weak_externals.ll

Index: llvm/test/ThinLTO/X86/weak_externals.ll
===
--- llvm/test/ThinLTO/X86/weak_externals.ll
+++ llvm/test/ThinLTO/X86/weak_externals.ll
@@ -40,4 +40,3 @@
 define linkonce_odr dso_local dereferenceable(16) %struct.S* @_ZN9SingletonI1SE11getInstanceEv() #0 comdat align 2 {
   ret %struct.S* @_ZZN9SingletonI1SE11getInstanceEvE8instance
 }
-
Index: llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll
===
--- llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll
+++ llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll
@@ -3,15 +3,17 @@
 ; verification error.
 ; RUN: opt -module-summary %s -o %t1.bc
 ; RUN: opt -module-summary %p/Inputs/linkonce_resolution_comdat.ll -o %t2.bc
-; RUN: llvm-lto -thinlto-action=run %t1.bc %t2.bc -exported-symbol=f -exported-symbol=g -thinlto-save-temps=%t3.
+; RUN: llvm-lto -thinlto-action=run -disable-thinlto-funcattrs=0 %t1.bc %t2.bc -exported-symbol=f -exported-symbol=g -thinlto-save-temps=%t3.
 
 ; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s --check-prefix=IMPORT1
 ; RUN: llvm-dis %t3.1.3.imported.bc -o - | FileCheck %s --check-prefix=IMPORT2
 ; Copy from first module is prevailing and converted to weak_odr, copy
 ; from second module is preempted and converted to available_externally and
 ; removed from comdat.
-; IMPORT1: define weak_odr i32 @f(i8* %0) unnamed_addr comdat($c1) {
-; IMPORT2: define available_externally i32 @f(i8* %0) unnamed_addr {
+; IMPORT1: define weak_odr i32 @f(i8* %0) unnamed_addr [[ATTR:#[0-9]+]] comdat($c1) {
+; IMPORT2: define available_externally i32 @f(i8* %0) unnamed_addr [[ATTR:#[0-9]+]] {
+
+; CHECK-DAG: attributes [[ATTR]] = { norecurse nounwind }
 
 ; RUN: llvm-nm -o - < %t1.bc.thinlto.o | FileCheck %s --check-prefix=NM1
 ; NM1: W f
Index: llvm/test/ThinLTO/X86/function_entry_count.ll
===
--- llvm/test/ThinLTO/X86/function_entry_count.ll
+++ llvm/test/ThinLTO/X86/function_entry_count.ll
@@ -2,7 +2,7 @@
 ; RUN: opt -thinlto-bc %p/Inputs/function_entry_count.ll -write-relbf-to-summary -thin-link-bitcode-file=%t2.thinlink.bc -o %t2.bc
 
 ; First perform the thin link on the normal bitcode file.
-; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.o -save-temps -thinlto-synthesize-entry-counts \
+; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.o -save-temps -disable-thinlto-funcattrs=0 -thinlto-synthesize-entry-counts \
 ; RUN: -r=%t1.bc,g, \
 ; RUN: -r=%t1.bc,f,px \
 ; RUN: -r=%t1.bc,h,px \
@@ -10,15 +10,16 @@
 ; RUN: -r=%t2.bc,g,px
 ; RUN: llvm-dis -o - %t.o.1.3.import.bc | FileCheck %s
 
-; RUN: llvm-lto -thinlto-action=run -thinlto-synthesize-entry-counts -exported-symbol=f \
+; RUN: llvm-lto -thinlto-action=run -disable-thinlto-funcattrs=0 -thinlto-synthesize-entry-counts -exported-symbol=f \
 ; RUN: -exported-symbol=g -exported-symbol=h -thinlto-save-temps=%t3. %t1.bc %t2.bc
 ; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s
 
-; CHECK: define void @h() !prof ![[PROF2:[0-9]+]]
-; CHECK: define void @f(i32{{.*}}) !prof ![[PROF1:[0-9]+]]
+; CHECK: define void @h() [[ATTR:#[0-9]+]] !prof ![[PROF2:[0-9]+]]
+; CHECK: define void @f

[PATCH] D108268: [Modules] Change result of reading AST block to llvm::Error instead

2021-08-20 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

`DiagnosticError` looks like a good fit for the task at hand, so it is worth to 
try it. Though I don't know if it would end up in the end convoluted or OK.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108268

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


[PATCH] D108499: [clang][codegen] Don't assert on CurLinkModule for silenced diagnostic

2021-08-20 Thread Rong Xu via Phabricator via cfe-commits
xur added a comment.

This looks fine to me. But I agree you that a more complete fix would be having 
CurLinkModule set for all callers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108499

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


[PATCH] D108483: [OpenMP] Correctly add member expressions to OpenMP info

2021-08-20 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec66ed79f43c: [OpenMP] Correctly add member expressions to 
OpenMP info (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108483

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_names.cpp

Index: clang/test/OpenMP/target_map_names.cpp
===
--- clang/test/OpenMP/target_map_names.cpp
+++ clang/test/OpenMP/target_map_names.cpp
@@ -166,6 +166,10 @@
 }
 
 struct S3 {
+  S3() {
+#pragma omp target data map(alloc : Z[0:64])
+{ }
+  }
   double Z[64];
 };
 
@@ -177,7 +181,10 @@
   { }
 }
 
+
+
 // DEBUG: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] c";s.Z[0:64];{{.*}}.cpp;{{[0-9]+}};{{[0-9]+}};;\00"
+// DEBUG: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] c";this->Z[0:64];{{.*}}.cpp;{{[0-9]+}};{{[0-9]+}};;\00"
 
 // Clang used to mistakenly generate the map name "x" for both x and y on this
 // directive.  Conditions to reproduce the bug: a single map clause has two
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -9435,34 +9435,50 @@
   }
 }
 
+// Try to extract the base declaration from a `this->x` expression if possible.
+static ValueDecl *getDeclFromThisExpr(const Expr *E) {
+  if (!E)
+return nullptr;
+
+  if (const auto *OASE = dyn_cast(E->IgnoreParenCasts()))
+if (const MemberExpr *ME =
+dyn_cast(OASE->getBase()->IgnoreParenImpCasts()))
+  return ME->getMemberDecl();
+  return nullptr;
+}
+
 /// Emit a string constant containing the names of the values mapped to the
 /// offloading runtime library.
 llvm::Constant *
 emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder,
MappableExprsHandler::MappingExprInfo &MapExprs) {
-  llvm::Constant *SrcLocStr;
-  if (!MapExprs.getMapDecl()) {
-SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr();
+
+  if (!MapExprs.getMapDecl() && !MapExprs.getMapExpr())
+return OMPBuilder.getOrCreateDefaultSrcLocStr();
+
+  SourceLocation Loc;
+  if (!MapExprs.getMapDecl() && MapExprs.getMapExpr()) {
+if (const ValueDecl *VD = getDeclFromThisExpr(MapExprs.getMapExpr()))
+  Loc = VD->getLocation();
+else
+  Loc = MapExprs.getMapExpr()->getExprLoc();
   } else {
-std::string ExprName = "";
-if (MapExprs.getMapExpr()) {
-  PrintingPolicy P(CGF.getContext().getLangOpts());
-  llvm::raw_string_ostream OS(ExprName);
-  MapExprs.getMapExpr()->printPretty(OS, nullptr, P);
-  OS.flush();
-} else {
-  ExprName = MapExprs.getMapDecl()->getNameAsString();
-}
+Loc = MapExprs.getMapDecl()->getLocation();
+  }
 
-SourceLocation Loc = MapExprs.getMapDecl()->getLocation();
-PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
-const char *FileName = PLoc.getFilename();
-unsigned Line = PLoc.getLine();
-unsigned Column = PLoc.getColumn();
-SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FileName, ExprName.c_str(),
-Line, Column);
+  std::string ExprName = "";
+  if (MapExprs.getMapExpr()) {
+PrintingPolicy P(CGF.getContext().getLangOpts());
+llvm::raw_string_ostream OS(ExprName);
+MapExprs.getMapExpr()->printPretty(OS, nullptr, P);
+OS.flush();
+  } else {
+ExprName = MapExprs.getMapDecl()->getNameAsString();
   }
-  return SrcLocStr;
+
+  PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
+  return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName.c_str(),
+ PLoc.getLine(), PLoc.getColumn());
 }
 
 /// Emit the arrays used to pass the captures and map information to the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ec66ed7 - [OpenMP] Correctly add member expressions to OpenMP info

2021-08-20 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2021-08-20T20:45:14-04:00
New Revision: ec66ed79f43c3303e462b86eff65d08d6cf8229f

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

LOG: [OpenMP] Correctly add member expressions to OpenMP info

Mapping expressions that have `this` as their base expression aren't
considered a valid base variable and the rest of the runtime expects
this. However, if we have an expression with no value declaration we can
try to extract it manually to provide more helpful debuggin information.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_map_names.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 90fcf2232be2f..5718546b3bb67 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -9435,34 +9435,50 @@ static void emitNonContiguousDescriptor(
   }
 }
 
+// Try to extract the base declaration from a `this->x` expression if possible.
+static ValueDecl *getDeclFromThisExpr(const Expr *E) {
+  if (!E)
+return nullptr;
+
+  if (const auto *OASE = dyn_cast(E->IgnoreParenCasts()))
+if (const MemberExpr *ME =
+dyn_cast(OASE->getBase()->IgnoreParenImpCasts()))
+  return ME->getMemberDecl();
+  return nullptr;
+}
+
 /// Emit a string constant containing the names of the values mapped to the
 /// offloading runtime library.
 llvm::Constant *
 emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder,
MappableExprsHandler::MappingExprInfo &MapExprs) {
-  llvm::Constant *SrcLocStr;
-  if (!MapExprs.getMapDecl()) {
-SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr();
+
+  if (!MapExprs.getMapDecl() && !MapExprs.getMapExpr())
+return OMPBuilder.getOrCreateDefaultSrcLocStr();
+
+  SourceLocation Loc;
+  if (!MapExprs.getMapDecl() && MapExprs.getMapExpr()) {
+if (const ValueDecl *VD = getDeclFromThisExpr(MapExprs.getMapExpr()))
+  Loc = VD->getLocation();
+else
+  Loc = MapExprs.getMapExpr()->getExprLoc();
   } else {
-std::string ExprName = "";
-if (MapExprs.getMapExpr()) {
-  PrintingPolicy P(CGF.getContext().getLangOpts());
-  llvm::raw_string_ostream OS(ExprName);
-  MapExprs.getMapExpr()->printPretty(OS, nullptr, P);
-  OS.flush();
-} else {
-  ExprName = MapExprs.getMapDecl()->getNameAsString();
-}
+Loc = MapExprs.getMapDecl()->getLocation();
+  }
 
-SourceLocation Loc = MapExprs.getMapDecl()->getLocation();
-PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
-const char *FileName = PLoc.getFilename();
-unsigned Line = PLoc.getLine();
-unsigned Column = PLoc.getColumn();
-SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FileName, ExprName.c_str(),
-Line, Column);
+  std::string ExprName = "";
+  if (MapExprs.getMapExpr()) {
+PrintingPolicy P(CGF.getContext().getLangOpts());
+llvm::raw_string_ostream OS(ExprName);
+MapExprs.getMapExpr()->printPretty(OS, nullptr, P);
+OS.flush();
+  } else {
+ExprName = MapExprs.getMapDecl()->getNameAsString();
   }
-  return SrcLocStr;
+
+  PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
+  return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName.c_str(),
+ PLoc.getLine(), PLoc.getColumn());
 }
 
 /// Emit the arrays used to pass the captures and map information to the

diff  --git a/clang/test/OpenMP/target_map_names.cpp 
b/clang/test/OpenMP/target_map_names.cpp
index a96a1e9d87719..92340cd68891e 100644
--- a/clang/test/OpenMP/target_map_names.cpp
+++ b/clang/test/OpenMP/target_map_names.cpp
@@ -166,6 +166,10 @@ void baz() {
 }
 
 struct S3 {
+  S3() {
+#pragma omp target data map(alloc : Z[0:64])
+{ }
+  }
   double Z[64];
 };
 
@@ -177,7 +181,10 @@ void qux() {
   { }
 }
 
+
+
 // DEBUG: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] 
c";s.Z[0:64];{{.*}}.cpp;{{[0-9]+}};{{[0-9]+}};;\00"
+// DEBUG: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] 
c";this->Z[0:64];{{.*}}.cpp;{{[0-9]+}};{{[0-9]+}};;\00"
 
 // Clang used to mistakenly generate the map name "x" for both x and y on this
 // directive.  Conditions to reproduce the bug: a single map clause has two



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


[PATCH] D108377: [asan] Implemented flag to emit intrinsics to optimize ASan callbacks.

2021-08-20 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

The test is still missing?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108377

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


[PATCH] D108499: [clang][codegen] Don't assert on CurLinkModule for silenced diagnostic

2021-08-20 Thread Bob Haarman via Phabricator via cfe-commits
inglorion added a comment.

There are some possible follow-ups here:

1. Making sure CurLinkModule is set in all (or at least more) cases.
2. Addressing the FIXME about warnings and notes.

I have some partial implementations of those ideas, but I figure we can take 
this change first while I figure out the other bits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108499

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


[PATCH] D107850: [asan] Implemented intrinsic for the custom calling convention similar used by HWASan for X86.

2021-08-20 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h:150
 
+namespace AsanAccessInfo {
+

kstoimenov wrote:
> vitalybuka wrote:
> > It's not how enums described here 
> > https://llvm.org/docs/CodingStandards.html#id43
> > Also it's common to use enum class nowerdays.
> > 
> > 
> > However this one does not need to be enum and just "constexpr size_t"
> I wanted to be as close as possible to the HWASan style. Please let me know 
> if you want me to change it. 
They are quite unrelated, no need to violate coding style to match them.

Also packing and unpacking implementation unnecessary separated.
Maybe something like this and keep bit arithmetic in a single cpp file:
```
struct AsanAccessInfo {
  uint8_t AccessSize;
  bool CompileKernel;
  bool IsWrite;
...

  explicit AsanAccessInfo(int64_t packed);
  int64_t Pack() const;
}
```

Also math a little bit simpler if 4bit field is the last



Comment at: llvm/lib/Target/X86/X86MCInstLower.cpp:1426
+  OutStreamer->emitInstruction(MCInstBuilder(X86::AND32ri8)
+   .addReg(X86::ECX)
+   .addReg(X86::ECX)

what is in ECX register here?



Comment at: llvm/lib/Target/X86/X86MCInstLower.cpp:1553-1555
+OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction);
+OutStreamer->emitSymbolAttribute(Sym, MCSA_Weak);
+OutStreamer->emitSymbolAttribute(Sym, MCSA_Hidden);

Tests do not check these attributes.



Comment at: llvm/lib/Target/X86/X86MCInstLower.cpp:1561-1564
+bool CompileKernel = (AccessInfo >> ASanAccessInfo::CompileKernelShift) & 
1;
+int32_t AccessSizeIndex =
+(AccessInfo >> ASanAccessInfo::AccessSizeShift) & 0xf;
+bool IsWrite = (AccessInfo >> ASanAccessInfo::IsWriteShift) & 1;

as-is shifts are in the header, and masks are here, which is not nice.



Comment at: llvm/test/CodeGen/X86/asan-check-memaccess-add.ll:6
+define void @load1(i8* nocapture readonly %x) {
+; CHECK:  callq   __asan_check_load1_rn[[RN1:.*]]
+; CHECK:  callq   __asan_check_store1_rn[[RN1]]

should we also check how we load registers before callq?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107850

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


[PATCH] D108499: [clang][codegen] Don't assert on CurLinkModule for silenced diagnostic

2021-08-20 Thread Bob Haarman via Phabricator via cfe-commits
inglorion created this revision.
inglorion requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes PR51564.

Under certain circumstances, it is possible to enter Clang's
BackendConsumer::DiagnosticHandlerImpl without CurLinkModule set.
For diagnostics of kind DK_Linker, this results in an assert.
However, these diagnostics are never actually surfaced, unless
they are errors. Crashing the compiler for diagnostics we don't
actually surface seems not worth it, so this change moves the
assert below the check so that it only triggers for diagnostics
we actually surface.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108499

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/Inputs/linker-diagnostic1.ll
  clang/test/CodeGen/linker-diagnostic.ll


Index: clang/test/CodeGen/linker-diagnostic.ll
===
--- /dev/null
+++ clang/test/CodeGen/linker-diagnostic.ll
@@ -0,0 +1,15 @@
+; RUN: mkdir -p %t
+; RUN: opt -module-summary -o %t/foo.o %s
+; RUN: opt -module-summary -o %t/bar.o %S/Inputs/linker-diagnostic1.ll
+; RUN: llvm-lto2 run --thinlto-distributed-indexes -r %t/foo.o,foo,plx -r 
%t/bar.o,bar,plx \
+; RUN:   -r %t/bar.o,foo, -o %t/foobar.so %t/foo.o %t/bar.o
+; RUN: %clang -c -o %t/lto.bar.o --target=armv6-none-unknown-eabi -O2 \
+; RUN:   -fthinlto-index=%t/bar.o.thinlto.bc %t/bar.o
+
+target triple = "thumbv6-unknown-linux-gnueabihf"
+target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
+
+define i32 @foo(i32 %x) {
+  %1 = add i32 %x, 1
+  ret i32 %1
+}
Index: clang/test/CodeGen/Inputs/linker-diagnostic1.ll
===
--- /dev/null
+++ clang/test/CodeGen/Inputs/linker-diagnostic1.ll
@@ -0,0 +1,9 @@
+target triple = "armv4-none-unknown-eabi"
+target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
+
+declare i32 @foo(i32)
+
+define i32 @bar(i32 %x) {
+  %1 = tail call i32 @foo(i32 %x)
+  ret i32 %1
+}
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -779,10 +779,10 @@
 ComputeDiagID(Severity, backend_frame_larger_than, DiagID);
 break;
   case DK_Linker:
-assert(CurLinkModule);
 // FIXME: stop eating the warnings and notes.
 if (Severity != DS_Error)
   return;
+assert(CurLinkModule);
 DiagID = diag::err_fe_cannot_link_module;
 break;
   case llvm::DK_OptimizationRemark:


Index: clang/test/CodeGen/linker-diagnostic.ll
===
--- /dev/null
+++ clang/test/CodeGen/linker-diagnostic.ll
@@ -0,0 +1,15 @@
+; RUN: mkdir -p %t
+; RUN: opt -module-summary -o %t/foo.o %s
+; RUN: opt -module-summary -o %t/bar.o %S/Inputs/linker-diagnostic1.ll
+; RUN: llvm-lto2 run --thinlto-distributed-indexes -r %t/foo.o,foo,plx -r %t/bar.o,bar,plx \
+; RUN:   -r %t/bar.o,foo, -o %t/foobar.so %t/foo.o %t/bar.o
+; RUN: %clang -c -o %t/lto.bar.o --target=armv6-none-unknown-eabi -O2 \
+; RUN:   -fthinlto-index=%t/bar.o.thinlto.bc %t/bar.o
+
+target triple = "thumbv6-unknown-linux-gnueabihf"
+target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
+
+define i32 @foo(i32 %x) {
+  %1 = add i32 %x, 1
+  ret i32 %1
+}
Index: clang/test/CodeGen/Inputs/linker-diagnostic1.ll
===
--- /dev/null
+++ clang/test/CodeGen/Inputs/linker-diagnostic1.ll
@@ -0,0 +1,9 @@
+target triple = "armv4-none-unknown-eabi"
+target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
+
+declare i32 @foo(i32)
+
+define i32 @bar(i32 %x) {
+  %1 = tail call i32 @foo(i32 %x)
+  ret i32 %1
+}
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -779,10 +779,10 @@
 ComputeDiagID(Severity, backend_frame_larger_than, DiagID);
 break;
   case DK_Linker:
-assert(CurLinkModule);
 // FIXME: stop eating the warnings and notes.
 if (Severity != DS_Error)
   return;
+assert(CurLinkModule);
 DiagID = diag::err_fe_cannot_link_module;
 break;
   case llvm::DK_OptimizationRemark:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108494: [Driver] Remove discouraged -gcc-toolchain

2021-08-20 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb686fc7a1bea: [Driver] Remove discouraged -gcc-toolchain 
(authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108494

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4301,7 +4301,6 @@
 // These are legacy user-facing driver-level option spellings. They are always
 // aliases for options that are spelled using the more common Unix / GNU flag
 // style of double-dash and equals-joined flags.
-def gcc_toolchain_legacy_spelling : Separate<["-"], "gcc-toolchain">, 
Alias;
 def target_legacy_spelling : Separate<["-"], "target">, Alias;
 
 // Special internal option to handle -Xlinker --no-demangle.


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4301,7 +4301,6 @@
 // These are legacy user-facing driver-level option spellings. They are always
 // aliases for options that are spelled using the more common Unix / GNU flag
 // style of double-dash and equals-joined flags.
-def gcc_toolchain_legacy_spelling : Separate<["-"], "gcc-toolchain">, Alias;
 def target_legacy_spelling : Separate<["-"], "target">, Alias;
 
 // Special internal option to handle -Xlinker --no-demangle.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b686fc7 - [Driver] Remove discouraged -gcc-toolchain

2021-08-20 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-08-20T16:36:42-07:00
New Revision: b686fc7a1bea5847676ee0f4e03d4318b0e9e350

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

LOG: [Driver] Remove discouraged -gcc-toolchain

Space separated driver options are uncommon but Clang traditionally
did not do a good job. --gcc-toolchain= is the preferred form.

This discourage form appears to be rare, so we can just drop it.

Reviewed By: phosek

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a91dacb0ec348..475b0ae088140 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4301,7 +4301,6 @@ def mno_vzeroupper : Flag<["-"], "mno-vzeroupper">, 
Group;
 // These are legacy user-facing driver-level option spellings. They are always
 // aliases for options that are spelled using the more common Unix / GNU flag
 // style of double-dash and equals-joined flags.
-def gcc_toolchain_legacy_spelling : Separate<["-"], "gcc-toolchain">, 
Alias;
 def target_legacy_spelling : Separate<["-"], "target">, Alias;
 
 // Special internal option to handle -Xlinker --no-demangle.



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


[PATCH] D108494: [Driver] Remove discouraged -gcc-toolchain

2021-08-20 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108494

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


[PATCH] D108494: [Driver] Remove discouraged -gcc-toolchain

2021-08-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: luismarques, phosek.
Herald added a subscriber: dang.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Space separated driver options are uncommon but Clang traditionally
did not do a good job. --gcc-toolchain= is the preferred form.

This discourage form appears to be rare, so we can just drop it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108494

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4301,7 +4301,6 @@
 // These are legacy user-facing driver-level option spellings. They are always
 // aliases for options that are spelled using the more common Unix / GNU flag
 // style of double-dash and equals-joined flags.
-def gcc_toolchain_legacy_spelling : Separate<["-"], "gcc-toolchain">, 
Alias;
 def target_legacy_spelling : Separate<["-"], "target">, Alias;
 
 // Special internal option to handle -Xlinker --no-demangle.


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4301,7 +4301,6 @@
 // These are legacy user-facing driver-level option spellings. They are always
 // aliases for options that are spelled using the more common Unix / GNU flag
 // style of double-dash and equals-joined flags.
-def gcc_toolchain_legacy_spelling : Separate<["-"], "gcc-toolchain">, Alias;
 def target_legacy_spelling : Separate<["-"], "target">, Alias;
 
 // Special internal option to handle -Xlinker --no-demangle.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108493: [HIP] Allow capture this pointer in device lambda

2021-08-20 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Sema/SemaCUDA.cpp:881-882
+  } else if (Capture.isThisCapture() && !LangOpts.HIP) {
+// Capture of this pointer is allowed for HIP since this pointer may be
+// pointing to managed memory which is accessible on both device and
+// host sides.

I assume there's no easy way to tell if it's a managed pointer or not.
Capturing a non-managed pointer would still be bad.
Should we make it a warning instead?




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

https://reviews.llvm.org/D108493

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


[clang] 40aab04 - [test] Migrate -gcc-toolchain with space separator to --gcc-toolchain=

2021-08-20 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-08-20T15:24:58-07:00
New Revision: 40aab0412fe7a14781e133627c2bb0a22761eac8

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

LOG: [test] Migrate -gcc-toolchain with space separator to --gcc-toolchain=

Space separated driver options are uncommon but Clang traditionally
did not do a good job. --gcc-toolchain= is the preferred form.

Added: 


Modified: 
clang/test/Driver/fuse-ld.c
clang/test/Driver/gcc-toolchain.cpp
libc/benchmarks/CMakeLists.txt
libcxx/benchmarks/CMakeLists.txt
lldb/packages/Python/lldbsuite/test/make/Android.rules
llvm/docs/HowToCrossCompileBuiltinsOnArm.rst

Removed: 




diff  --git a/clang/test/Driver/fuse-ld.c b/clang/test/Driver/fuse-ld.c
index 74a2e5f4d9654..dfcf31e25ffa6 100644
--- a/clang/test/Driver/fuse-ld.c
+++ b/clang/test/Driver/fuse-ld.c
@@ -60,19 +60,19 @@
 
 // RUN: %clang %s -### -fuse-ld=ld \
 // RUN: -target arm-linux-androideabi \
-// RUN: -gcc-toolchain %S/Inputs/basic_android_tree 2>&1 \
+// RUN: --gcc-toolchain=%S/Inputs/basic_android_tree 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-ANDROID-ARM-LD-TC
 // CHECK-ANDROID-ARM-LD-TC: 
Inputs/basic_android_tree/lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin{{/|\\+}}ld
 
 // RUN: %clang %s -### -fuse-ld=bfd \
 // RUN: -target arm-linux-androideabi \
-// RUN: -gcc-toolchain %S/Inputs/basic_android_tree 2>&1 \
+// RUN: --gcc-toolchain=%S/Inputs/basic_android_tree 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=CHECK-ANDROID-ARM-BFD-TC
 // CHECK-ANDROID-ARM-BFD-TC: 
Inputs/basic_android_tree/lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin{{/|\\+}}ld.bfd
 
 // RUN: %clang %s -### -fuse-ld=gold \
 // RUN: -target arm-linux-androideabi \
-// RUN: -gcc-toolchain %S/Inputs/basic_android_tree 2>&1 \
+// RUN: --gcc-toolchain=%S/Inputs/basic_android_tree 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=CHECK-ANDROID-ARM-GOLD-TC
 // CHECK-ANDROID-ARM-GOLD-TC: 
Inputs/basic_android_tree/lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin{{/|\\+}}ld.gold
 

diff  --git a/clang/test/Driver/gcc-toolchain.cpp 
b/clang/test/Driver/gcc-toolchain.cpp
index 7cdba0841b8cd..e3a1670110a5f 100644
--- a/clang/test/Driver/gcc-toolchain.cpp
+++ b/clang/test/Driver/gcc-toolchain.cpp
@@ -8,7 +8,7 @@
 //
 // Additionally check that the legacy spelling of the flag works.
 // RUN: %clangxx %s -### --target=x86_64-linux-gnu --sysroot= \
-// RUN:   -gcc-toolchain %S/Inputs/ubuntu_14.04_multiarch_tree/usr 
-stdlib=libstdc++ --rtlib=libgcc 2>&1 | \
+// RUN:   --gcc-toolchain=%S/Inputs/ubuntu_14.04_multiarch_tree/usr 
-stdlib=libstdc++ --rtlib=libgcc 2>&1 | \
 // RUN:   FileCheck %s
 //
 // Test for header search toolchain detection.

diff  --git a/libc/benchmarks/CMakeLists.txt b/libc/benchmarks/CMakeLists.txt
index 3eece745096f9..2f06836b0fadd 100644
--- a/libc/benchmarks/CMakeLists.txt
+++ b/libc/benchmarks/CMakeLists.txt
@@ -10,7 +10,7 @@ set(LLVM_LINK_COMPONENTS Support)
 set(GOOGLE_BENCHMARK_TARGET_FLAGS ${BENCHMARK_DIALECT_FLAG})
 if (LIBCXX_BENCHMARK_GCC_TOOLCHAIN)
   set(GOOGLE_BENCHMARK_TARGET_FLAGS
-  -gcc-toolchain ${LIBCXX_BENCHMARK_GCC_TOOLCHAIN})
+  --gcc-toolchain=${LIBCXX_BENCHMARK_GCC_TOOLCHAIN})
 endif()
 string(REPLACE ";" " " GOOGLE_BENCHMARK_TARGET_FLAGS 
"${GOOGLE_BENCHMARK_TARGET_FLAGS}")
 

diff  --git a/libcxx/benchmarks/CMakeLists.txt 
b/libcxx/benchmarks/CMakeLists.txt
index c4b8247da63b1..8e33f8ebcf0cf 100644
--- a/libcxx/benchmarks/CMakeLists.txt
+++ b/libcxx/benchmarks/CMakeLists.txt
@@ -47,7 +47,7 @@ ExternalProject_Add(google-benchmark-libcxx
 set(BENCHMARK_NATIVE_TARGET_FLAGS)
 if (LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN)
   set(BENCHMARK_NATIVE_TARGET_FLAGS
-  -gcc-toolchain ${LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN})
+  --gcc-toolchain=${LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN})
 endif()
 split_list(BENCHMARK_NATIVE_TARGET_FLAGS)
 

diff  --git a/lldb/packages/Python/lldbsuite/test/make/Android.rules 
b/lldb/packages/Python/lldbsuite/test/make/Android.rules
index 7339c22d2e4c4..32f786aa34756 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Android.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Android.rules
@@ -66,8 +66,8 @@ OBJCOPY ?= $(GCC_TOOLCHAIN)/bin/$(TOOL_PREFIX)-objcopy
 ARCHIVER ?= $(GCC_TOOLCHAIN)/bin/$(TOOL_PREFIX)-ar
 
 ifeq "$(findstring clang,$(CC))" "clang"
-   ARCH_CFLAGS += -target $(TRIPLE) -gcc-toolchain $(GCC_TOOLCHAIN)
-   ARCH_LDFLAGS += -target $(TRIPLE) -gcc-toolchain $(GCC_TOOLCHAIN)
+   ARCH_CFLAGS += -target $(TRIPLE) --gcc-toolchain=$(GCC_TOOLCHAIN)
+   ARCH_LDFLAGS += -target $(TRIPLE) --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 
 ARCH_CFLAGS += --sysroot=$(NDK_ROOT

[PATCH] D108268: [Modules] Change result of reading AST block to llvm::Error instead

2021-08-20 Thread Ben Barham via Phabricator via cfe-commits
bnbarham added a comment.

In D108268#2958346 , @vsapsai wrote:

> Not super happy with the complexity `DiagnosedError` introduces, want to 
> consider alternatives first.

Ah yes, I wasn't happy with that either but couldn't come up with a decent 
alternative. I also considered using `DiagnosticError` but we'd need to keep a 
`DiagStorageAllocator` around in that case.

Honestly I don't love `Error` in general. It'd be nice if DiagnosticsEngine 
handled multiple in-flight diagnostics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108268

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


[PATCH] D108493: [HIP] Allow capture this pointer in device lambda

2021-08-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
yaxunl requested review of this revision.

HIP currently diagnose capture of `this` pointer in device lambda in
host member functions. If `this` pointer points to managed memory,
it can be used in both device and host functions. Under this
situation, capturing `this` pointer in device lambda functions
in host member functions is valid usage.


https://reviews.llvm.org/D108493

Files:
  clang/lib/Sema/SemaCUDA.cpp
  clang/test/SemaCUDA/lambda.cu


Index: clang/test/SemaCUDA/lambda.cu
===
--- clang/test/SemaCUDA/lambda.cu
+++ clang/test/SemaCUDA/lambda.cu
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=com %s
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device 
-verify=com,dev,cuda %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev \
+// RUN:   -triple amdgcn-amd-amdhsa -target-cpu gfx906 -x hip %s
 
 #include "Inputs/cuda.h"
 
@@ -7,7 +9,8 @@
 
 template
 __global__ void kernel(F f) { f(); }
-// dev-note@-1 7{{called by 'kernel<(lambda}}
+// dev-note@-1 3{{called by 'kernel<(lambda}}
+// cuda-note@-2 5{{called by 'kernel<(lambda}}
 
 __host__ __device__ void hd(int x);
 
@@ -22,19 +25,23 @@
 kernel<<<1,1>>>([](){ hd(0); });
 
 kernel<<<1,1>>>([=](){ hd(b); });
-// dev-error@-1 {{capture host side class data member by this pointer in 
device or host device lambda function}}
+// cuda-error@-1 {{capture host side class data member by this pointer in 
device or host device lambda function}}
 
 kernel<<<1,1>>>([&](){ hd(b); });
-// dev-error@-1 {{capture host side class data member by this pointer in 
device or host device lambda function}}
+// cuda-error@-1 {{capture host side class data member by this pointer in 
device or host device lambda function}}
 
 kernel<<<1,1>>>([&] __device__ (){ hd(b); });
-// dev-error@-1 {{capture host side class data member by this pointer in 
device or host device lambda function}}
+// cuda-error@-1 {{capture host side class data member by this pointer in 
device or host device lambda function}}
 
 kernel<<<1,1>>>([&](){
   auto f = [&]{ hd(b); };
-  // dev-error@-1 {{capture host side class data member by this pointer in 
device or host device lambda function}}
+  // cuda-error@-1 {{capture host side class data member by this pointer 
in device or host device lambda function}}
   f();
 });
+
+auto lambda1 = [this] __device__ { hd(this->b); };
+// cuda-error@-1 {{capture host side class data member by this pointer in 
device or host device lambda function}}
+kernel<<<1,1>>>(lambda1);
   }
 };
 
Index: clang/lib/Sema/SemaCUDA.cpp
===
--- clang/lib/Sema/SemaCUDA.cpp
+++ clang/lib/Sema/SemaCUDA.cpp
@@ -877,7 +877,10 @@
 SemaDiagnosticBuilder(DiagKind, Capture.getLocation(),
   diag::err_capture_bad_target, Callee, *this)
 << Capture.getVariable();
-  } else if (Capture.isThisCapture()) {
+  } else if (Capture.isThisCapture() && !LangOpts.HIP) {
+// Capture of this pointer is allowed for HIP since this pointer may be
+// pointing to managed memory which is accessible on both device and
+// host sides.
 SemaDiagnosticBuilder(DiagKind, Capture.getLocation(),
   diag::err_capture_bad_target_this_ptr, Callee, 
*this);
   }


Index: clang/test/SemaCUDA/lambda.cu
===
--- clang/test/SemaCUDA/lambda.cu
+++ clang/test/SemaCUDA/lambda.cu
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=com %s
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev,cuda %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev \
+// RUN:   -triple amdgcn-amd-amdhsa -target-cpu gfx906 -x hip %s
 
 #include "Inputs/cuda.h"
 
@@ -7,7 +9,8 @@
 
 template
 __global__ void kernel(F f) { f(); }
-// dev-note@-1 7{{called by 'kernel<(lambda}}
+// dev-note@-1 3{{called by 'kernel<(lambda}}
+// cuda-note@-2 5{{called by 'kernel<(lambda}}
 
 __host__ __device__ void hd(int x);
 
@@ -22,19 +25,23 @@
 kernel<<<1,1>>>([](){ hd(0); });
 
 kernel<<<1,1>>>([=](){ hd(b); });
-// dev-error@-1 {{capture host side class data member by this pointer in device or host device lambda function}}
+// cuda-error@-1 {{capture host side class data member by this pointer in device or host device lambda function}}
 
 kernel<<<1,1>>>([&](){ hd(b); });
-// dev-error@-1 {{capture host side class data member by this pointer in device or host device lambda function}}
+// cuda-error@-1 {{capture host side class data member by this pointer in d

[PATCH] D108268: [Modules] Change result of reading AST block to llvm::Error instead

2021-08-20 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Not super happy with the complexity `DiagnosedError` introduces, want to 
consider alternatives first.




Comment at: clang/lib/Serialization/ASTReader.cpp:3762
+return llvm::createStringError(std::errc::illegal_byte_sequence,
+   "invalid pragma float control record");
   FpPragmaCurrentValue = FPOptionsOverride::getFromOpaqueInt(Record[0]);

Good copy-paste catch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108268

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


[PATCH] D107850: [asan] Implemented intrinsic for the custom calling convention similar used by HWASan for X86.

2021-08-20 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov added a comment.

All tests are passing locally. Should be good to review now.




Comment at: llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h:150
 
+namespace AsanAccessInfo {
+

vitalybuka wrote:
> It's not how enums described here 
> https://llvm.org/docs/CodingStandards.html#id43
> Also it's common to use enum class nowerdays.
> 
> 
> However this one does not need to be enum and just "constexpr size_t"
I wanted to be as close as possible to the HWASan style. Please let me know if 
you want me to change it. 



Comment at: llvm/test/CodeGen/X86/asan-check-memaccess-or.ll:47
+  %2 = bitcast i64* %x to i8*
+  call void @llvm.asan.check.memaccess(i8* %2, i64 2147450880, i32 0,
+   i32 3, i32 3, i32 1)

vitalybuka wrote:
> Is this test out of date? Code has fewer arguments now.
Should be updated now. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107850

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


[PATCH] D108482: [Clang] Fixes instantiation of OpaqueValueExprs (Bug #45964)

2021-08-20 Thread Jason Rice via Phabricator via cfe-commits
ricejasonf updated this revision to Diff 367907.
ricejasonf added a comment.

Fixed the formatting with clang-format


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

https://reviews.llvm.org/D108482

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h


Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -10511,7 +10511,19 @@
 TreeTransform::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
   assert((!E->getSourceExpr() || 
getDerived().AlreadyTransformed(E->getType())) &&
  "opaque value expression requires transformation");
-  return E;
+
+  // Note that SourceExpr can be nullptr
+  ExprResult SourceExpr = TransformExpr(E->getSourceExpr());
+  if (SourceExpr.isInvalid())
+return ExprError();
+  if (SourceExpr.get() == E->getSourceExpr() && !getDerived().AlwaysRebuild()) 
{
+return E;
+  }
+
+  OpaqueValueExpr *New = new (SemaRef.Context)
+  OpaqueValueExpr(E->getExprLoc(), E->getType(), E->getValueKind(),
+  E->getObjectKind(), SourceExpr.get());
+  return New;
 }
 
 template
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -8643,9 +8643,13 @@
 
 case SK_ArrayLoopIndex: {
   Expr *Cur = CurInit.get();
-  Expr *BaseExpr = new (S.Context)
-  OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
-  Cur->getValueKind(), Cur->getObjectKind(), Cur);
+  // prevent nested OpaqueValueExprs
+  Expr *BaseExpr = dyn_cast(Cur);
+  if (!BaseExpr) {
+BaseExpr = new (S.Context)
+OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
+Cur->getValueKind(), Cur->getObjectKind(), Cur);
+  }
   Expr *IndexExpr =
   new (S.Context) ArrayInitIndexExpr(S.Context.getSizeType());
   CurInit = S.CreateBuiltinArraySubscriptExpr(


Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -10511,7 +10511,19 @@
 TreeTransform::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
   assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
  "opaque value expression requires transformation");
-  return E;
+
+  // Note that SourceExpr can be nullptr
+  ExprResult SourceExpr = TransformExpr(E->getSourceExpr());
+  if (SourceExpr.isInvalid())
+return ExprError();
+  if (SourceExpr.get() == E->getSourceExpr() && !getDerived().AlwaysRebuild()) {
+return E;
+  }
+
+  OpaqueValueExpr *New = new (SemaRef.Context)
+  OpaqueValueExpr(E->getExprLoc(), E->getType(), E->getValueKind(),
+  E->getObjectKind(), SourceExpr.get());
+  return New;
 }
 
 template
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -8643,9 +8643,13 @@
 
 case SK_ArrayLoopIndex: {
   Expr *Cur = CurInit.get();
-  Expr *BaseExpr = new (S.Context)
-  OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
-  Cur->getValueKind(), Cur->getObjectKind(), Cur);
+  // prevent nested OpaqueValueExprs
+  Expr *BaseExpr = dyn_cast(Cur);
+  if (!BaseExpr) {
+BaseExpr = new (S.Context)
+OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
+Cur->getValueKind(), Cur->getObjectKind(), Cur);
+  }
   Expr *IndexExpr =
   new (S.Context) ArrayInitIndexExpr(S.Context.getSizeType());
   CurInit = S.CreateBuiltinArraySubscriptExpr(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] 9ae9dd3 - [libunwind] Add UNW_AARCH64_* beside UNW_ARM64_*

2021-08-20 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-08-20T14:26:27-07:00
New Revision: 9ae9dd3fcfb9f471887ea6fbb0d0e8f2b9b46a28

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

LOG: [libunwind] Add UNW_AARCH64_* beside UNW_ARM64_*

The original libunwind project defines UNW_AARCH64_* instead of UNW_ARM64_*.
Rename the enum members to match. This allows some applications with simple
`unw_init_local` usage to migrate to llvm-project libunwind.

Note: the canonical names of `UNW_ARM_D{0..31}` are now `UNW_AARCH64_V{0..31}`,
to match the original libunwind.

UNW_ARM64_* are kept for now for compatibility. Some may be unneeded and can be
cleaned up in the future.

Reviewed By: #libunwind, compnerd

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

Added: 


Modified: 
libunwind/include/libunwind.h
libunwind/src/CompactUnwinder.hpp
libunwind/src/DwarfInstructions.hpp
libunwind/src/DwarfParser.hpp
libunwind/src/Registers.hpp
libunwind/src/Unwind-seh.cpp
libunwind/src/UnwindCursor.hpp

Removed: 




diff  --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index 0feecd7bd6fc3..5ba63e5b7e5b3 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -493,77 +493,150 @@ enum {
 
 // 64-bit ARM64 registers
 enum {
-  UNW_ARM64_X0 = 0,
-  UNW_ARM64_X1 = 1,
-  UNW_ARM64_X2 = 2,
-  UNW_ARM64_X3 = 3,
-  UNW_ARM64_X4 = 4,
-  UNW_ARM64_X5 = 5,
-  UNW_ARM64_X6 = 6,
-  UNW_ARM64_X7 = 7,
-  UNW_ARM64_X8 = 8,
-  UNW_ARM64_X9 = 9,
-  UNW_ARM64_X10 = 10,
-  UNW_ARM64_X11 = 11,
-  UNW_ARM64_X12 = 12,
-  UNW_ARM64_X13 = 13,
-  UNW_ARM64_X14 = 14,
-  UNW_ARM64_X15 = 15,
-  UNW_ARM64_X16 = 16,
-  UNW_ARM64_X17 = 17,
-  UNW_ARM64_X18 = 18,
-  UNW_ARM64_X19 = 19,
-  UNW_ARM64_X20 = 20,
-  UNW_ARM64_X21 = 21,
-  UNW_ARM64_X22 = 22,
-  UNW_ARM64_X23 = 23,
-  UNW_ARM64_X24 = 24,
-  UNW_ARM64_X25 = 25,
-  UNW_ARM64_X26 = 26,
-  UNW_ARM64_X27 = 27,
-  UNW_ARM64_X28 = 28,
-  UNW_ARM64_X29 = 29,
-  UNW_ARM64_FP = 29,
-  UNW_ARM64_X30 = 30,
-  UNW_ARM64_LR = 30,
-  UNW_ARM64_X31 = 31,
-  UNW_ARM64_SP = 31,
-  UNW_ARM64_PC = 32,
-  // reserved block
-  UNW_ARM64_RA_SIGN_STATE = 34,
+  UNW_AARCH64_X0 = 0,
+  UNW_AARCH64_X1 = 1,
+  UNW_AARCH64_X2 = 2,
+  UNW_AARCH64_X3 = 3,
+  UNW_AARCH64_X4 = 4,
+  UNW_AARCH64_X5 = 5,
+  UNW_AARCH64_X6 = 6,
+  UNW_AARCH64_X7 = 7,
+  UNW_AARCH64_X8 = 8,
+  UNW_AARCH64_X9 = 9,
+  UNW_AARCH64_X10 = 10,
+  UNW_AARCH64_X11 = 11,
+  UNW_AARCH64_X12 = 12,
+  UNW_AARCH64_X13 = 13,
+  UNW_AARCH64_X14 = 14,
+  UNW_AARCH64_X15 = 15,
+  UNW_AARCH64_X16 = 16,
+  UNW_AARCH64_X17 = 17,
+  UNW_AARCH64_X18 = 18,
+  UNW_AARCH64_X19 = 19,
+  UNW_AARCH64_X20 = 20,
+  UNW_AARCH64_X21 = 21,
+  UNW_AARCH64_X22 = 22,
+  UNW_AARCH64_X23 = 23,
+  UNW_AARCH64_X24 = 24,
+  UNW_AARCH64_X25 = 25,
+  UNW_AARCH64_X26 = 26,
+  UNW_AARCH64_X27 = 27,
+  UNW_AARCH64_X28 = 28,
+  UNW_AARCH64_X29 = 29,
+  UNW_AARCH64_FP = 29,
+  UNW_AARCH64_X30 = 30,
+  UNW_AARCH64_LR = 30,
+  UNW_AARCH64_X31 = 31,
+  UNW_AARCH64_SP = 31,
+  UNW_AARCH64_PC = 32,
+
   // reserved block
-  UNW_ARM64_D0 = 64,
-  UNW_ARM64_D1 = 65,
-  UNW_ARM64_D2 = 66,
-  UNW_ARM64_D3 = 67,
-  UNW_ARM64_D4 = 68,
-  UNW_ARM64_D5 = 69,
-  UNW_ARM64_D6 = 70,
-  UNW_ARM64_D7 = 71,
-  UNW_ARM64_D8 = 72,
-  UNW_ARM64_D9 = 73,
-  UNW_ARM64_D10 = 74,
-  UNW_ARM64_D11 = 75,
-  UNW_ARM64_D12 = 76,
-  UNW_ARM64_D13 = 77,
-  UNW_ARM64_D14 = 78,
-  UNW_ARM64_D15 = 79,
-  UNW_ARM64_D16 = 80,
-  UNW_ARM64_D17 = 81,
-  UNW_ARM64_D18 = 82,
-  UNW_ARM64_D19 = 83,
-  UNW_ARM64_D20 = 84,
-  UNW_ARM64_D21 = 85,
-  UNW_ARM64_D22 = 86,
-  UNW_ARM64_D23 = 87,
-  UNW_ARM64_D24 = 88,
-  UNW_ARM64_D25 = 89,
-  UNW_ARM64_D26 = 90,
-  UNW_ARM64_D27 = 91,
-  UNW_ARM64_D28 = 92,
-  UNW_ARM64_D29 = 93,
-  UNW_ARM64_D30 = 94,
-  UNW_ARM64_D31 = 95,
+  UNW_AARCH64_RA_SIGN_STATE = 34,
+
+  // FP/vector registers
+  UNW_AARCH64_V0 = 64,
+  UNW_AARCH64_V1 = 65,
+  UNW_AARCH64_V2 = 66,
+  UNW_AARCH64_V3 = 67,
+  UNW_AARCH64_V4 = 68,
+  UNW_AARCH64_V5 = 69,
+  UNW_AARCH64_V6 = 70,
+  UNW_AARCH64_V7 = 71,
+  UNW_AARCH64_V8 = 72,
+  UNW_AARCH64_V9 = 73,
+  UNW_AARCH64_V10 = 74,
+  UNW_AARCH64_V11 = 75,
+  UNW_AARCH64_V12 = 76,
+  UNW_AARCH64_V13 = 77,
+  UNW_AARCH64_V14 = 78,
+  UNW_AARCH64_V15 = 79,
+  UNW_AARCH64_V16 = 80,
+  UNW_AARCH64_V17 = 81,
+  UNW_AARCH64_V18 = 82,
+  UNW_AARCH64_V19 = 83,
+  UNW_AARCH64_V20 = 84,
+  UNW_AARCH64_V21 = 85,
+  UNW_AARCH64_V22 = 86,
+  UNW_AARCH64_V23 = 87,
+  UNW_AARCH64_V24 = 88,
+  UNW_AARCH64_V25 = 89,
+  UNW_AARCH64_V26 = 90,
+  UNW_AARCH64_V27 = 91,
+  UNW_AARCH64_V28 = 92,
+  UNW_AARCH64_V29 = 93,
+  UNW_AARCH64_V30 = 94,
+  UNW_AARCH64_V31 = 95,
+
+  // Compatibility aliases
+  UNW_ARM64_X0 = UNW_AARCH64_X0,
+  UNW_ARM64_X1 = UNW_AARCH64_X1,
+  UNW_ARM64_X2 = UNW_AARCH64_X2,
+  UNW_ARM64_X3 = UNW_

[clang] 644f88a - [NFC] addAttribute(FunctionIndex) => addFnAttribute()

2021-08-20 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2021-08-20T14:18:59-07:00
New Revision: 644f88a25b32600b1a48ba2e8b2f797ffa074193

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

LOG: [NFC] addAttribute(FunctionIndex) => addFnAttribute()

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 50c1e180f574..8c38b4f732f2 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5246,9 +5246,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (const FunctionDecl *FD = dyn_cast_or_null(CurFuncDecl))
 if (FD->hasAttr())
   // All calls within a strictfp function are marked strictfp
-  Attrs =
-Attrs.addAttribute(getLLVMContext(), 
llvm::AttributeList::FunctionIndex,
-   llvm::Attribute::StrictFP);
+  Attrs = Attrs.addFnAttribute(getLLVMContext(), 
llvm::Attribute::StrictFP);
 
   AssumeAlignedAttrEmitter AssumeAlignedAttrEmitter(*this, TargetDecl);
   Attrs = AssumeAlignedAttrEmitter.TryEmitAsCallSiteAttribute(Attrs);



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


[PATCH] D108424: [NFC][clang] Move multiversion resolver code generation to llvm/ subdirectory

2021-08-20 Thread Andrei Elovikov via Phabricator via cfe-commits
a.elovikov updated this revision to Diff 367890.
a.elovikov added a comment.

Fix a bug with not saving builder's insertion point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108424

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  llvm/include/llvm/Transforms/Utils/X86EmitMultiVersionResolver.h
  llvm/lib/Transforms/Utils/CMakeLists.txt
  llvm/lib/Transforms/Utils/X86EmitMultiVersionResolver.cpp

Index: llvm/lib/Transforms/Utils/X86EmitMultiVersionResolver.cpp
===
--- /dev/null
+++ llvm/lib/Transforms/Utils/X86EmitMultiVersionResolver.cpp
@@ -0,0 +1,227 @@
+//===-- X86EmitMultiVersionResolver -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements utitlities to generate code used for CPU dispatch code.
+//
+//===--===//
+
+#include "llvm/Transforms/Utils/X86EmitMultiVersionResolver.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Type.h"
+#include "llvm/Support/X86TargetParser.h"
+
+using namespace llvm;
+using namespace llvm::X86;
+
+Value *llvm::formResolverCondition(IRBuilderBase &Builder,
+   const MultiVersionResolverOption &RO) {
+  llvm::Value *Condition = nullptr;
+
+  if (!RO.Conditions.Architecture.empty())
+Condition = llvm::X86::emitCpuIs(Builder, RO.Conditions.Architecture);
+  if (!RO.Conditions.Features.empty()) {
+llvm::Value *FeatureCond =
+llvm::X86::emitCpuSupports(Builder, RO.Conditions.Features);
+Condition =
+Condition ? Builder.CreateAnd(Condition, FeatureCond) : FeatureCond;
+  }
+  return Condition;
+}
+
+static void CreateMultiVersionResolverReturn(Function *Resolver,
+ IRBuilderBase &Builder,
+ Function *FuncToReturn,
+ bool UseIFunc) {
+  if (UseIFunc) {
+Builder.CreateRet(FuncToReturn);
+return;
+  }
+
+  SmallVector Args;
+  for_each(Resolver->args(), [&](Argument &Arg) { Args.push_back(&Arg); });
+
+  CallInst *Result = Builder.CreateCall(FuncToReturn, Args);
+  Result->setTailCallKind(CallInst::TCK_MustTail);
+
+  if (Resolver->getReturnType()->isVoidTy())
+Builder.CreateRetVoid();
+  else
+Builder.CreateRet(Result);
+}
+
+void llvm::emitMultiVersionResolver(
+Function *Resolver, ArrayRef Options,
+bool UseIFunc) {
+  assert(Triple(Resolver->getParent()->getTargetTriple()).isX86() &&
+ "Only implemented for x86 targets");
+
+  auto &Ctx = Resolver->getContext();
+  // Main function's basic block.
+  BasicBlock *CurBlock = BasicBlock::Create(Ctx, "resolver_entry", Resolver);
+
+  IRBuilder<> Builder(CurBlock, CurBlock->begin());
+  llvm::X86::emitCPUInit(Builder);
+
+  for (const MultiVersionResolverOption &RO : Options) {
+Builder.SetInsertPoint(CurBlock);
+llvm::Value *Condition = formResolverCondition(Builder, RO);
+
+// The 'default' or 'generic' case.
+if (!Condition) {
+  assert(&RO == Options.end() - 1 &&
+ "Default or Generic case must be last");
+  CreateMultiVersionResolverReturn(Resolver, Builder, RO.Fn, UseIFunc);
+  return;
+}
+
+llvm::BasicBlock *RetBlock =
+BasicBlock::Create(Ctx, "resolver_return", Resolver);
+{
+  IRBuilderBase::InsertPointGuard Guard(Builder);
+  Builder.SetInsertPoint(RetBlock);
+  CreateMultiVersionResolverReturn(Resolver, Builder, RO.Fn, UseIFunc);
+}
+CurBlock = BasicBlock::Create(Ctx, "resolver_else", Resolver);
+Builder.CreateCondBr(Condition, RetBlock, CurBlock);
+  }
+
+  // If no generic/default, emit an unreachable.
+  Builder.SetInsertPoint(CurBlock);
+  CallInst *TrapCall = Builder.CreateIntrinsic(Intrinsic::trap, {}, {});
+  TrapCall->setDoesNotReturn();
+  TrapCall->setDoesNotThrow();
+  Builder.CreateUnreachable();
+}
+
+static Type *getCpuModelType(IRBuilderBase &Builder) {
+  Type *Int32Ty = Builder.getInt32Ty();
+
+  // Matching the struct layout from the compiler-rt/libgcc structure that is
+  // filled in:
+  // unsigned int __cpu_vendor;
+  // unsigned int __cpu_type;
+  // unsigned int __cpu_subtype;
+  // unsigned int __cpu_features[1];
+  Type *STy =
+  StructType::get(Int32Ty, Int32Ty, Int32Ty, ArrayType::get(Int32Ty, 1));
+  return STy;
+}
+
+static Value *getOrCreateGlobal(IRBuilderBase &Builder, StringRef

[PATCH] D108483: [OpenMP] Correctly add member expressions to OpenMP info

2021-08-20 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 367887.
jhuber6 added a comment.

Add static.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108483

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_names.cpp

Index: clang/test/OpenMP/target_map_names.cpp
===
--- clang/test/OpenMP/target_map_names.cpp
+++ clang/test/OpenMP/target_map_names.cpp
@@ -166,6 +166,10 @@
 }
 
 struct S3 {
+  S3() {
+#pragma omp target data map(alloc : Z[0:64])
+{ }
+  }
   double Z[64];
 };
 
@@ -177,7 +181,10 @@
   { }
 }
 
+
+
 // DEBUG: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] c";s.Z[0:64];{{.*}}.cpp;{{[0-9]+}};{{[0-9]+}};;\00"
+// DEBUG: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] c";this->Z[0:64];{{.*}}.cpp;{{[0-9]+}};{{[0-9]+}};;\00"
 
 // Clang used to mistakenly generate the map name "x" for both x and y on this
 // directive.  Conditions to reproduce the bug: a single map clause has two
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -9435,34 +9435,50 @@
   }
 }
 
+// Try to extract the base declaration from a `this->x` expression if possible.
+static ValueDecl *getDeclFromThisExpr(const Expr *E) {
+  if (!E)
+return nullptr;
+
+  if (const auto *OASE = dyn_cast(E->IgnoreParenCasts()))
+if (const MemberExpr *ME =
+dyn_cast(OASE->getBase()->IgnoreParenImpCasts()))
+  return ME->getMemberDecl();
+  return nullptr;
+}
+
 /// Emit a string constant containing the names of the values mapped to the
 /// offloading runtime library.
 llvm::Constant *
 emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder,
MappableExprsHandler::MappingExprInfo &MapExprs) {
-  llvm::Constant *SrcLocStr;
-  if (!MapExprs.getMapDecl()) {
-SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr();
+
+  if (!MapExprs.getMapDecl() && !MapExprs.getMapExpr())
+return OMPBuilder.getOrCreateDefaultSrcLocStr();
+
+  SourceLocation Loc;
+  if (!MapExprs.getMapDecl() && MapExprs.getMapExpr()) {
+if (const ValueDecl *VD = getDeclFromThisExpr(MapExprs.getMapExpr()))
+  Loc = VD->getLocation();
+else
+  Loc = MapExprs.getMapExpr()->getExprLoc();
   } else {
-std::string ExprName = "";
-if (MapExprs.getMapExpr()) {
-  PrintingPolicy P(CGF.getContext().getLangOpts());
-  llvm::raw_string_ostream OS(ExprName);
-  MapExprs.getMapExpr()->printPretty(OS, nullptr, P);
-  OS.flush();
-} else {
-  ExprName = MapExprs.getMapDecl()->getNameAsString();
-}
+Loc = MapExprs.getMapDecl()->getLocation();
+  }
 
-SourceLocation Loc = MapExprs.getMapDecl()->getLocation();
-PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
-const char *FileName = PLoc.getFilename();
-unsigned Line = PLoc.getLine();
-unsigned Column = PLoc.getColumn();
-SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FileName, ExprName.c_str(),
-Line, Column);
+  std::string ExprName = "";
+  if (MapExprs.getMapExpr()) {
+PrintingPolicy P(CGF.getContext().getLangOpts());
+llvm::raw_string_ostream OS(ExprName);
+MapExprs.getMapExpr()->printPretty(OS, nullptr, P);
+OS.flush();
+  } else {
+ExprName = MapExprs.getMapDecl()->getNameAsString();
   }
-  return SrcLocStr;
+
+  PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
+  return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName.c_str(),
+ PLoc.getLine(), PLoc.getColumn());
 }
 
 /// Emit the arrays used to pass the captures and map information to the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108483: [OpenMP] Correctly add member expressions to OpenMP info

2021-08-20 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG, one nit.




Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:9439
+// Try to extract the base declaration from a `this->x` expression if possible.
+ValueDecl *getDeclFromThisExpr(const Expr *E) {
+  if (!E)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108483

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


[PATCH] D108483: [OpenMP] Correctly add member expressions to OpenMP info

2021-08-20 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added a reviewer: jdoerfert.
Herald added subscribers: guansong, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Mapping expressions that have `this` as their base expression aren't
considered a valid base variable and the rest of the runtime expects
this. However, if we have an expression with no value declaration we can
try to extract it manually to provide more helpful debuggin information.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108483

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_names.cpp

Index: clang/test/OpenMP/target_map_names.cpp
===
--- clang/test/OpenMP/target_map_names.cpp
+++ clang/test/OpenMP/target_map_names.cpp
@@ -166,6 +166,10 @@
 }
 
 struct S3 {
+  S3() {
+#pragma omp target data map(alloc : Z[0:64])
+{ }
+  }
   double Z[64];
 };
 
@@ -177,7 +181,10 @@
   { }
 }
 
+
+
 // DEBUG: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] c";s.Z[0:64];{{.*}}.cpp;{{[0-9]+}};{{[0-9]+}};;\00"
+// DEBUG: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] c";this->Z[0:64];{{.*}}.cpp;{{[0-9]+}};{{[0-9]+}};;\00"
 
 // Clang used to mistakenly generate the map name "x" for both x and y on this
 // directive.  Conditions to reproduce the bug: a single map clause has two
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -9435,34 +9435,50 @@
   }
 }
 
+// Try to extract the base declaration from a `this->x` expression if possible.
+ValueDecl *getDeclFromThisExpr(const Expr *E) {
+  if (!E)
+return nullptr;
+
+  if (const auto *OASE = dyn_cast(E->IgnoreParenCasts()))
+if (const MemberExpr *ME =
+dyn_cast(OASE->getBase()->IgnoreParenImpCasts()))
+  return ME->getMemberDecl();
+  return nullptr;
+}
+
 /// Emit a string constant containing the names of the values mapped to the
 /// offloading runtime library.
 llvm::Constant *
 emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder,
MappableExprsHandler::MappingExprInfo &MapExprs) {
-  llvm::Constant *SrcLocStr;
-  if (!MapExprs.getMapDecl()) {
-SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr();
+
+  if (!MapExprs.getMapDecl() && !MapExprs.getMapExpr())
+return OMPBuilder.getOrCreateDefaultSrcLocStr();
+
+  SourceLocation Loc;
+  if (!MapExprs.getMapDecl() && MapExprs.getMapExpr()) {
+if (const ValueDecl *VD = getDeclFromThisExpr(MapExprs.getMapExpr()))
+  Loc = VD->getLocation();
+else
+  Loc = MapExprs.getMapExpr()->getExprLoc();
   } else {
-std::string ExprName = "";
-if (MapExprs.getMapExpr()) {
-  PrintingPolicy P(CGF.getContext().getLangOpts());
-  llvm::raw_string_ostream OS(ExprName);
-  MapExprs.getMapExpr()->printPretty(OS, nullptr, P);
-  OS.flush();
-} else {
-  ExprName = MapExprs.getMapDecl()->getNameAsString();
-}
+Loc = MapExprs.getMapDecl()->getLocation();
+  }
 
-SourceLocation Loc = MapExprs.getMapDecl()->getLocation();
-PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
-const char *FileName = PLoc.getFilename();
-unsigned Line = PLoc.getLine();
-unsigned Column = PLoc.getColumn();
-SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FileName, ExprName.c_str(),
-Line, Column);
+  std::string ExprName = "";
+  if (MapExprs.getMapExpr()) {
+PrintingPolicy P(CGF.getContext().getLangOpts());
+llvm::raw_string_ostream OS(ExprName);
+MapExprs.getMapExpr()->printPretty(OS, nullptr, P);
+OS.flush();
+  } else {
+ExprName = MapExprs.getMapDecl()->getNameAsString();
   }
-  return SrcLocStr;
+
+  PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
+  return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName.c_str(),
+ PLoc.getLine(), PLoc.getColumn());
 }
 
 /// Emit the arrays used to pass the captures and map information to the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107850: [asan] Implemented intrinsic for the custom calling convention similar used by HWASan for X86.

2021-08-20 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov updated this revision to Diff 367882.
kstoimenov added a comment.

Upload after updating AddressSanitizer.cpp.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107850

Files:
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Target/X86/X86AsmPrinter.cpp
  llvm/lib/Target/X86/X86AsmPrinter.h
  llvm/lib/Target/X86/X86InstrCompiler.td
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Target/X86/X86RegisterInfo.td
  llvm/test/CodeGen/X86/asan-check-memaccess-add.ll
  llvm/test/CodeGen/X86/asan-check-memaccess-or.ll
  llvm/tools/llvm-exegesis/CMakeLists.txt

Index: llvm/tools/llvm-exegesis/CMakeLists.txt
===
--- llvm/tools/llvm-exegesis/CMakeLists.txt
+++ llvm/tools/llvm-exegesis/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_LINK_COMPONENTS
+  Instrumentation
   MC
   MCParser
   Support
Index: llvm/test/CodeGen/X86/asan-check-memaccess-or.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/asan-check-memaccess-or.ll
@@ -0,0 +1,223 @@
+; RUN: llc < %s | FileCheck %s
+
+target triple = "x86_64-pc-win"
+
+define void @load1(i8* nocapture readonly %x) {
+; CHECK:  callq   __asan_check_load1_rn[[RN1:.*]]
+; CHECK:  callq   __asan_check_store1_rn[[RN1]]
+; CHECK-NEXT: retq
+  call void @llvm.asan.check.memaccess(i8* %x, i32 0)
+  call void @llvm.asan.check.memaccess(i8* %x, i32 32)
+  ret void
+}
+
+define void @load2(i16* nocapture readonly %x) {
+; CHECK:  callq   __asan_check_load2_rn[[RN2:.*]]
+; CHECK:  callq   __asan_check_store2_rn[[RN2]]
+; CHECK-NEXT: retq
+  %1 = ptrtoint i16* %x to i64
+  %2 = bitcast i16* %x to i8*
+  call void @llvm.asan.check.memaccess(i8* %2, i32 2)
+  call void @llvm.asan.check.memaccess(i8* %2, i32 34)
+  ret void
+}
+
+define void @load4(i32* nocapture readonly %x) {
+; CHECK:  callq   __asan_check_load4_rn[[RN4:.*]]
+; CHECK:  callq   __asan_check_store4_rn[[RN4]]
+; CHECK-NEXT: retq
+  %1 = ptrtoint i32* %x to i64
+  %2 = bitcast i32* %x to i8*
+  call void @llvm.asan.check.memaccess(i8* %2, i32 4)
+  call void @llvm.asan.check.memaccess(i8* %2, i32 36)
+  ret void
+}
+define void @load8(i64* nocapture readonly %x) {
+; CHECK:  callq   __asan_check_load8_rn[[RN8:.*]]
+; CHECK:  callq   __asan_check_store8_rn[[RN8]]
+; CHECK-NEXT: retq
+  %1 = ptrtoint i64* %x to i64
+  %2 = bitcast i64* %x to i8*
+  call void @llvm.asan.check.memaccess(i8* %2, i32 6)
+  call void @llvm.asan.check.memaccess(i8* %2, i32 38)
+  ret void
+}
+
+define void @load16(i128* nocapture readonly %x) {
+; CHECK:  callq   __asan_check_load16_rn[[RN16:.*]]
+; CHECK:  callq   __asan_check_store16_rn[[RN16]]
+; CHECK-NEXT: retq
+  %1 = ptrtoint i128* %x to i64
+  %2 = bitcast i128* %x to i8*
+  call void @llvm.asan.check.memaccess(i8* %2, i32 8)
+  call void @llvm.asan.check.memaccess(i8* %2, i32 40)
+  ret void
+}
+
+; CHECK:  __asan_check_load1_rn[[RN1]]:
+; CHECK-NEXT: movq[[REG:.*]], %r8
+; CHECK-NEXT: shrq$3, %r8
+; CHECK-NEXT: orq $17592186044416, %r8{{.*}}
+; CHECK-NEXT: movb(%r8), %r8b
+; CHECK-NEXT: testb   %r8b, %r8b
+; CHECK-NEXT: jne [[EXTRA:.*]]
+; CHECK-NEXT: [[RET:.*]]:
+; CHECK-NEXT: retq
+; CHECK-NEXT: [[EXTRA]]:
+; CHECK-NEXT: pushq   %rcx
+; CHECK-NEXT: movq[[REG]], %rcx
+; CHECK-NEXT: andl$7, %ecx
+; CHECK-NEXT: cmpl%r8d, %ecx
+; CHECK-NEXT: popq%rcx
+; CHECK-NEXT: jl  [[RET]]
+; CHECK-NEXT: movq[[REG:.*]], %rdi
+; CHECK-NEXT: jmp __asan_report_load1
+
+; CHECK:  __asan_check_load2_rn[[RN2]]:
+; CHECK-NEXT: movq[[REG:.*]], %r8
+; CHECK-NEXT: shrq$3, %r8
+; CHECK-NEXT: orq $17592186044416, %r8{{.*}}
+; CHECK-NEXT: movb(%r8), %r8b
+; CHECK-NEXT: testb   %r8b, %r8b
+; CHECK-NEXT: jne [[EXTRA:.*]]
+; CHECK-NEXT: [[RET:.*]]:
+; CHECK-NEXT: retq
+; CHECK-NEXT: [[EXTRA]]:
+; CHECK-NEXT: pushq   %rcx
+; CHECK-NEXT: movq[[REG]], %rcx
+; CHECK-NEXT: andl$7, %ecx
+; CHECK-NEXT: addl$1, %ecx
+; CHECK-NEXT: cmpl%r8d, %ecx
+; CHECK-NEXT: popq%rcx
+; CHECK-NEXT: jl  [[RET]]
+; CHECK-NEXT: movq[[REG:.*]], %rdi
+; CHECK-NEXT: jmp __asan_report_load2
+
+; CHECK:  __asan_check_load4_rn[[RN4]]:
+; CHECK-NEXT: movq[[REG:.*]], %r8
+; CHECK-NEXT: shrq$3, %r8
+; CHECK-NEXT: orq $17592186044416, %r8{{.*}}
+; CHECK-NEXT: movb(%r8), %r8b
+; CHECK-NEXT: testb   %r8b, %r8b
+; CHECK-

[PATCH] D108482: [Clang] Fixes instantiation of OpaqueValueExprs (Bug #45964)

2021-08-20 Thread Jason Rice via Phabricator via cfe-commits
ricejasonf created this revision.
ricejasonf added a reviewer: aaron.ballman.
ricejasonf added a project: clang.
ricejasonf requested review of this revision.
Herald added a subscriber: cfe-commits.

The structured bindings decomposition of a non-dependent array in a dependent 
context (a template) were, upon instantiation, creating nested OpaqueValueExprs 
that would trigger assertions in CodeGen. Additionally the OpaqueValuesExpr's 
contained SourceExpr is being emitted in CodeGen, but there was no code for its 
transform in template instantiation. This would trigger other assertions such 
as when emitting a DeclRefExpr that refers to a VarDecl that is not marked as 
ODR-used.

This is all based on cursory deduction, but with the way the code flows from 
SemaTemplateInstantiate back to SemaInit, it is apparent that the nesting of 
OpaqueValueExpr is unintentional.

This commit fixes https://bugs.llvm.org/show_bug.cgi?id=45964 and possible 
other issues involving OpaqueValueExprs in template instantiations might be 
resolved.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108482

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h


Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -10511,7 +10511,19 @@
 TreeTransform::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
   assert((!E->getSourceExpr() || 
getDerived().AlreadyTransformed(E->getType())) &&
  "opaque value expression requires transformation");
-  return E;
+
+  // Note that SourceExpr can be nullptr
+  ExprResult SourceExpr = TransformExpr(E->getSourceExpr());
+  if (SourceExpr.isInvalid()) return ExprError();
+  if (SourceExpr.get() == E->getSourceExpr() && !getDerived().AlwaysRebuild()) 
{
+return E;
+  }
+
+  OpaqueValueExpr *New =
+new (SemaRef.Context) OpaqueValueExpr(E->getExprLoc(), E->getType(),
+  E->getValueKind(), 
E->getObjectKind(),
+  SourceExpr.get());
+  return New;
 }
 
 template
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -8643,9 +8643,13 @@
 
 case SK_ArrayLoopIndex: {
   Expr *Cur = CurInit.get();
-  Expr *BaseExpr = new (S.Context)
-  OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
-  Cur->getValueKind(), Cur->getObjectKind(), Cur);
+  // prevent nested OpaqueValueExprs
+  Expr *BaseExpr = dyn_cast(Cur);
+  if (!BaseExpr) {
+BaseExpr = new (S.Context)
+OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
+Cur->getValueKind(), Cur->getObjectKind(), Cur);
+  }
   Expr *IndexExpr =
   new (S.Context) ArrayInitIndexExpr(S.Context.getSizeType());
   CurInit = S.CreateBuiltinArraySubscriptExpr(


Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -10511,7 +10511,19 @@
 TreeTransform::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
   assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
  "opaque value expression requires transformation");
-  return E;
+
+  // Note that SourceExpr can be nullptr
+  ExprResult SourceExpr = TransformExpr(E->getSourceExpr());
+  if (SourceExpr.isInvalid()) return ExprError();
+  if (SourceExpr.get() == E->getSourceExpr() && !getDerived().AlwaysRebuild()) {
+return E;
+  }
+
+  OpaqueValueExpr *New =
+new (SemaRef.Context) OpaqueValueExpr(E->getExprLoc(), E->getType(),
+  E->getValueKind(), E->getObjectKind(),
+  SourceExpr.get());
+  return New;
 }
 
 template
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -8643,9 +8643,13 @@
 
 case SK_ArrayLoopIndex: {
   Expr *Cur = CurInit.get();
-  Expr *BaseExpr = new (S.Context)
-  OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
-  Cur->getValueKind(), Cur->getObjectKind(), Cur);
+  // prevent nested OpaqueValueExprs
+  Expr *BaseExpr = dyn_cast(Cur);
+  if (!BaseExpr) {
+BaseExpr = new (S.Context)
+OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(),
+Cur->getValueKind(), Cur->getObjectKind(), Cur);
+  }
   Expr *IndexExpr =
   new (S.Context) ArrayInitIndexExpr(S.Context.getSizeType());
   CurInit = S.CreateBuiltinArraySubscriptExpr(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailm

[PATCH] D108377: [asan] Implemented flag to emit intrinsics to optimize ASan callbacks.

2021-08-20 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov updated this revision to Diff 367881.
kstoimenov added a comment.

This time AddressSanitizer.cpp should be updated for real.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108377

Files:
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -348,6 +348,10 @@
 static cl::opt ClOpt("asan-opt", cl::desc("Optimize instrumentation"),
cl::Hidden, cl::init(true));
 
+static cl::opt ClOptimizeCallbacks("asan-optimize-callbacks",
+ cl::desc("Optimize callbacks"),
+ cl::Hidden, cl::init(false));
+
 static cl::opt ClOptSameTemp(
 "asan-opt-same-temp", cl::desc("Instrument the same temp just once"),
 cl::Hidden, cl::init(true));
@@ -634,6 +638,7 @@
 C = &(M.getContext());
 LongSize = M.getDataLayout().getPointerSizeInBits();
 IntptrTy = Type::getIntNTy(*C, LongSize);
+Int8PtrTy = Type::getInt8PtrTy(*C);
 TargetTriple = Triple(M.getTargetTriple());
 
 Mapping = getShadowMapping(TargetTriple, LongSize, this->CompileKernel);
@@ -724,6 +729,7 @@
   bool UseAfterScope;
   AsanDetectStackUseAfterReturnMode UseAfterReturn;
   Type *IntptrTy;
+  Type *Int8PtrTy;
   ShadowMapping Mapping;
   FunctionCallee AsanHandleNoReturnFunc;
   FunctionCallee AsanPtrCmpFunction, AsanPtrSubFunction;
@@ -1745,14 +1751,26 @@
   IRBuilder<> IRB(InsertBefore);
   Value *AddrLong = IRB.CreatePointerCast(Addr, IntptrTy);
   size_t AccessSizeIndex = TypeSizeToSizeIndex(TypeSize);
+  const int32_t AccessInfo =
+  (CompileKernel << ASanAccessInfo::CompileKernelShift) +
+  (IsWrite << ASanAccessInfo::IsWriteShift) +
+  (AccessSizeIndex << ASanAccessInfo::AccessSizeShift);
 
   if (UseCalls) {
-if (Exp == 0)
-  IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex],
- AddrLong);
-else
-  IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][1][AccessSizeIndex],
- {AddrLong, ConstantInt::get(IRB.getInt32Ty(), Exp)});
+if (ClOptimizeCallbacks) {
+  Value *Ptr8 = IRB.CreatePointerCast(Addr, Int8PtrTy);
+  Module *M = IRB.GetInsertBlock()->getParent()->getParent();
+  IRB.CreateCall(
+  Intrinsic::getDeclaration(M, Intrinsic::asan_check_memaccess),
+  {Ptr8, ConstantInt::get(IRB.getInt32Ty(), AccessInfo)});
+} else {
+  if (Exp == 0)
+IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex],
+   AddrLong);
+  else
+IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][1][AccessSizeIndex],
+   {AddrLong, ConstantInt::get(IRB.getInt32Ty(), Exp)});
+}
 return;
   }
 


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -348,6 +348,10 @@
 static cl::opt ClOpt("asan-opt", cl::desc("Optimize instrumentation"),
cl::Hidden, cl::init(true));
 
+static cl::opt ClOptimizeCallbacks("asan-optimize-callbacks",
+ cl::desc("Optimize callbacks"),
+ cl::Hidden, cl::init(false));
+
 static cl::opt ClOptSameTemp(
 "asan-opt-same-temp", cl::desc("Instrument the same temp just once"),
 cl::Hidden, cl::init(true));
@@ -634,6 +638,7 @@
 C = &(M.getContext());
 LongSize = M.getDataLayout().getPointerSizeInBits();
 IntptrTy = Type::getIntNTy(*C, LongSize);
+Int8PtrTy = Type::getInt8PtrTy(*C);
 TargetTriple = Triple(M.getTargetTriple());
 
 Mapping = getShadowMapping(TargetTriple, LongSize, this->CompileKernel);
@@ -724,6 +729,7 @@
   bool UseAfterScope;
   AsanDetectStackUseAfterReturnMode UseAfterReturn;
   Type *IntptrTy;
+  Type *Int8PtrTy;
   ShadowMapping Mapping;
   FunctionCallee AsanHandleNoReturnFunc;
   FunctionCallee AsanPtrCmpFunction, AsanPtrSubFunction;
@@ -1745,14 +1751,26 @@
   IRBuilder<> IRB(InsertBefore);
   Value *AddrLong = IRB.CreatePointerCast(Addr, IntptrTy);
   size_t AccessSizeIndex = TypeSizeToSizeIndex(TypeSize);
+  const int32_t AccessInfo =
+  (CompileKernel << ASanAccessInfo::CompileKernelShift) +
+  (IsWrite << ASanAccessInfo::IsWriteShift) +
+  (AccessSizeIndex << ASanAccessInfo::AccessSizeShift);
 
   if (UseCalls) {
-if (Exp == 0)
-  IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex],
- AddrLong);
-else
-  IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][1][Ac

[clang] 5ca7131 - [DebugInfo] convert btf_tag attrs to DI annotations for record fields

2021-08-20 Thread Yonghong Song via cfe-commits

Author: Yonghong Song
Date: 2021-08-20T12:52:51-07:00
New Revision: 5ca7131eb369949ee3adf2d3a562bf7e56ca7422

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

LOG: [DebugInfo] convert btf_tag attrs to DI annotations for record fields

Generate btf_tag annotations for record fields. The annotations
are represented as an DINodeArray in DebugInfo.

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

Added: 
clang/test/CodeGen/attr-btf_tag-field.c

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 967fa7f1493a..989945a1b4ff 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1377,16 +1377,16 @@ llvm::DIType *CGDebugInfo::createBitFieldType(const 
FieldDecl *BitFieldDecl,
 Offset = BitFieldInfo.StorageSize - BitFieldInfo.Size - Offset;
   uint64_t OffsetInBits = StorageOffsetInBits + Offset;
   llvm::DINode::DIFlags Flags = getAccessFlag(BitFieldDecl->getAccess(), RD);
+  llvm::DINodeArray Annotations = CollectBTFTagAnnotations(BitFieldDecl);
   return DBuilder.createBitFieldMemberType(
   RecordTy, Name, File, Line, SizeInBits, OffsetInBits, 
StorageOffsetInBits,
-  Flags, DebugType);
+  Flags, DebugType, Annotations);
 }
 
-llvm::DIType *
-CGDebugInfo::createFieldType(StringRef name, QualType type, SourceLocation loc,
- AccessSpecifier AS, uint64_t offsetInBits,
- uint32_t AlignInBits, llvm::DIFile *tunit,
- llvm::DIScope *scope, const RecordDecl *RD) {
+llvm::DIType *CGDebugInfo::createFieldType(
+StringRef name, QualType type, SourceLocation loc, AccessSpecifier AS,
+uint64_t offsetInBits, uint32_t AlignInBits, llvm::DIFile *tunit,
+llvm::DIScope *scope, const RecordDecl *RD, llvm::DINodeArray Annotations) 
{
   llvm::DIType *debugType = getOrCreateType(type, tunit);
 
   // Get the location for the field.
@@ -1404,7 +1404,7 @@ CGDebugInfo::createFieldType(StringRef name, QualType 
type, SourceLocation loc,
 
   llvm::DINode::DIFlags flags = getAccessFlag(AS, RD);
   return DBuilder.createMemberType(scope, name, file, line, SizeInBits, Align,
-   offsetInBits, flags, debugType);
+   offsetInBits, flags, debugType, 
Annotations);
 }
 
 void CGDebugInfo::CollectRecordLambdaFields(
@@ -1494,9 +1494,10 @@ void CGDebugInfo::CollectRecordNormalField(
 FieldType = createBitFieldType(field, RecordTy, RD);
   } else {
 auto Align = getDeclAlignIfRequired(field, CGM.getContext());
+llvm::DINodeArray Annotations = CollectBTFTagAnnotations(field);
 FieldType =
 createFieldType(name, type, field->getLocation(), field->getAccess(),
-OffsetInBits, Align, tunit, RecordTy, RD);
+OffsetInBits, Align, tunit, RecordTy, RD, Annotations);
   }
 
   elements.push_back(FieldType);
@@ -2064,6 +2065,9 @@ llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
 }
 
 llvm::DINodeArray CGDebugInfo::CollectBTFTagAnnotations(const Decl *D) {
+  if (!D->hasAttr())
+return nullptr;
+
   SmallVector Annotations;
   for (const auto *I : D->specific_attrs()) {
 llvm::Metadata *Ops[2] = {
@@ -3446,10 +3450,7 @@ llvm::DICompositeType 
*CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
 Flags |= llvm::DINode::FlagExportSymbols;
   }
 
-  llvm::DINodeArray Annotations = nullptr;
-  if (D->hasAttr())
-Annotations = CollectBTFTagAnnotations(D);
-
+  llvm::DINodeArray Annotations = CollectBTFTagAnnotations(D);
   llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
   getTagForRecord(RD), RDName, RDContext, DefUnit, Line, 0, Size, Align,
   Flags, Identifier, Annotations);

diff  --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index c0674b4511c7..0d22accb93b6 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -299,7 +299,8 @@ class CGDebugInfo {
 SourceLocation loc, AccessSpecifier AS,
 uint64_t offsetInBits, uint32_t AlignInBits,
 llvm::DIFile *tunit, llvm::DIScope *scope,
-const RecordDecl *RD = nullptr);
+const RecordDecl *RD = nullptr,
+llvm::DINodeArray Annotations = nullptr);
 
   llvm::DIType *createFieldType(StringRef name, QualType type,
 SourceLocation loc, AccessSpecifier AS,

diff  --git a/clang/test/CodeGen/attr-btf_tag-field.c 
b/clang/test/CodeGen/att

[PATCH] D107850: [asan] Implemented intrinsic for the custom calling convention similar used by HWASan for X86.

2021-08-20 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov updated this revision to Diff 367876.
kstoimenov added a comment.
Herald added a subscriber: mgorny.

Moved back to using AccessInfo and fixed the tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107850

Files:
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Target/X86/X86AsmPrinter.cpp
  llvm/lib/Target/X86/X86AsmPrinter.h
  llvm/lib/Target/X86/X86InstrCompiler.td
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Target/X86/X86RegisterInfo.td
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/CodeGen/X86/asan-check-memaccess-add.ll
  llvm/test/CodeGen/X86/asan-check-memaccess-or.ll
  llvm/tools/llvm-exegesis/CMakeLists.txt

Index: llvm/tools/llvm-exegesis/CMakeLists.txt
===
--- llvm/tools/llvm-exegesis/CMakeLists.txt
+++ llvm/tools/llvm-exegesis/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_LINK_COMPONENTS
+  Instrumentation
   MC
   MCParser
   Support
Index: llvm/test/CodeGen/X86/asan-check-memaccess-or.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/asan-check-memaccess-or.ll
@@ -0,0 +1,223 @@
+; RUN: llc < %s | FileCheck %s
+
+target triple = "x86_64-pc-win"
+
+define void @load1(i8* nocapture readonly %x) {
+; CHECK:  callq   __asan_check_load1_rn[[RN1:.*]]
+; CHECK:  callq   __asan_check_store1_rn[[RN1]]
+; CHECK-NEXT: retq
+  call void @llvm.asan.check.memaccess(i8* %x, i32 0)
+  call void @llvm.asan.check.memaccess(i8* %x, i32 32)
+  ret void
+}
+
+define void @load2(i16* nocapture readonly %x) {
+; CHECK:  callq   __asan_check_load2_rn[[RN2:.*]]
+; CHECK:  callq   __asan_check_store2_rn[[RN2]]
+; CHECK-NEXT: retq
+  %1 = ptrtoint i16* %x to i64
+  %2 = bitcast i16* %x to i8*
+  call void @llvm.asan.check.memaccess(i8* %2, i32 2)
+  call void @llvm.asan.check.memaccess(i8* %2, i32 34)
+  ret void
+}
+
+define void @load4(i32* nocapture readonly %x) {
+; CHECK:  callq   __asan_check_load4_rn[[RN4:.*]]
+; CHECK:  callq   __asan_check_store4_rn[[RN4]]
+; CHECK-NEXT: retq
+  %1 = ptrtoint i32* %x to i64
+  %2 = bitcast i32* %x to i8*
+  call void @llvm.asan.check.memaccess(i8* %2, i32 4)
+  call void @llvm.asan.check.memaccess(i8* %2, i32 36)
+  ret void
+}
+define void @load8(i64* nocapture readonly %x) {
+; CHECK:  callq   __asan_check_load8_rn[[RN8:.*]]
+; CHECK:  callq   __asan_check_store8_rn[[RN8]]
+; CHECK-NEXT: retq
+  %1 = ptrtoint i64* %x to i64
+  %2 = bitcast i64* %x to i8*
+  call void @llvm.asan.check.memaccess(i8* %2, i32 6)
+  call void @llvm.asan.check.memaccess(i8* %2, i32 38)
+  ret void
+}
+
+define void @load16(i128* nocapture readonly %x) {
+; CHECK:  callq   __asan_check_load16_rn[[RN16:.*]]
+; CHECK:  callq   __asan_check_store16_rn[[RN16]]
+; CHECK-NEXT: retq
+  %1 = ptrtoint i128* %x to i64
+  %2 = bitcast i128* %x to i8*
+  call void @llvm.asan.check.memaccess(i8* %2, i32 8)
+  call void @llvm.asan.check.memaccess(i8* %2, i32 40)
+  ret void
+}
+
+; CHECK:  __asan_check_load1_rn[[RN1]]:
+; CHECK-NEXT: movq[[REG:.*]], %r8
+; CHECK-NEXT: shrq$3, %r8
+; CHECK-NEXT: orq $17592186044416, %r8{{.*}}
+; CHECK-NEXT: movb(%r8), %r8b
+; CHECK-NEXT: testb   %r8b, %r8b
+; CHECK-NEXT: jne [[EXTRA:.*]]
+; CHECK-NEXT: [[RET:.*]]:
+; CHECK-NEXT: retq
+; CHECK-NEXT: [[EXTRA]]:
+; CHECK-NEXT: pushq   %rcx
+; CHECK-NEXT: movq[[REG]], %rcx
+; CHECK-NEXT: andl$7, %ecx
+; CHECK-NEXT: cmpl%r8d, %ecx
+; CHECK-NEXT: popq%rcx
+; CHECK-NEXT: jl  [[RET]]
+; CHECK-NEXT: movq[[REG:.*]], %rdi
+; CHECK-NEXT: jmp __asan_report_load1
+
+; CHECK:  __asan_check_load2_rn[[RN2]]:
+; CHECK-NEXT: movq[[REG:.*]], %r8
+; CHECK-NEXT: shrq$3, %r8
+; CHECK-NEXT: orq $17592186044416, %r8{{.*}}
+; CHECK-NEXT: movb(%r8), %r8b
+; CHECK-NEXT: testb   %r8b, %r8b
+; CHECK-NEXT: jne [[EXTRA:.*]]
+; CHECK-NEXT: [[RET:.*]]:
+; CHECK-NEXT: retq
+; CHECK-NEXT: [[EXTRA]]:
+; CHECK-NEXT: pushq   %rcx
+; CHECK-NEXT: movq[[REG]], %rcx
+; CHECK-NEXT: andl$7, %ecx
+; CHECK-NEXT: addl$1, %ecx
+; CHECK-NEXT: cmpl%r8d, %ecx
+; CHECK-NEXT: popq%rcx
+; CHECK-NEXT: jl  [[RET]]
+; CHECK-NEXT: movq[[REG:.*]], %rdi
+; CHECK-NEXT: jmp __asan_report_load2
+
+; CHECK:  __asan_check_load4_rn[[RN4]]:
+; CHECK-NEXT: movq[[REG:.*]], %r8
+; CHECK-NEXT: shrq$3, %r8
+; CHECK-NEXT: orq $17592186044416, %r

[PATCH] D107394: [AIX] "aligned" attribute does not decrease alignment

2021-08-20 Thread Steven Wan via Phabricator via cfe-commits
stevewan updated this revision to Diff 367875.
stevewan added a comment.

De-Morgan-ize if condition for readability


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107394

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
  clang/test/Layout/aix-type-align-and-pack-attr.cpp

Index: clang/test/Layout/aix-type-align-and-pack-attr.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-type-align-and-pack-attr.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+namespace test1 {
+struct __attribute__((__aligned__(2))) S {
+  double d;
+};
+
+S s;
+
+// CHECK: @{{.*}}test1{{.*}}s{{.*}} = global %"struct.test1::S" zeroinitializer, align 8
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2), packed)) S {
+  double d;
+};
+
+S s;
+
+// CHECK: @{{.*}}test2{{.*}}s{{.*}} = global %"struct.test2::S" zeroinitializer, align 2
+} // namespace test2
+
+namespace test3 {
+struct __attribute__((__aligned__(16))) S {
+  double d;
+};
+
+S s;
+
+// CHECK: @{{.*}}test3{{.*}}s{{.*}} = global %"struct.test3::S" zeroinitializer, align 16
+} // namespace test3
+
+namespace test4 {
+struct __attribute__((aligned(2))) SS {
+  double d;
+};
+
+struct S {
+  struct SS ss;
+} s;
+
+// CHECK: @{{.*}}test4{{.*}}s{{.*}} = global %"struct.test4::S" zeroinitializer, align 8
+} // namespace test4
+
+namespace test5 {
+struct __attribute__((aligned(2), packed)) SS {
+  double d;
+};
+
+struct S {
+  struct SS ss;
+} s;
+
+// CHECK: @{{.*}}test5{{.*}}s{{.*}} = global %"struct.test5::S" zeroinitializer, align 2
+} // namespace test5
Index: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
===
--- clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
-// RUN:   FileCheck %s
-
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
-// RUN:   FileCheck %s
-
-namespace test1 {
-struct __attribute__((__aligned__(2))) C {
-  double x;
-} c;
-
-// CHECK: @{{.*}}test1{{.*}}c{{.*}} = global %"struct.test1::C" zeroinitializer, align 8
-} // namespace test1
-
-namespace test2 {
-struct __attribute__((__aligned__(2), packed)) C {
-  double x;
-} c;
-
-// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" zeroinitializer, align 2
-} // namespace test2
-
-namespace test3 {
-struct __attribute__((__aligned__(16))) C {
-  double x;
-} c;
-
-// CHECK: @{{.*}}test3{{.*}}c{{.*}} = global %"struct.test3::C" zeroinitializer, align 16
-} // namespace test3
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1978,7 +1978,7 @@
   // and zero-width bit-fields count as prior members; members of empty class
   // types marked `no_unique_address` are not considered to be prior members.
   CharUnits PreferredAlign = FieldAlign;
-  if (DefaultsToAIXPowerAlignment && !AlignIsRequired &&
+  if (DefaultsToAIXPowerAlignment &&
   (FoundFirstNonOverlappingEmptyFieldForAIX || IsNaturalAlign)) {
 auto performBuiltinTypeAlignmentUpgrade = [&](const BuiltinType *BTy) {
   if (BTy->getKind() == BuiltinType::Double ||
@@ -1989,16 +1989,25 @@
   }
 };
 
-const Type *Ty = D->getType()->getBaseElementTypeUnsafe();
-if (const ComplexType *CTy = Ty->getAs()) {
-  performBuiltinTypeAlignmentUpgrade(CTy->getElementType()->castAs());
-} else if (const BuiltinType *BTy = Ty->getAs()) {
-  performBuiltinTypeAlignmentUpgrade(BTy);
-} else if (const RecordType *RT = Ty->getAs()) {
-  const RecordDecl *RD = RT->getDecl();
-  assert(RD && "Expected non-null RecordDecl.");
-  const ASTRecordLayout &FieldRecord = Context.getASTRecordLayout(RD);
-  PreferredAlign = FieldRecord.getPreferredAlignment();
+const Type *Ty = D->getType().getTypePtr();
+const Type *BaseTy = Ty->getBaseElementTypeUnsafe();
+// When used as part of a typedef, or together with a 'packed' attribute,
+// the 'aligned' attribute can be used to decrease alignment. In that case,
+// it overrides any computed alignment we have, and there is no need to
+// upgrade the alignment.
+if (!(AlignIsRequired &&
+  !(Ty->getTypeClass() == Type::Typedef || FieldPacked))) {
+  if (const ComplexType *CTy = BaseTy->getAs()) {
+performBuiltinTypeAlignmentUpgrade(
+CTy->getElementType()->castAs());
+  } else if (const BuiltinType *BTy = BaseTy->getAs()) {
+pe

[PATCH] D108377: [asan] Implemented flag to emit intrinsics to optimize ASan callbacks.

2021-08-20 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov updated this revision to Diff 367873.
kstoimenov added a comment.

Moved files from the parent patch which didn't belong there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108377

Files:
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -348,6 +348,10 @@
 static cl::opt ClOpt("asan-opt", cl::desc("Optimize instrumentation"),
cl::Hidden, cl::init(true));
 
+static cl::opt ClOptimizeCallbacks("asan-optimize-callbacks",
+ cl::desc("Optimize callbacks"),
+ cl::Hidden, cl::init(false));
+
 static cl::opt ClOptSameTemp(
 "asan-opt-same-temp", cl::desc("Instrument the same temp just once"),
 cl::Hidden, cl::init(true));
@@ -634,6 +638,7 @@
 C = &(M.getContext());
 LongSize = M.getDataLayout().getPointerSizeInBits();
 IntptrTy = Type::getIntNTy(*C, LongSize);
+Int8PtrTy = Type::getInt8PtrTy(*C);
 TargetTriple = Triple(M.getTargetTriple());
 
 Mapping = getShadowMapping(TargetTriple, LongSize, this->CompileKernel);
@@ -724,6 +729,7 @@
   bool UseAfterScope;
   AsanDetectStackUseAfterReturnMode UseAfterReturn;
   Type *IntptrTy;
+  Type *Int8PtrTy;
   ShadowMapping Mapping;
   FunctionCallee AsanHandleNoReturnFunc;
   FunctionCallee AsanPtrCmpFunction, AsanPtrSubFunction;
@@ -1745,27 +1751,14 @@
   IRBuilder<> IRB(InsertBefore);
   Value *AddrLong = IRB.CreatePointerCast(Addr, IntptrTy);
   size_t AccessSizeIndex = TypeSizeToSizeIndex(TypeSize);
-  const int32_t AccessInfo =
-  (CompileKernel << ASanAccessInfo::CompileKernelShift) +
-  (IsWrite << ASanAccessInfo::IsWriteShift) +
-  (AccessSizeIndex << ASanAccessInfo::AccessSizeShift);
-
 
   if (UseCalls) {
-if (ClOptimizeCallbacks) {
-  Value *Ptr8 = IRB.CreatePointerCast(Addr, Int8PtrTy);
-  Module *M = IRB.GetInsertBlock()->getParent()->getParent();
-  IRB.CreateCall(
-  Intrinsic::getDeclaration(M, Intrinsic::asan_check_memaccess),
-  {Ptr8, ConstantInt::get(IRB.getInt32Ty(), AccessInfo)});
-} else {
-  if (Exp == 0)
-IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex],
-   AddrLong);
-  else
-IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][1][AccessSizeIndex],
-   {AddrLong, ConstantInt::get(IRB.getInt32Ty(), Exp)});
-}
+if (Exp == 0)
+  IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex],
+ AddrLong);
+else
+  IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][1][AccessSizeIndex],
+ {AddrLong, ConstantInt::get(IRB.getInt32Ty(), Exp)});
 return;
   }
 
Index: llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
===
--- llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
+++ llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
@@ -155,17 +155,6 @@
 bool UseOdrIndicator = true,
 AsanDtorKind DestructorKind = AsanDtorKind::Global);
 
-namespace ASanAccessInfo {
-
-// Bit field positions for accessinfo parameter to llvm.asan.check.memaccess.
-enum {
-  CompileKernelShift = 0, // 1 bit
-  AccessSizeShift = 1, // 4 bits
-  IsWriteShift = 5, // 1 bit
-};
-
-} // namespace ASanAccessInfo
-
 } // namespace llvm
 
 #endif


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -348,6 +348,10 @@
 static cl::opt ClOpt("asan-opt", cl::desc("Optimize instrumentation"),
cl::Hidden, cl::init(true));
 
+static cl::opt ClOptimizeCallbacks("asan-optimize-callbacks",
+ cl::desc("Optimize callbacks"),
+ cl::Hidden, cl::init(false));
+
 static cl::opt ClOptSameTemp(
 "asan-opt-same-temp", cl::desc("Instrument the same temp just once"),
 cl::Hidden, cl::init(true));
@@ -634,6 +638,7 @@
 C = &(M.getContext());
 LongSize = M.getDataLayout().getPointerSizeInBits();
 IntptrTy = Type::getIntNTy(*C, LongSize);
+Int8PtrTy = Type::getInt8PtrTy(*C);
 TargetTriple = Triple(M.getTargetTriple());
 
 Mapping = getShadowMapping(TargetTriple, LongSize, this->CompileKernel);
@@ -724,6 +729,7 @@
   bool UseAfterScope;
   AsanDetectStackUseAfterReturnMode UseAfterReturn;
   Type *IntptrTy;
+ 

[PATCH] D108377: [asan] Implemented flag to emit intrinsics to optimize ASan callbacks.

2021-08-20 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

Flag is not used anywhere?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108377

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


[PATCH] D69560: [clang-tidy] Add 'bugprone-easily-swappable-parameters' check

2021-08-20 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp:57
+   "Const_Reverse_Iterator",
+   "const_reverse_iterator"
+   "Constreverseiterator",

@whisperity There is a missing comma at the end of the "const_reverse_iterator" 
line causing implicit concatenation with the following "Constreverseiterator" 
line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69560

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


[PATCH] D108481: Avoid nullptr dereferencing of 'Constraint'

2021-08-20 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir created this revision.
schittir added reviewers: erichkeane, saar.raz.
schittir added a project: clang.
schittir requested review of this revision.
Herald added a subscriber: cfe-commits.

  Klocwork static code analysis exposed this bug:
  Pointer 'Constraint' returned from call to function
  'cast_or_null' may
  be NULL and will be dereferenced in the statement following it
  
  Replace 'cast_or_null' with 'cast' so that the latter can assert
  when it encounters a NULL


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108481

Files:
  clang/lib/Sema/SemaConcept.cpp


Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -1065,8 +1065,7 @@
   assert(TC &&
  "TPL must have a template type parameter with a type constraint");
   auto *Constraint =
-  cast_or_null(
-  TC->getImmediatelyDeclaredConstraint());
+  cast(TC->getImmediatelyDeclaredConstraint());
   bool Dependent =
   Constraint->getTemplateArgsAsWritten() &&
   TemplateSpecializationType::anyInstantiationDependentTemplateArguments(


Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -1065,8 +1065,7 @@
   assert(TC &&
  "TPL must have a template type parameter with a type constraint");
   auto *Constraint =
-  cast_or_null(
-  TC->getImmediatelyDeclaredConstraint());
+  cast(TC->getImmediatelyDeclaredConstraint());
   bool Dependent =
   Constraint->getTemplateArgsAsWritten() &&
   TemplateSpecializationType::anyInstantiationDependentTemplateArguments(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108377: [asan] Implemented flag to emit intrinsics to optimize ASan callbacks.

2021-08-20 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov updated this revision to Diff 367872.
kstoimenov added a comment.

Removed test code which should be added under a different directory.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108377

Files:
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -348,6 +348,10 @@
 static cl::opt ClOpt("asan-opt", cl::desc("Optimize instrumentation"),
cl::Hidden, cl::init(true));
 
+static cl::opt ClOptimizeCallbacks("asan-optimize-callbacks",
+ cl::desc("Optimize callbacks"),
+ cl::Hidden, cl::init(false));
+
 static cl::opt ClOptSameTemp(
 "asan-opt-same-temp", cl::desc("Instrument the same temp just once"),
 cl::Hidden, cl::init(true));
@@ -634,6 +638,7 @@
 C = &(M.getContext());
 LongSize = M.getDataLayout().getPointerSizeInBits();
 IntptrTy = Type::getIntNTy(*C, LongSize);
+Int8PtrTy = Type::getInt8PtrTy(*C);
 TargetTriple = Triple(M.getTargetTriple());
 
 Mapping = getShadowMapping(TargetTriple, LongSize, this->CompileKernel);
@@ -724,6 +729,7 @@
   bool UseAfterScope;
   AsanDetectStackUseAfterReturnMode UseAfterReturn;
   Type *IntptrTy;
+  Type *Int8PtrTy;
   ShadowMapping Mapping;
   FunctionCallee AsanHandleNoReturnFunc;
   FunctionCallee AsanPtrCmpFunction, AsanPtrSubFunction;


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -348,6 +348,10 @@
 static cl::opt ClOpt("asan-opt", cl::desc("Optimize instrumentation"),
cl::Hidden, cl::init(true));
 
+static cl::opt ClOptimizeCallbacks("asan-optimize-callbacks",
+ cl::desc("Optimize callbacks"),
+ cl::Hidden, cl::init(false));
+
 static cl::opt ClOptSameTemp(
 "asan-opt-same-temp", cl::desc("Instrument the same temp just once"),
 cl::Hidden, cl::init(true));
@@ -634,6 +638,7 @@
 C = &(M.getContext());
 LongSize = M.getDataLayout().getPointerSizeInBits();
 IntptrTy = Type::getIntNTy(*C, LongSize);
+Int8PtrTy = Type::getInt8PtrTy(*C);
 TargetTriple = Triple(M.getTargetTriple());
 
 Mapping = getShadowMapping(TargetTriple, LongSize, this->CompileKernel);
@@ -724,6 +729,7 @@
   bool UseAfterScope;
   AsanDetectStackUseAfterReturnMode UseAfterReturn;
   Type *IntptrTy;
+  Type *Int8PtrTy;
   ShadowMapping Mapping;
   FunctionCallee AsanHandleNoReturnFunc;
   FunctionCallee AsanPtrCmpFunction, AsanPtrSubFunction;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106616: [Clang][LLVM] generate btf_tag annotations for DIDerived types

2021-08-20 Thread Yonghong Song 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 rG430e22388173: [DebugInfo] generate btf_tag annotations for 
DIDerived types (authored by yonghong-song).

Changed prior to commit:
  https://reviews.llvm.org/D106616?vs=367846&id=367864#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106616

Files:
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/test/Bitcode/attr-btf_tag-field.ll

Index: llvm/test/Bitcode/attr-btf_tag-field.ll
===
--- /dev/null
+++ llvm/test/Bitcode/attr-btf_tag-field.ll
@@ -0,0 +1,91 @@
+; REQUIRES: x86-registered-target
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+%struct.t1 = type { i32 }
+%struct.t2 = type { i8, [3 x i8] }
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local i32 @foo(%struct.t1* %arg) #0 !dbg !9 {
+entry:
+  %arg.addr = alloca %struct.t1*, align 8
+  store %struct.t1* %arg, %struct.t1** %arg.addr, align 8
+  call void @llvm.dbg.declare(metadata %struct.t1** %arg.addr, metadata !20, metadata !DIExpression()), !dbg !21
+  %0 = load %struct.t1*, %struct.t1** %arg.addr, align 8, !dbg !22
+  %a = getelementptr inbounds %struct.t1, %struct.t1* %0, i32 0, i32 0, !dbg !23
+  %1 = load i32, i32* %a, align 4, !dbg !23
+  ret i32 %1, !dbg !24
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local i32 @foo2(%struct.t2* %arg) #0 !dbg !25 {
+entry:
+  %arg.addr = alloca %struct.t2*, align 8
+  store %struct.t2* %arg, %struct.t2** %arg.addr, align 8
+  call void @llvm.dbg.declare(metadata %struct.t2** %arg.addr, metadata !32, metadata !DIExpression()), !dbg !33
+  %0 = load %struct.t2*, %struct.t2** %arg.addr, align 8, !dbg !34
+  %1 = bitcast %struct.t2* %0 to i8*, !dbg !35
+  %bf.load = load i8, i8* %1, align 4, !dbg !35
+  %bf.shl = shl i8 %bf.load, 7, !dbg !35
+  %bf.ashr = ashr i8 %bf.shl, 7, !dbg !35
+  %bf.cast = sext i8 %bf.ashr to i32, !dbg !35
+  ret i32 %bf.cast, !dbg !36
+}
+
+attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
+attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5, !6, !7}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git 4cbaee98885ead226304e8836090069db6596965)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "attr-btf_tag-field.c", directory: "/home/yhs/work/tests/llvm/btf_tag")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{i32 7, !"uwtable", i32 1}
+!7 = !{i32 7, !"frame-pointer", i32 2}
+!8 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 4cbaee98885ead226304e8836090069db6596965)"}
+!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 11, type: !10, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!10 = !DISubroutineType(types: !11)
+!11 = !{!12, !13}
+!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64)
+!14 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", file: !1, line: 7, size: 32, elements: !15)
+!15 = !{!16}
+!16 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !14, file: !1, line: 8, baseType: !12, size: 32, annotations: !17)
+!17 = !{!18, !19}
+!18 = !{!"btf_tag", !"tag1"}
+!19 = !{!"btf_tag", !"tag2"}
+
+; CHECK:!DIDerivedType(tag: DW_TAG_member, name: "a"
+; CHECK-SAME:   annotations: ![[ANNOT:[0-9]+]]
+; CHECK:![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
+; CHECK:![[TAG1]] = !{!"btf_tag", !"tag1"}
+; CHECK:![[TAG2]] = !{!"btf_tag", !"tag2"}
+
+!20 = !DILocalVariable(name: "arg", arg: 1, scope: !9, file: !1, line: 11, type: !13)
+!21 = !DILocation(line: 11, column: 20, scope: !9)
+!22 = !DILocation(line: 12, column: 10, scope: !9)
+!23 = !DILocation(line: 12, column: 15, scope: !9)
+!24 = !DILocation(line: 12, column: 

[PATCH] D107095: Implement #pragma clang header_unsafe

2021-08-20 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 367863.
beanz added a comment.

Missed updating the flag name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107095

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Pragma.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Lexer/Inputs/pedantic-macro-interplay.h
  clang/test/Lexer/Inputs/unsafe-macro-2.h
  clang/test/Lexer/Inputs/unsafe-macro.h
  clang/test/Lexer/pedantic-macro-interplay.c
  clang/test/Lexer/unsafe-macro.c

Index: clang/test/Lexer/unsafe-macro.c
===
--- /dev/null
+++ clang/test/Lexer/unsafe-macro.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -Wrestrict-expansion %s -fsyntax-only -verify
+#include "Inputs/unsafe-macro.h"
+#include "Inputs/unsafe-macro-2.h"
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if UNSAFE_MACRO
+#endif
Index: clang/test/Lexer/pedantic-macro-interplay.c
===
--- /dev/null
+++ clang/test/Lexer/pedantic-macro-interplay.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -Wpedantic-macros %s -fsyntax-only -verify
+
+// This test verifies that the -Wpedantic-macros warnings don't fire in the
+// annotation pragmas themselves. This ensures you can annotate macros with
+// more than one of the pragmas without spewing warnings all over the code.
+
+#include "Inputs/pedantic-macro-interplay.h"
+
+#define UNSAFE_MACRO_2 1
+#pragma clang deprecated(UNSAFE_MACRO_2, "Don't use this!")
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as deprecated: Don't use this!}}
+#pragma clang restrict_expansion(UNSAFE_MACRO_2, "Don't use this!")
+
+// expected-no-diagnostics
Index: clang/test/Lexer/Inputs/unsafe-macro.h
===
--- /dev/null
+++ clang/test/Lexer/Inputs/unsafe-macro.h
@@ -0,0 +1,27 @@
+// expected-error@+1{{expected (}}
+#pragma clang restrict_expansion
+
+// expected-error@+1{{expected identifier}}
+#pragma clang restrict_expansion(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang restrict_expansion(foo)
+
+
+#define UNSAFE_MACRO 1
+// expected-note@+8{{macro marked 'restrict_expansion' here}}
+// expected-note@+7{{macro marked 'restrict_expansion' here}}
+// expected-note@+6{{macro marked 'restrict_expansion' here}}
+// expected-note@+5{{macro marked 'restrict_expansion' here}}
+// expected-note@+4{{macro marked 'restrict_expansion' here}}
+// expected-note@+3{{macro marked 'restrict_expansion' here}}
+// expected-note@+2{{macro marked 'restrict_expansion' here}}
+// expected-note@+1{{macro marked 'restrict_expansion' here}} 
+#pragma clang restrict_expansion(UNSAFE_MACRO, "Don't use this!")
+
+#define UNSAFE_MACRO_2 2
+// expected-note@+1{{macro marked 'restrict_expansion' here}}
+#pragma clang restrict_expansion(UNSAFE_MACRO_2)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(UNSAFE_MACRO
Index: clang/test/Lexer/Inputs/unsafe-macro-2.h
===
--- /dev/null
+++ clang/test/Lexer/Inputs/unsafe-macro-2.h
@@ -0,0 +1,70 @@
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if defined(UNSAFE_MACRO)
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#ifdef UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#ifndef UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+const int x = UNSAFE_MACRO;
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+const int y = UNSAFE_MACRO_2;
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+#undef UNSAFE_MACRO_2
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+#define UNSAFE_MACRO_2 2
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+const int z = UNSAFE_MACRO_2;
+
+
+// Test that we diagnose on #elif.
+#if 0
+#elif UNSAFE_MACRO
+// expected-warning@-1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#endif
+
+
+// Test that we diagnose on #elifdef.
+#ifdef baz
+#elifdef UNSAFE_MACRO
+// expected-warning@-1{{macro 'UNSAFE_MACRO' has been 

[PATCH] D107095: Implement #pragma clang header_unsafe

2021-08-20 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 367861.
beanz added a comment.

Cleaning up documentation wording to make more sense with the rename


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107095

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Pragma.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Lexer/Inputs/pedantic-macro-interplay.h
  clang/test/Lexer/Inputs/unsafe-macro-2.h
  clang/test/Lexer/Inputs/unsafe-macro.h
  clang/test/Lexer/pedantic-macro-interplay.c
  clang/test/Lexer/unsafe-macro.c

Index: clang/test/Lexer/unsafe-macro.c
===
--- /dev/null
+++ clang/test/Lexer/unsafe-macro.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -Wheader-unsafe-macro %s -fsyntax-only -verify
+#include "Inputs/unsafe-macro.h"
+#include "Inputs/unsafe-macro-2.h"
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if UNSAFE_MACRO
+#endif
Index: clang/test/Lexer/pedantic-macro-interplay.c
===
--- /dev/null
+++ clang/test/Lexer/pedantic-macro-interplay.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -Wpedantic-macros %s -fsyntax-only -verify
+
+// This test verifies that the -Wpedantic-macros warnings don't fire in the
+// annotation pragmas themselves. This ensures you can annotate macros with
+// more than one of the pragmas without spewing warnings all over the code.
+
+#include "Inputs/pedantic-macro-interplay.h"
+
+#define UNSAFE_MACRO_2 1
+#pragma clang deprecated(UNSAFE_MACRO_2, "Don't use this!")
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as deprecated: Don't use this!}}
+#pragma clang restrict_expansion(UNSAFE_MACRO_2, "Don't use this!")
+
+// expected-no-diagnostics
Index: clang/test/Lexer/Inputs/unsafe-macro.h
===
--- /dev/null
+++ clang/test/Lexer/Inputs/unsafe-macro.h
@@ -0,0 +1,27 @@
+// expected-error@+1{{expected (}}
+#pragma clang restrict_expansion
+
+// expected-error@+1{{expected identifier}}
+#pragma clang restrict_expansion(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang restrict_expansion(foo)
+
+
+#define UNSAFE_MACRO 1
+// expected-note@+8{{macro marked 'restrict_expansion' here}}
+// expected-note@+7{{macro marked 'restrict_expansion' here}}
+// expected-note@+6{{macro marked 'restrict_expansion' here}}
+// expected-note@+5{{macro marked 'restrict_expansion' here}}
+// expected-note@+4{{macro marked 'restrict_expansion' here}}
+// expected-note@+3{{macro marked 'restrict_expansion' here}}
+// expected-note@+2{{macro marked 'restrict_expansion' here}}
+// expected-note@+1{{macro marked 'restrict_expansion' here}} 
+#pragma clang restrict_expansion(UNSAFE_MACRO, "Don't use this!")
+
+#define UNSAFE_MACRO_2 2
+// expected-note@+1{{macro marked 'restrict_expansion' here}}
+#pragma clang restrict_expansion(UNSAFE_MACRO_2)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(UNSAFE_MACRO
Index: clang/test/Lexer/Inputs/unsafe-macro-2.h
===
--- /dev/null
+++ clang/test/Lexer/Inputs/unsafe-macro-2.h
@@ -0,0 +1,70 @@
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if defined(UNSAFE_MACRO)
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#ifdef UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#ifndef UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+const int x = UNSAFE_MACRO;
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+const int y = UNSAFE_MACRO_2;
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+#undef UNSAFE_MACRO_2
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+#define UNSAFE_MACRO_2 2
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+const int z = UNSAFE_MACRO_2;
+
+
+// Test that we diagnose on #elif.
+#if 0
+#elif UNSAFE_MACRO
+// expected-warning@-1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#endif
+
+
+// Test that we diagnose on #elifdef.
+#ifdef baz
+#elifdef UNSAFE_MACRO
+// expected-war

[PATCH] D108479: [Clang] Add __builtin_addressof_nocfi

2021-08-20 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added reviewers: nickdesaulniers, pcc.
samitolvanen added a comment.

Here's a PoC of the built-in function that returns the address of the function 
body with CFI. Based on D108478 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108479

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


[PATCH] D107095: Implement #pragma clang header_unsafe

2021-08-20 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 367856.
beanz added a comment.

Fixing documentation line wrapping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107095

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Pragma.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Lexer/Inputs/pedantic-macro-interplay.h
  clang/test/Lexer/Inputs/unsafe-macro-2.h
  clang/test/Lexer/Inputs/unsafe-macro.h
  clang/test/Lexer/pedantic-macro-interplay.c
  clang/test/Lexer/unsafe-macro.c

Index: clang/test/Lexer/unsafe-macro.c
===
--- /dev/null
+++ clang/test/Lexer/unsafe-macro.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -Wheader-unsafe-macro %s -fsyntax-only -verify
+#include "Inputs/unsafe-macro.h"
+#include "Inputs/unsafe-macro-2.h"
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if UNSAFE_MACRO
+#endif
Index: clang/test/Lexer/pedantic-macro-interplay.c
===
--- /dev/null
+++ clang/test/Lexer/pedantic-macro-interplay.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -Wpedantic-macros %s -fsyntax-only -verify
+
+// This test verifies that the -Wpedantic-macros warnings don't fire in the
+// annotation pragmas themselves. This ensures you can annotate macros with
+// more than one of the pragmas without spewing warnings all over the code.
+
+#include "Inputs/pedantic-macro-interplay.h"
+
+#define UNSAFE_MACRO_2 1
+#pragma clang deprecated(UNSAFE_MACRO_2, "Don't use this!")
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as deprecated: Don't use this!}}
+#pragma clang restrict_expansion(UNSAFE_MACRO_2, "Don't use this!")
+
+// expected-no-diagnostics
Index: clang/test/Lexer/Inputs/unsafe-macro.h
===
--- /dev/null
+++ clang/test/Lexer/Inputs/unsafe-macro.h
@@ -0,0 +1,27 @@
+// expected-error@+1{{expected (}}
+#pragma clang restrict_expansion
+
+// expected-error@+1{{expected identifier}}
+#pragma clang restrict_expansion(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang restrict_expansion(foo)
+
+
+#define UNSAFE_MACRO 1
+// expected-note@+8{{macro marked 'restrict_expansion' here}}
+// expected-note@+7{{macro marked 'restrict_expansion' here}}
+// expected-note@+6{{macro marked 'restrict_expansion' here}}
+// expected-note@+5{{macro marked 'restrict_expansion' here}}
+// expected-note@+4{{macro marked 'restrict_expansion' here}}
+// expected-note@+3{{macro marked 'restrict_expansion' here}}
+// expected-note@+2{{macro marked 'restrict_expansion' here}}
+// expected-note@+1{{macro marked 'restrict_expansion' here}} 
+#pragma clang restrict_expansion(UNSAFE_MACRO, "Don't use this!")
+
+#define UNSAFE_MACRO_2 2
+// expected-note@+1{{macro marked 'restrict_expansion' here}}
+#pragma clang restrict_expansion(UNSAFE_MACRO_2)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(UNSAFE_MACRO
Index: clang/test/Lexer/Inputs/unsafe-macro-2.h
===
--- /dev/null
+++ clang/test/Lexer/Inputs/unsafe-macro-2.h
@@ -0,0 +1,70 @@
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if defined(UNSAFE_MACRO)
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#ifdef UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#ifndef UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+const int x = UNSAFE_MACRO;
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+const int y = UNSAFE_MACRO_2;
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+#undef UNSAFE_MACRO_2
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+#define UNSAFE_MACRO_2 2
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+const int z = UNSAFE_MACRO_2;
+
+
+// Test that we diagnose on #elif.
+#if 0
+#elif UNSAFE_MACRO
+// expected-warning@-1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#endif
+
+
+// Test that we diagnose on #elifdef.
+#ifdef baz
+#elifdef UNSAFE_MACRO
+// expected-warning@-1{{macro 'UNSAFE_MACRO' has

[PATCH] D107095: Implement #pragma clang header_unsafe

2021-08-20 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 367851.
beanz added a comment.

Renaming to restrict_expansion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107095

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Pragma.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Lexer/Inputs/pedantic-macro-interplay.h
  clang/test/Lexer/Inputs/unsafe-macro-2.h
  clang/test/Lexer/Inputs/unsafe-macro.h
  clang/test/Lexer/pedantic-macro-interplay.c
  clang/test/Lexer/unsafe-macro.c

Index: clang/test/Lexer/unsafe-macro.c
===
--- /dev/null
+++ clang/test/Lexer/unsafe-macro.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -Wheader-unsafe-macro %s -fsyntax-only -verify
+#include "Inputs/unsafe-macro.h"
+#include "Inputs/unsafe-macro-2.h"
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if UNSAFE_MACRO
+#endif
Index: clang/test/Lexer/pedantic-macro-interplay.c
===
--- /dev/null
+++ clang/test/Lexer/pedantic-macro-interplay.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -Wpedantic-macros %s -fsyntax-only -verify
+
+// This test verifies that the -Wpedantic-macros warnings don't fire in the
+// annotation pragmas themselves. This ensures you can annotate macros with
+// more than one of the pragmas without spewing warnings all over the code.
+
+#include "Inputs/pedantic-macro-interplay.h"
+
+#define UNSAFE_MACRO_2 1
+#pragma clang deprecated(UNSAFE_MACRO_2, "Don't use this!")
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as deprecated: Don't use this!}}
+#pragma clang restrict_expansion(UNSAFE_MACRO_2, "Don't use this!")
+
+// expected-no-diagnostics
Index: clang/test/Lexer/Inputs/unsafe-macro.h
===
--- /dev/null
+++ clang/test/Lexer/Inputs/unsafe-macro.h
@@ -0,0 +1,27 @@
+// expected-error@+1{{expected (}}
+#pragma clang restrict_expansion
+
+// expected-error@+1{{expected identifier}}
+#pragma clang restrict_expansion(4
+
+// expected-error@+1{{no macro named foo}}
+#pragma clang restrict_expansion(foo)
+
+
+#define UNSAFE_MACRO 1
+// expected-note@+8{{macro marked 'restrict_expansion' here}}
+// expected-note@+7{{macro marked 'restrict_expansion' here}}
+// expected-note@+6{{macro marked 'restrict_expansion' here}}
+// expected-note@+5{{macro marked 'restrict_expansion' here}}
+// expected-note@+4{{macro marked 'restrict_expansion' here}}
+// expected-note@+3{{macro marked 'restrict_expansion' here}}
+// expected-note@+2{{macro marked 'restrict_expansion' here}}
+// expected-note@+1{{macro marked 'restrict_expansion' here}} 
+#pragma clang restrict_expansion(UNSAFE_MACRO, "Don't use this!")
+
+#define UNSAFE_MACRO_2 2
+// expected-note@+1{{macro marked 'restrict_expansion' here}}
+#pragma clang restrict_expansion(UNSAFE_MACRO_2)
+
+// expected-error@+1{{expected )}}
+#pragma clang deprecated(UNSAFE_MACRO
Index: clang/test/Lexer/Inputs/unsafe-macro-2.h
===
--- /dev/null
+++ clang/test/Lexer/Inputs/unsafe-macro-2.h
@@ -0,0 +1,70 @@
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#if defined(UNSAFE_MACRO)
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#ifdef UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#ifndef UNSAFE_MACRO
+#endif
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+const int x = UNSAFE_MACRO;
+
+// expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+const int y = UNSAFE_MACRO_2;
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+#undef UNSAFE_MACRO_2
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+#define UNSAFE_MACRO_2 2
+
+// not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as unsafe for use in headers}}
+const int z = UNSAFE_MACRO_2;
+
+
+// Test that we diagnose on #elif.
+#if 0
+#elif UNSAFE_MACRO
+// expected-warning@-1{{macro 'UNSAFE_MACRO' has been marked as unsafe for use in headers: Don't use this!}}
+#endif
+
+
+// Test that we diagnose on #elifdef.
+#ifdef baz
+#elifdef UNSAFE_MACRO
+// expected-warning@-1{{macro 'UNSAFE_MACRO' has been

[PATCH] D108479: [Clang] Add __builtin_addressof_nocfi

2021-08-20 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen created this revision.
Herald added a subscriber: martong.
samitolvanen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change adds __builtin_addressof_nocfi(). This built-in function
is similar to the existing __builtin_addressof(), except that with
-fsanitize=cfi, it returns the address of the function body instead of
a CFI jump table address.

__builtin_addressof_nocfi() is helpful in low-level code, such as
operating system kernels, which may need the address of a specific
function without a jump table indirection.

Link: https://github.com/ClangBuiltLinux/linux/issues/1353

Depends on D108478 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108479

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/APValue.h
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/APValue.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  clang/test/CodeGen/builtin-addressof-nocfi.c
  clang/test/SemaCXX/builtins.cpp

Index: clang/test/SemaCXX/builtins.cpp
===
--- clang/test/SemaCXX/builtins.cpp
+++ clang/test/SemaCXX/builtins.cpp
@@ -39,6 +39,14 @@
   S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address of a temporary}}
 }
 
+namespace addressof_nocfi {
+  void a(void) {}
+  static_assert(__builtin_addressof_nocfi(a) == a, "");
+
+  struct S {} s;
+  static_assert(__builtin_addressof_nocfi(s) == &s, "");
+}
+
 void no_ms_builtins() {
   __assume(1); // expected-error {{use of undeclared}}
   __noop(1); // expected-error {{use of undeclared}}
Index: clang/test/CodeGen/builtin-addressof-nocfi.c
===
--- /dev/null
+++ clang/test/CodeGen/builtin-addressof-nocfi.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=cfi-icall -o - %s | FileCheck %s
+
+void a(void) {}
+void b(void) {}
+void c(void (*p)(void)) {
+  p();
+}
+
+// CHECK: @e = constant void ()* no_cfi @a
+void (*const e)(void) = __builtin_addressof_nocfi(a);
+// CHECK: @f = global [2 x void ()*] [void ()* @b, void ()* no_cfi @b]
+void (*f[])(void) = {b, __builtin_addressof_nocfi(b)};
+
+void d(void) {
+  // CHECK: store void ()* no_cfi @b, void ()** %g
+  void (*g)(void) = __builtin_addressof_nocfi(b);
+  // CHECK: call void @c(void ()* no_cfi @a)
+  c(__builtin_addressof_nocfi(a));
+  e();
+  f[1]();
+  g();
+}
Index: clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -66,7 +66,8 @@
   case Builtin::BI__builtin_expect:
   case Builtin::BI__builtin_expect_with_probability:
   case Builtin::BI__builtin_assume_aligned:
-  case Builtin::BI__builtin_addressof: {
+  case Builtin::BI__builtin_addressof:
+  case Builtin::BI__builtin_addressof_nocfi: {
 // For __builtin_unpredictable, __builtin_expect,
 // __builtin_expect_with_probability and __builtin_assume_aligned,
 // just return the value of the subexpression.
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1749,6 +1749,7 @@
   return ExprError();
 break;
   case Builtin::BI__builtin_addressof:
+  case Builtin::BI__builtin_addressof_nocfi:
 if (SemaBuiltinAddressof(*this, TheCall))
   return ExprError();
 break;
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1887,8 +1887,12 @@
 if (D->hasAttr())
   return CGM.GetWeakRefReference(D).getPointer();
 
-if (auto FD = dyn_cast(D))
-  return CGM.GetAddrOfFunction(FD);
+if (auto FD = dyn_cast(D)) {
+  auto *C = CGM.GetAddrOfFunction(FD);
+  if (base.isNoCFIValue())
+return llvm::NoCFIValue::get(cast(C));
+  return C;
+}
 
 if (auto VD = dyn_cast(D)) {
   // We can never refer to a variable with local storage.
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -4375,6 +4375,9 @@
   }
   case Builtin::BI__builtin_addressof:
 return RValue::get(EmitLValue(E->getArg(0)).getPointer(*this));
+  case Builtin::BI__builtin_addressof_nocfi:
+return RValue::get(llvm::NoCFIValue::get(
+cast(EmitLValue(E->getArg(0)).getPointer(*this;
   case Builtin::BI__builtin_operator_new:
 

[PATCH] D107290: [PoC][RISCV] Add support for the vscale_range attribute

2021-08-20 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.cpp:349
+  unsigned VLENMax = 65536;
+  return std::make_pair(VLENMin / 64, VLENMax / 64);
+}

Should we move RVVBitsPerBlock to RISCVTargetParser.def? Or some other place 
that can be shared between lllvm/lib/Target/RISCV/ and here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107290

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


[PATCH] D106616: [Clang][LLVM] generate btf_tag annotations for DIDerived types

2021-08-20 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 367846.
yonghong-song added a comment.

- put checking btf_tag existence condition in function CollectBTFTagAnnotations


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106616

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/attr-btf_tag-field.c
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/test/Bitcode/attr-btf_tag-field.ll

Index: llvm/test/Bitcode/attr-btf_tag-field.ll
===
--- /dev/null
+++ llvm/test/Bitcode/attr-btf_tag-field.ll
@@ -0,0 +1,91 @@
+; REQUIRES: x86-registered-target
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+%struct.t1 = type { i32 }
+%struct.t2 = type { i8, [3 x i8] }
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local i32 @foo(%struct.t1* %arg) #0 !dbg !9 {
+entry:
+  %arg.addr = alloca %struct.t1*, align 8
+  store %struct.t1* %arg, %struct.t1** %arg.addr, align 8
+  call void @llvm.dbg.declare(metadata %struct.t1** %arg.addr, metadata !20, metadata !DIExpression()), !dbg !21
+  %0 = load %struct.t1*, %struct.t1** %arg.addr, align 8, !dbg !22
+  %a = getelementptr inbounds %struct.t1, %struct.t1* %0, i32 0, i32 0, !dbg !23
+  %1 = load i32, i32* %a, align 4, !dbg !23
+  ret i32 %1, !dbg !24
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local i32 @foo2(%struct.t2* %arg) #0 !dbg !25 {
+entry:
+  %arg.addr = alloca %struct.t2*, align 8
+  store %struct.t2* %arg, %struct.t2** %arg.addr, align 8
+  call void @llvm.dbg.declare(metadata %struct.t2** %arg.addr, metadata !32, metadata !DIExpression()), !dbg !33
+  %0 = load %struct.t2*, %struct.t2** %arg.addr, align 8, !dbg !34
+  %1 = bitcast %struct.t2* %0 to i8*, !dbg !35
+  %bf.load = load i8, i8* %1, align 4, !dbg !35
+  %bf.shl = shl i8 %bf.load, 7, !dbg !35
+  %bf.ashr = ashr i8 %bf.shl, 7, !dbg !35
+  %bf.cast = sext i8 %bf.ashr to i32, !dbg !35
+  ret i32 %bf.cast, !dbg !36
+}
+
+attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
+attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5, !6, !7}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git 4cbaee98885ead226304e8836090069db6596965)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "attr-btf_tag-field.c", directory: "/home/yhs/work/tests/llvm/btf_tag")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{i32 7, !"uwtable", i32 1}
+!7 = !{i32 7, !"frame-pointer", i32 2}
+!8 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 4cbaee98885ead226304e8836090069db6596965)"}
+!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 11, type: !10, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!10 = !DISubroutineType(types: !11)
+!11 = !{!12, !13}
+!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64)
+!14 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", file: !1, line: 7, size: 32, elements: !15)
+!15 = !{!16}
+!16 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !14, file: !1, line: 8, baseType: !12, size: 32, annotations: !17)
+!17 = !{!18, !19}
+!18 = !{!"btf_tag", !"tag1"}
+!19 = !{!"btf_tag", !"tag2"}
+
+; CHECK:!DIDerivedType(tag: DW_TAG_member, name: "a"
+; CHECK-SAME:   annotations: ![[ANNOT:[0-9]+]]
+; CHECK:![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
+; CHECK:![[TAG1]] = !{!"btf_tag", !"tag1"}
+; CHECK:![[TAG2]] = !{!"btf_tag", !"tag2"}
+
+!20 = !DILocalVariable(name: "arg", arg: 1, scope: !9, file: !1, line: 11, type: !13)
+!21 = !DILocation(line: 11, column: 20, scope: !9)
+!22 = !DILocation(line: 12, column: 10, scope: !9)
+!23 = !DILocation(line: 12, column: 15, scope: !9)
+!24 = !DILocation(line: 12, column: 3, scope: !9)
+!25 = distinct !DISubprogram(name: "foo2", scop

[PATCH] D106616: [Clang][LLVM] generate btf_tag annotations for DIDerived types

2021-08-20 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

For

> (any chance have you measured/could you measure how much larger the bitcode 
> for, say, an LLVM self-host Debug build gets with all these btf patches? 
> (even without targeting/using btf, this is adding an extra field to lots of 
> the debug info metadata, and I'd like to know whether that makes an 
> observable difference in file size))

The following are some experiments:

$ cat t.c
#define __tag1 __attribute__((btf_tag("tag1")))
struct t { int a __tag1; };
struct t g;

compilation flag: clang  -O2 -g -emit-llvm -c t.c -o t.bc

Without this patch (no field annotation in record members):

  1904 bytes

With this patch (no field annotation in record members):

  1904 bytes

With this patch (with above field annotation in record members):

  1924 bytes

If I use the code below:
#define __tag1 __attribute__((btf_tag("tag1")))
#define __tag2 __attribute__((btf_tag("tag2")))
struct t { int a __tag1 __tag2; };
struct t g;

The IR:
!8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !3, line: 
3, baseType: !9, size: 32, annotations: !10)
!10 = !{!11, !12}
!11 = !{!"btf_tag", !"tag1"}
!12 = !{!"btf_tag", !"tag2"}

I got 1936 bytes.

So the conclusion is:

- no overhead for bitcode size if NO annotations.
- moderate overhead for annotations. we expect btf_tag is only used in 
selective places.




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1503-1504
+llvm::DINodeArray Annotations = nullptr;
+if (field->hasAttr())
+  Annotations = CollectBTFTagAnnotations(field);
+

dblaikie wrote:
> could the `hasAttr` test be sunk into the `CollectBTFTagAnnotations` 
> function? (so it's not repeated at all the callers)
Good idea. Will change based on your suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106616

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


[PATCH] D108469: Improve handling of static assert messages.

2021-08-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 367844.
cor3ntin added a comment.

Remove superfluous assert


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
  clang/test/Lexer/null-character-in-literal.c
  clang/test/Misc/diag-special-chars.c
  clang/test/PCH/cxx-static_assert.cpp
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
  clang/test/SemaCXX/static-assert.cpp
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/Unicode.cpp

Index: llvm/lib/Support/Unicode.cpp
===
--- llvm/lib/Support/Unicode.cpp
+++ llvm/lib/Support/Unicode.cpp
@@ -20,198 +20,256 @@
 namespace unicode {
 
 bool isPrintable(int UCS) {
-  // Sorted list of non-overlapping intervals of code points that are not
-  // supposed to be printable.
-  static const UnicodeCharRange NonPrintableRanges[] = {
-{ 0x, 0x001F }, { 0x007F, 0x009F }, { 0x034F, 0x034F },
-{ 0x0378, 0x0379 }, { 0x037F, 0x0383 }, { 0x038B, 0x038B },
-{ 0x038D, 0x038D }, { 0x03A2, 0x03A2 }, { 0x0528, 0x0530 },
-{ 0x0557, 0x0558 }, { 0x0560, 0x0560 }, { 0x0588, 0x0588 },
-{ 0x058B, 0x058E }, { 0x0590, 0x0590 }, { 0x05C8, 0x05CF },
-{ 0x05EB, 0x05EF }, { 0x05F5, 0x0605 }, { 0x061C, 0x061D },
-{ 0x06DD, 0x06DD }, { 0x070E, 0x070F }, { 0x074B, 0x074C },
-{ 0x07B2, 0x07BF }, { 0x07FB, 0x07FF }, { 0x082E, 0x082F },
-{ 0x083F, 0x083F }, { 0x085C, 0x085D }, { 0x085F, 0x089F },
-{ 0x08A1, 0x08A1 }, { 0x08AD, 0x08E3 }, { 0x08FF, 0x08FF },
-{ 0x0978, 0x0978 }, { 0x0980, 0x0980 }, { 0x0984, 0x0984 },
-{ 0x098D, 0x098E }, { 0x0991, 0x0992 }, { 0x09A9, 0x09A9 },
-{ 0x09B1, 0x09B1 }, { 0x09B3, 0x09B5 }, { 0x09BA, 0x09BB },
-{ 0x09C5, 0x09C6 }, { 0x09C9, 0x09CA }, { 0x09CF, 0x09D6 },
-{ 0x09D8, 0x09DB }, { 0x09DE, 0x09DE }, { 0x09E4, 0x09E5 },
-{ 0x09FC, 0x0A00 }, { 0x0A04, 0x0A04 }, { 0x0A0B, 0x0A0E },
-{ 0x0A11, 0x0A12 }, { 0x0A29, 0x0A29 }, { 0x0A31, 0x0A31 },
-{ 0x0A34, 0x0A34 }, { 0x0A37, 0x0A37 }, { 0x0A3A, 0x0A3B },
-{ 0x0A3D, 0x0A3D }, { 0x0A43, 0x0A46 }, { 0x0A49, 0x0A4A },
-{ 0x0A4E, 0x0A50 }, { 0x0A52, 0x0A58 }, { 0x0A5D, 0x0A5D },
-{ 0x0A5F, 0x0A65 }, { 0x0A76, 0x0A80 }, { 0x0A84, 0x0A84 },
-{ 0x0A8E, 0x0A8E }, { 0x0A92, 0x0A92 }, { 0x0AA9, 0x0AA9 },
-{ 0x0AB1, 0x0AB1 }, { 0x0AB4, 0x0AB4 }, { 0x0ABA, 0x0ABB },
-{ 0x0AC6, 0x0AC6 }, { 0x0ACA, 0x0ACA }, { 0x0ACE, 0x0ACF },
-{ 0x0AD1, 0x0ADF }, { 0x0AE4, 0x0AE5 }, { 0x0AF2, 0x0B00 },
-{ 0x0B04, 0x0B04 }, { 0x0B0D, 0x0B0E }, { 0x0B11, 0x0B12 },
-{ 0x0B29, 0x0B29 }, { 0x0B31, 0x0B31 }, { 0x0B34, 0x0B34 },
-{ 0x0B3A, 0x0B3B }, { 0x0B45, 0x0B46 }, { 0x0B49, 0x0B4A },
-{ 0x0B4E, 0x0B55 }, { 0x0B58, 0x0B5B }, { 0x0B5E, 0x0B5E },
-{ 0x0B64, 0x0B65 }, { 0x0B78, 0x0B81 }, { 0x0B84, 0x0B84 },
-{ 0x0B8B, 0x0B8D }, { 0x0B91, 0x0B91 }, { 0x0B96, 0x0B98 },
-{ 0x0B9B, 0x0B9B }, { 0x0B9D, 0x0B9D }, { 0x0BA0, 0x0BA2 },
-{ 0x0BA5, 0x0BA7 }, { 0x0BAB, 0x0BAD }, { 0x0BBA, 0x0BBD },
-{ 0x0BC3, 0x0BC5 }, { 0x0BC9, 0x0BC9 }, { 0x0BCE, 0x0BCF },
-{ 0x0BD1, 0x0BD6 }, { 0x0BD8, 0x0BE5 }, { 0x0BFB, 0x0C00 },
-{ 0x0C04, 0x0C04 }, { 0x0C0D, 0x0C0D }, { 0x0C11, 0x0C11 },
-{ 0x0C29, 0x0C29 }, { 0x0C34, 0x0C34 }, { 0x0C3A, 0x0C3C },
-{ 0x0C45, 0x0C45 }, { 0x0C49, 0x0C49 }, { 0x0C4E, 0x0C54 },
-{ 0x0C57, 0x0C57 }, { 0x0C5A, 0x0C5F }, { 0x0C64, 0x0C65 },
-{ 0x0C70, 0x0C77 }, { 0x0C80, 0x0C81 }, { 0x0C84, 0x0C84 },
-{ 0x0C8D, 0x0C8D }, { 0x0C91, 0x0C91 }, { 0x0CA9, 0x0CA9 },
-{ 0x0CB4, 0x0CB4 }, { 0x0CBA, 0x0CBB }, { 0x0CC5, 0x0CC5 },
-{ 0x0CC9, 0x0CC9 }, { 0x0CCE, 0x0CD4 }, { 0x0CD7, 0x0CDD },
-{ 0x0CDF, 0x0CDF }, { 0x0CE4, 0x0CE5 }, { 0x0CF0, 0x0CF0 },
-{ 0x0CF3, 0x0D01 }, { 0x0D04, 0x0D04 }, { 0x0D0D, 0x0D0D },
-{ 0x0D11, 0x0D11 }, { 0x0D3B, 0x0D3C }, { 0x0D45, 0x0D45 },
-{ 0x0D49, 0x0D49 }, { 0x0D4F, 0x0D56 }, { 0x0D58, 0x0D5F },
-{ 0x0D64, 0x0D65 }, { 0x0D76, 0x0D78 }, { 0x0D80, 0x0D81 },
-{ 0x0D84, 0x0D84 }, { 0x0D97, 0x0D99 }, { 0x0DB2, 0x0DB2 },
-{ 0x0DBC, 0x0DBC }, { 0x0DBE, 0x0DBF }, { 0x0DC7, 0x0DC9 },
-{ 0x0DCB, 0x0DCE }, { 0x0DD5, 0x0DD5 }, { 0x0DD7, 0x0DD7 },
-{ 0x0DE0, 0x0DF1 }, { 0x0DF5, 0x0E00 }, { 0x0E3B, 0x0E3E },
-{ 0x0E5C, 0x0E80 }, { 0x0E83, 0x0E83 }, { 0x0E85, 0x0E86 },
-{ 0x0E89, 0x0E89 }, { 0x0E8B, 0x0E8C }, { 0x0E8E, 0x0E93 },
-{ 0x0E98, 0x0E98 }, { 0x0EA0, 0x0EA0 }, { 0x0EA4, 0x0EA4 },
-{ 0x0EA6, 0x0EA6 }, { 0x0EA8, 0x0EA9 }, { 0x0EAC, 0x0EAC },
-{ 0x0EBA, 0x0EBA }, { 0x0EBE, 0x0EBF }, { 0x0EC5, 0x0EC5 },
-{ 0x0EC7, 0x0EC7 }, { 0x0ECE, 0x0ECF }, { 0x0EDA, 0x0EDB },
-{ 0x0EE0, 0x0EFF }, { 0x0F48,

[PATCH] D108407: [CodeGen][WIP] Avoid generating Record layouts for pointee types

2021-08-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I have no problem with breaking LLVM analyses that rely on record types being 
filled in when they don't need to be.  I've been consistently telling people 
for years that they shouldn't be relying on IR types for things like that.

I would stick with the frontend terminology of a "complete" type, though.  And 
you might consider adding a function to CGT which completes a type, both for 
clarity and so that you can fast-path the common case where you've already got 
a sized type.

You can probably rip out the UpdateCompletedType logic when you're done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108407

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


[PATCH] D108469: Improve handling of static assert messages.

2021-08-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 367840.
cor3ntin added a comment.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.

- Add more tests
- Add a table for format codepoints - which we want to output

as is. These include among other ZWJ (for emojis) and LTR/RTL 
marks.

- At the same time, update the unicode tables to Unicode 13.

(We may want to move all the unicode tables 
(there are some in clang and some in llvm) in the same place for 
better maintainance in the future!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
  clang/test/Lexer/null-character-in-literal.c
  clang/test/Misc/diag-special-chars.c
  clang/test/PCH/cxx-static_assert.cpp
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
  clang/test/SemaCXX/static-assert.cpp
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/Unicode.cpp

Index: llvm/lib/Support/Unicode.cpp
===
--- llvm/lib/Support/Unicode.cpp
+++ llvm/lib/Support/Unicode.cpp
@@ -20,198 +20,256 @@
 namespace unicode {
 
 bool isPrintable(int UCS) {
-  // Sorted list of non-overlapping intervals of code points that are not
-  // supposed to be printable.
-  static const UnicodeCharRange NonPrintableRanges[] = {
-{ 0x, 0x001F }, { 0x007F, 0x009F }, { 0x034F, 0x034F },
-{ 0x0378, 0x0379 }, { 0x037F, 0x0383 }, { 0x038B, 0x038B },
-{ 0x038D, 0x038D }, { 0x03A2, 0x03A2 }, { 0x0528, 0x0530 },
-{ 0x0557, 0x0558 }, { 0x0560, 0x0560 }, { 0x0588, 0x0588 },
-{ 0x058B, 0x058E }, { 0x0590, 0x0590 }, { 0x05C8, 0x05CF },
-{ 0x05EB, 0x05EF }, { 0x05F5, 0x0605 }, { 0x061C, 0x061D },
-{ 0x06DD, 0x06DD }, { 0x070E, 0x070F }, { 0x074B, 0x074C },
-{ 0x07B2, 0x07BF }, { 0x07FB, 0x07FF }, { 0x082E, 0x082F },
-{ 0x083F, 0x083F }, { 0x085C, 0x085D }, { 0x085F, 0x089F },
-{ 0x08A1, 0x08A1 }, { 0x08AD, 0x08E3 }, { 0x08FF, 0x08FF },
-{ 0x0978, 0x0978 }, { 0x0980, 0x0980 }, { 0x0984, 0x0984 },
-{ 0x098D, 0x098E }, { 0x0991, 0x0992 }, { 0x09A9, 0x09A9 },
-{ 0x09B1, 0x09B1 }, { 0x09B3, 0x09B5 }, { 0x09BA, 0x09BB },
-{ 0x09C5, 0x09C6 }, { 0x09C9, 0x09CA }, { 0x09CF, 0x09D6 },
-{ 0x09D8, 0x09DB }, { 0x09DE, 0x09DE }, { 0x09E4, 0x09E5 },
-{ 0x09FC, 0x0A00 }, { 0x0A04, 0x0A04 }, { 0x0A0B, 0x0A0E },
-{ 0x0A11, 0x0A12 }, { 0x0A29, 0x0A29 }, { 0x0A31, 0x0A31 },
-{ 0x0A34, 0x0A34 }, { 0x0A37, 0x0A37 }, { 0x0A3A, 0x0A3B },
-{ 0x0A3D, 0x0A3D }, { 0x0A43, 0x0A46 }, { 0x0A49, 0x0A4A },
-{ 0x0A4E, 0x0A50 }, { 0x0A52, 0x0A58 }, { 0x0A5D, 0x0A5D },
-{ 0x0A5F, 0x0A65 }, { 0x0A76, 0x0A80 }, { 0x0A84, 0x0A84 },
-{ 0x0A8E, 0x0A8E }, { 0x0A92, 0x0A92 }, { 0x0AA9, 0x0AA9 },
-{ 0x0AB1, 0x0AB1 }, { 0x0AB4, 0x0AB4 }, { 0x0ABA, 0x0ABB },
-{ 0x0AC6, 0x0AC6 }, { 0x0ACA, 0x0ACA }, { 0x0ACE, 0x0ACF },
-{ 0x0AD1, 0x0ADF }, { 0x0AE4, 0x0AE5 }, { 0x0AF2, 0x0B00 },
-{ 0x0B04, 0x0B04 }, { 0x0B0D, 0x0B0E }, { 0x0B11, 0x0B12 },
-{ 0x0B29, 0x0B29 }, { 0x0B31, 0x0B31 }, { 0x0B34, 0x0B34 },
-{ 0x0B3A, 0x0B3B }, { 0x0B45, 0x0B46 }, { 0x0B49, 0x0B4A },
-{ 0x0B4E, 0x0B55 }, { 0x0B58, 0x0B5B }, { 0x0B5E, 0x0B5E },
-{ 0x0B64, 0x0B65 }, { 0x0B78, 0x0B81 }, { 0x0B84, 0x0B84 },
-{ 0x0B8B, 0x0B8D }, { 0x0B91, 0x0B91 }, { 0x0B96, 0x0B98 },
-{ 0x0B9B, 0x0B9B }, { 0x0B9D, 0x0B9D }, { 0x0BA0, 0x0BA2 },
-{ 0x0BA5, 0x0BA7 }, { 0x0BAB, 0x0BAD }, { 0x0BBA, 0x0BBD },
-{ 0x0BC3, 0x0BC5 }, { 0x0BC9, 0x0BC9 }, { 0x0BCE, 0x0BCF },
-{ 0x0BD1, 0x0BD6 }, { 0x0BD8, 0x0BE5 }, { 0x0BFB, 0x0C00 },
-{ 0x0C04, 0x0C04 }, { 0x0C0D, 0x0C0D }, { 0x0C11, 0x0C11 },
-{ 0x0C29, 0x0C29 }, { 0x0C34, 0x0C34 }, { 0x0C3A, 0x0C3C },
-{ 0x0C45, 0x0C45 }, { 0x0C49, 0x0C49 }, { 0x0C4E, 0x0C54 },
-{ 0x0C57, 0x0C57 }, { 0x0C5A, 0x0C5F }, { 0x0C64, 0x0C65 },
-{ 0x0C70, 0x0C77 }, { 0x0C80, 0x0C81 }, { 0x0C84, 0x0C84 },
-{ 0x0C8D, 0x0C8D }, { 0x0C91, 0x0C91 }, { 0x0CA9, 0x0CA9 },
-{ 0x0CB4, 0x0CB4 }, { 0x0CBA, 0x0CBB }, { 0x0CC5, 0x0CC5 },
-{ 0x0CC9, 0x0CC9 }, { 0x0CCE, 0x0CD4 }, { 0x0CD7, 0x0CDD },
-{ 0x0CDF, 0x0CDF }, { 0x0CE4, 0x0CE5 }, { 0x0CF0, 0x0CF0 },
-{ 0x0CF3, 0x0D01 }, { 0x0D04, 0x0D04 }, { 0x0D0D, 0x0D0D },
-{ 0x0D11, 0x0D11 }, { 0x0D3B, 0x0D3C }, { 0x0D45, 0x0D45 },
-{ 0x0D49, 0x0D49 }, { 0x0D4F, 0x0D56 }, { 0x0D58, 0x0D5F },
-{ 0x0D64, 0x0D65 }, { 0x0D76, 0x0D78 }, { 0x0D80, 0x0D81 },
-{ 0x0D84, 0x0D84 }, { 0x0D97, 0x0D99 }, { 0x0DB2, 0x0DB2 },
-{ 0x0DBC, 0x0DBC }, { 0x0DBE, 0x0DBF }, { 0x0DC7, 0x0DC9 },
-{ 0x0DCB, 0x0DCE }, { 0x0DD5, 0x0DD5 }, { 0x0DD7, 0x0DD7 },
-{ 0x0DE0, 0x0DF1 }, { 0x0DF5, 0x0E00 }, { 0x0E3B, 0x0E3E 

[PATCH] D108360: [clang][NFC] Remove dead code

2021-08-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added a reviewer: Anastasia.
rjmccall added a comment.

Hi, Andy.  This patch is obviously okay, although it makes me wonder if it was 
introduced by a patch collision or something similar that needs closer 
attention.  CC'ing Anastasia.

I'm not sure that I agree with your overall plan, though:

- The WebAssembly operand stack is not a good match for an address space at the 
language level because it's not addressable at all.  If you can't meaningfully 
have a pointer into the address space, then you don't really need this in the 
type system; it's more like a declaration modifier at best.
- Allocating local variables on the operand stack ought to be a very 
straightforward analysis in the backend.  There's not much optimization value 
in trying to do it in the frontend, and it's going to be problematic for things 
like coroutine lowering.
- The security argument seems pretty weak, not because security isn't important 
but because this is not really an adequate basis for getting the tamper-proof 
guarantee you want.  For example, LLVM passes can and do introduce its own 
allocas and store scalars into them sometimes.  Really you need some sort of 
"tamper-proof" *type* which the compiler can make an end-to-end guarantee of 
non-tamper-ability for the values of, and while optimally this would be 
implemented by just keeping values on the operand stack, in the general case 
you will need to have some sort of strategy for keeping things in memory.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108360

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


[PATCH] D85223: [CUDA][HIP] Support accessing static device variable in host code for -fgpu-rdc

2021-08-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:6265-6268
+void CodeGenModule::printPostfixForExternalizedStaticVar(
+llvm::raw_ostream &OS) const {
+  OS << ".static." << getContext().getCUIDHash();
+}

Hahnfeld wrote:
> I've tried to use this with CUDA, but it errors out because `.` is not 
> allowed in identifiers. Could you check if https://reviews.llvm.org/D108456 
> also works for HIP?
I will try it with our CI and get back to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85223

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


[PATCH] D107394: [AIX] "aligned" attribute does not decrease alignment

2021-08-20 Thread Steven Wan via Phabricator via cfe-commits
stevewan added inline comments.



Comment at: clang/lib/AST/RecordLayoutBuilder.cpp:1975
+  bool AlignAttrCanDecreaseAlignment =
+  AlignIsRequired && (Ty->getAs() != nullptr || FieldPacked);
+

rjmccall wrote:
> Okay, so first off, the comment and variable names here make this sound very 
> general when in fact this computation is only relevant to the AIX alignment 
> upgrade logic.  Also, please do not introduce new variables with broad scope 
> named things like `Ty` that are actually referring to a very specific type 
> and not, say, the unadulterated type of the field.
> 
> It seems to me that the right way to think about this is that, while the AIX 
> power alignment upgrade considers whether field type alignment is "required", 
> it uses a different condition than the standard rule when making that 
> decision.  It's important to understand what that rule is exactly, and we 
> can't see that from the current test cases.  In particular, attributes on 
> fields that define structs inline actually end up applying to both the field 
> and the struct, which confounds unrelated issues.  Consider:
> 
> ```
> struct __attribute__((packed, aligned(2))) SS {
>   double d;
> };
> 
> struct S {
>   // Neither the field nor the struct are packed, but the field type is.
>   // Do we apply the alignment upgrade to S or not?
>   struct SS s;
> };
> ```
> 
> Regardless, I don't think this check for a typedef works; it's bypassing 
> quite a bit of recursive logic for computing whether type alignment is 
> required.  For example, you could have an explicitly aligned typedef of an 
> array type, and you'll lose that typedef here.
Thanks for the review. 

> the comment and variable names here make this sound very general when in fact 
> this computation is only relevant to the AIX alignment upgrade logic.
Moved the variable declarations back to the AIX alignment upgrade logic. 
>  It's important to understand what that rule is exactly, and we can't see 
> that from the current test cases.
Updated the test cases accordingly.
> For example, you could have an explicitly aligned typedef of an array type, 
> and you'll lose that typedef here.
Updated the check to examine the immediate type rather than the base element 
type, this should take care of the array-type considerations. 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107394

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


[PATCH] D108450: [clang][CodeGen] GetDefaultAlignTempAlloca uses preferred alignment

2021-08-20 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Sure, I guess there's no harm in this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108450

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


[PATCH] D108458: [clang][CodeGen] Add default constructor for Address. NFC.

2021-08-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

You can still use a type without a default constructor in a `DenseMap`; you 
just have to use `insert` instead of `dict[key] = ...`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108458

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


[PATCH] D107394: [AIX] "aligned" attribute does not decrease alignment

2021-08-20 Thread Steven Wan via Phabricator via cfe-commits
stevewan updated this revision to Diff 367833.
stevewan added a comment.

Address comments about the check


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107394

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
  clang/test/Layout/aix-type-align-and-pack-attr.cpp

Index: clang/test/Layout/aix-type-align-and-pack-attr.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-type-align-and-pack-attr.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+namespace test1 {
+struct __attribute__((__aligned__(2))) S {
+  double d;
+};
+
+S s;
+
+// CHECK: @{{.*}}test1{{.*}}s{{.*}} = global %"struct.test1::S" zeroinitializer, align 8
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2), packed)) S {
+  double d;
+};
+
+S s;
+
+// CHECK: @{{.*}}test2{{.*}}s{{.*}} = global %"struct.test2::S" zeroinitializer, align 2
+} // namespace test2
+
+namespace test3 {
+struct __attribute__((__aligned__(16))) S {
+  double d;
+};
+
+S s;
+
+// CHECK: @{{.*}}test3{{.*}}s{{.*}} = global %"struct.test3::S" zeroinitializer, align 16
+} // namespace test3
+
+namespace test4 {
+struct __attribute__((aligned(2))) SS {
+  double d;
+};
+
+struct S {
+  struct SS ss;
+} s;
+
+// CHECK: @{{.*}}test4{{.*}}s{{.*}} = global %"struct.test4::S" zeroinitializer, align 8
+} // namespace test4
+
+namespace test5 {
+struct __attribute__((aligned(2), packed)) SS {
+  double d;
+};
+
+struct S {
+  struct SS ss;
+} s;
+
+// CHECK: @{{.*}}test5{{.*}}s{{.*}} = global %"struct.test5::S" zeroinitializer, align 2
+} // namespace test5
Index: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
===
--- clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
-// RUN:   FileCheck %s
-
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
-// RUN:   FileCheck %s
-
-namespace test1 {
-struct __attribute__((__aligned__(2))) C {
-  double x;
-} c;
-
-// CHECK: @{{.*}}test1{{.*}}c{{.*}} = global %"struct.test1::C" zeroinitializer, align 8
-} // namespace test1
-
-namespace test2 {
-struct __attribute__((__aligned__(2), packed)) C {
-  double x;
-} c;
-
-// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" zeroinitializer, align 2
-} // namespace test2
-
-namespace test3 {
-struct __attribute__((__aligned__(16))) C {
-  double x;
-} c;
-
-// CHECK: @{{.*}}test3{{.*}}c{{.*}} = global %"struct.test3::C" zeroinitializer, align 16
-} // namespace test3
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1978,7 +1978,7 @@
   // and zero-width bit-fields count as prior members; members of empty class
   // types marked `no_unique_address` are not considered to be prior members.
   CharUnits PreferredAlign = FieldAlign;
-  if (DefaultsToAIXPowerAlignment && !AlignIsRequired &&
+  if (DefaultsToAIXPowerAlignment &&
   (FoundFirstNonOverlappingEmptyFieldForAIX || IsNaturalAlign)) {
 auto performBuiltinTypeAlignmentUpgrade = [&](const BuiltinType *BTy) {
   if (BTy->getKind() == BuiltinType::Double ||
@@ -1989,16 +1989,25 @@
   }
 };
 
-const Type *Ty = D->getType()->getBaseElementTypeUnsafe();
-if (const ComplexType *CTy = Ty->getAs()) {
-  performBuiltinTypeAlignmentUpgrade(CTy->getElementType()->castAs());
-} else if (const BuiltinType *BTy = Ty->getAs()) {
-  performBuiltinTypeAlignmentUpgrade(BTy);
-} else if (const RecordType *RT = Ty->getAs()) {
-  const RecordDecl *RD = RT->getDecl();
-  assert(RD && "Expected non-null RecordDecl.");
-  const ASTRecordLayout &FieldRecord = Context.getASTRecordLayout(RD);
-  PreferredAlign = FieldRecord.getPreferredAlignment();
+const Type *Ty = D->getType().getTypePtr();
+const Type *BaseTy = Ty->getBaseElementTypeUnsafe();
+// When used as part of a typedef, or together with a 'packed' attribute,
+// the 'aligned' attribute can be used to decrease alignment. In that case,
+// it overrides any computed alignment we have, and there is no need to
+// upgrade the alignment.
+if (!AlignIsRequired ||
+Ty->getTypeClass() != Type::Typedef && !FieldPacked) {
+  if (const ComplexType *CTy = BaseTy->getAs()) {
+performBuiltinTypeAlignmentUpgrade(
+CTy->getElementType()->castAs());
+  } else if (const BuiltinType *BTy = BaseTy->getAs()) {
+performBuiltinType

[PATCH] D108445: [clang][NFC] GetOrCreateLLVMGlobal takes LangAS

2021-08-20 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108445

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


[PATCH] D106620: [Clang][LLVM] generate btf_tag annotations for func parameters

2021-08-20 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Sounds good


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106620

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


[PATCH] D106619: [Clang][LLVM] generate btf_tag annotations for DIGlobalVariable

2021-08-20 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Sounds good.

(any chance have you measured/could you measure how much larger the bitcode 
for, say, an LLVM self-host Debug build gets with all these btf patches? (even 
without targeting/using btf, this is adding an extra field to lots of the debug 
info metadata, and I'd like to know whether that makes an observable difference 
in file size))


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106619

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


[PATCH] D108456: [CUDA] Fix static device variables with -fgpu-rdc

2021-08-20 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:6450
 llvm::raw_ostream &OS) const {
-  OS << ".static." << getContext().getCUIDHash();
+  OS << "__static__" << getContext().getCUIDHash();
 }

I would expect  NVPTXAssignValidGlobalNames.cpp to deal with this ptx quirk. 
I'm fine with the underscores, but it would be good we're not just covering up 
an issue somewhere else.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108456

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


[PATCH] D106616: [Clang][LLVM] generate btf_tag annotations for DIDerived types

2021-08-20 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Sounds good. Please do the `hasAttr`/`CollectBTFTagAnnotations` refactor in a 
separate preliminary commit (cleaning up any existing callers that have the 
null check like that), then commit this in two parts, llvm first, then clang.




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1503-1504
+llvm::DINodeArray Annotations = nullptr;
+if (field->hasAttr())
+  Annotations = CollectBTFTagAnnotations(field);
+

could the `hasAttr` test be sunk into the `CollectBTFTagAnnotations` function? 
(so it's not repeated at all the callers)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106616

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


[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-08-20 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn added a comment.

In D104854#2957490 , @lebedev.ri 
wrote:

> In D104854#2957471 , @sepavloff 
> wrote:
>
>> In D104854#2957423 , @spatel wrote:
>>
>>> Is it intentional that we are not canonicalizing the intrinsic call back to 
>>> `fcmp uno` in the default FP environment?
>>
>> It is lowered to unordered comparison by default. Changing `llvm.isnan` to  
>> `fcmp uno` somewhere in IR would make it possible to optimize out the latter 
>> if fast-math mode is on. Preserving semantics of `isnan` when fast-math is 
>> in effect was one of the goals of this change.
>
> Eeek. Was there an RFC about this?
> This does not sound good to me at all,
> much like "let's not apply fast-math flags to x86 vector intrinsics".

We can switch into and out of the default FP environment inside a single 
function. If we want different behavior based on the FP environment then this 
should be a constrained intrinsic. Then the intrinsic would know the FP 
environment, or at least enough about it to know if traps and FP status bits 
are relevant.

I think the distinction is constrained vs non-constrained because FMF can 
optionally be used in both cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[clang] b1efefa - Revert "[openmp][nfc] Refactor GridValues"

2021-08-20 Thread Jon Chesterfield via cfe-commits

Author: Jon Chesterfield
Date: 2021-08-20T18:17:27+01:00
New Revision: b1efeface70c26f2f2e30636943c02f356ce4faa

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

LOG: Revert "[openmp][nfc] Refactor GridValues"

Failed a nvptx codegen test
This reverts commit 2a47a84b40115b01e03e4d89c1d47ba74beb7bf3.

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Basic/Targets/AMDGPU.h
clang/lib/Basic/Targets/NVPTX.cpp
clang/lib/Basic/Targets/NVPTX.h
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
llvm/include/llvm/Frontend/OpenMP/OMPGridValues.h

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index fe6f67d40b53..ab855948b447 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -210,6 +210,9 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   unsigned char RegParmMax, SSERegParmMax;
   TargetCXXABI TheCXXABI;
   const LangASMap *AddrSpaceMap;
+  const llvm::omp::GV *GridValues =
+  nullptr; // target-specific GPU grid values that must be
+   // consistent between host RTL (plugin), device RTL, and clang.
 
   mutable StringRef PlatformName;
   mutable VersionTuple PlatformMinVersion;
@@ -1407,10 +1410,10 @@ class TargetInfo : public virtual 
TransferrableTargetInfo,
 return LangAS::Default;
   }
 
-  // access target-specific GPU grid values that must be consistent between
-  // host RTL (plugin), deviceRTL and clang.
-  virtual const llvm::omp::GV &getGridValue() const {
-llvm_unreachable("getGridValue not implemented on this target");
+  /// Return a target-specific GPU grid values
+  const llvm::omp::GV &getGridValue() const {
+assert(GridValues != nullptr && "GridValues not initialized");
+return *GridValues;
   }
 
   /// Retrieve the name of the platform as it is used in the

diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index ba7ffa34c73e..cebb19e7ccab 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -17,6 +17,7 @@
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPGridValues.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -334,6 +335,7 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple 
&Triple,
   llvm::AMDGPU::getArchAttrR600(GPUKind)) {
   resetDataLayout(isAMDGCN(getTriple()) ? DataLayoutStringAMDGCN
 : DataLayoutStringR600);
+  GridValues = &llvm::omp::AMDGPUGridValues;
 
   setAddressSpaceMap(Triple.getOS() == llvm::Triple::Mesa3D ||
  !isAMDGCN(Triple));

diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index e791a83f38ae..77c2c5fd5014 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -370,10 +370,6 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
 return getLangASFromTargetAS(Constant);
   }
 
-  const llvm::omp::GV &getGridValue() const override {
-return llvm::omp::AMDGPUGridValues;
-  }
-
   /// \returns Target specific vtbl ptr address space.
   unsigned getVtblPtrAddressSpace() const override {
 return static_cast(Constant);

diff  --git a/clang/lib/Basic/Targets/NVPTX.cpp 
b/clang/lib/Basic/Targets/NVPTX.cpp
index c245753c93f4..d1a34e4a81c5 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -16,6 +16,7 @@
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPGridValues.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -64,6 +65,7 @@ NVPTXTargetInfo::NVPTXTargetInfo(const llvm::Triple &Triple,
   TLSSupported = false;
   VLASupported = false;
   AddrSpaceMap = &NVPTXAddrSpaceMap;
+  GridValues = &llvm::omp::NVPTXGridValues;
   UseAddrSpaceMapMangling = true;
 
   // Define available target features

diff  --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h
index ef751b8e1a8d..c7db3cdaaf10 100644
--- a/clang/lib/Basic/Targets/NVPTX.h
+++ b/clang/lib/Basic/Targets/NVPTX.h
@@ -147,10 +147,6 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public 
TargetInfo {
 Opts["cl_khr_local_int32_extended_atomics"] = true;
   }
 
-  const llvm::omp::GV &getGridValue() const override {
-return llvm::omp::NVPTXGridValues;
-  }
-
   /// \returns If a target requires an address within a target specific address
   /// space \p AddressSpace to be converted in order to be used, then return 
the
   /// 

[PATCH] D108422: [NFC][clang] Move remaining part of X86Target.def to llvm/Support/X86TargetParser.def

2021-08-20 Thread Andrei Elovikov via Phabricator via cfe-commits
a.elovikov updated this revision to Diff 367821.
a.elovikov added a comment.

Remove stale FIXME comment in the code being moved


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108422

Files:
  clang/include/clang/Basic/X86Target.def
  clang/lib/Basic/Targets/X86.cpp
  llvm/include/llvm/Support/X86TargetParser.def

Index: llvm/include/llvm/Support/X86TargetParser.def
===
--- llvm/include/llvm/Support/X86TargetParser.def
+++ llvm/include/llvm/Support/X86TargetParser.def
@@ -208,3 +208,49 @@
 X86_FEATURE   (LVI_LOAD_HARDENING,  "lvi-load-hardening")
 #undef X86_FEATURE_COMPAT
 #undef X86_FEATURE
+
+#ifndef CPU_SPECIFIC
+#define CPU_SPECIFIC(NAME, MANGLING, FEATURES)
+#endif
+
+#ifndef CPU_SPECIFIC_ALIAS
+#define CPU_SPECIFIC_ALIAS(NEW_NAME, NAME)
+#endif
+
+CPU_SPECIFIC("generic", 'A', "")
+CPU_SPECIFIC("pentium", 'B', "")
+CPU_SPECIFIC("pentium_pro", 'C', "+cmov")
+CPU_SPECIFIC("pentium_mmx", 'D', "+mmx")
+CPU_SPECIFIC("pentium_ii", 'E', "+cmov,+mmx")
+CPU_SPECIFIC("pentium_iii", 'H', "+cmov,+mmx,+sse")
+CPU_SPECIFIC_ALIAS("pentium_iii_no_xmm_regs", "pentium_iii")
+CPU_SPECIFIC("pentium_4", 'J', "+cmov,+mmx,+sse,+sse2")
+CPU_SPECIFIC("pentium_m", 'K', "+cmov,+mmx,+sse,+sse2")
+CPU_SPECIFIC("pentium_4_sse3", 'L', "+cmov,+mmx,+sse,+sse2,+sse3")
+CPU_SPECIFIC("core_2_duo_ssse3", 'M', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3")
+CPU_SPECIFIC("core_2_duo_sse4_1", 'N', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1")
+CPU_SPECIFIC("atom", 'O', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+movbe")
+CPU_SPECIFIC("atom_sse4_2", 'c', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt")
+CPU_SPECIFIC("core_i7_sse4_2", 'P', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt")
+CPU_SPECIFIC("core_aes_pclmulqdq", 'Q', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt")
+CPU_SPECIFIC("atom_sse4_2_movbe", 'd', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt")
+CPU_SPECIFIC("goldmont", 'i', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt")
+CPU_SPECIFIC("sandybridge", 'R', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx")
+CPU_SPECIFIC_ALIAS("core_2nd_gen_avx", "sandybridge")
+CPU_SPECIFIC("ivybridge", 'S', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+f16c,+avx")
+CPU_SPECIFIC_ALIAS("core_3rd_gen_avx", "ivybridge")
+CPU_SPECIFIC("haswell", 'V', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2")
+CPU_SPECIFIC_ALIAS("core_4th_gen_avx", "haswell")
+CPU_SPECIFIC("core_4th_gen_avx_tsx", 'W', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2")
+CPU_SPECIFIC("broadwell", 'X', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx")
+CPU_SPECIFIC_ALIAS("core_5th_gen_avx", "broadwell")
+CPU_SPECIFIC("core_5th_gen_avx_tsx", 'Y', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx")
+CPU_SPECIFIC("knl", 'Z', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512f,+adx,+avx512er,+avx512pf,+avx512cd")
+CPU_SPECIFIC_ALIAS("mic_avx512", "knl")
+CPU_SPECIFIC("skylake", 'b', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx,+mpx")
+CPU_SPECIFIC( "skylake_avx512", 'a', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512dq,+avx512f,+adx,+avx512cd,+avx512bw,+avx512vl,+clwb")
+CPU_SPECIFIC("cannonlake", 'e', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512dq,+avx512f,+adx,+avx512ifma,+avx512cd,+avx512bw,+avx512vl,+avx512vbmi")
+CPU_SPECIFIC("knm", 'j', "+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512f,+adx,+avx512er,+avx512pf,+avx512cd,+avx5124fmaps,+avx5124vnniw,+avx512vpopcntdq")
+
+#undef CPU_SPECIFIC_ALIAS
+#undef CPU_SPECIFIC
Index: clang/lib/Basic/Targets/X86.cpp
===
--- clang/lib/Basic/Targets/X86.cpp
+++ clang/lib/Basic/Targets/X86.cpp
@@ -1103,21 +1103,21 @@
   return llvm::StringSwitch(Name)
 #define CPU_SPECIFIC(NAME, MANGLING, FEATURES) .Case(NAME, true)
 #define CPU_SPECIFIC_ALIAS(NEW_NAME, NAME) .Case(NEW_NAME, true)
-#include "clang/Basic/X86Target.def"
+#include "llvm/Support/X86TargetParser.def"
   .Default(false);
 }
 
 static StringRef CPUSpecificCPUDispatchNameDealias(StringRef Name) {
   return llvm::StringSwitch(Name)
 #define CPU_SPECIFIC_ALIAS(NEW_NAME, NAME) .Case(NEW_NAME, NAME)
-#include "clang/Basic/X86Target.def"
+#include "llvm/Support/X86TargetParser.def"
   .Default(Name);
 }
 
 char X86TargetInfo::CPUSpecificManglingC

[PATCH] D108469: Improve handling of static assert messages.

2021-08-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Basic/Diagnostic.cpp:818
+  llvm::raw_string_ostream stream(number);
+  stream << "";
+  OutStr.append(number.begin(), number.end());

jfb wrote:
> We don't have a better hex formatter? 😟
> Not a big deal, but I'd hoped that ADT had something!
There are a few hex formatter, none that pads to a minimum size!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

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


[PATCH] D108422: [NFC][clang] Move remaining part of X86Target.def to llvm/Support/X86TargetParser.def

2021-08-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: llvm/include/llvm/Support/X86TargetParser.def:220
+
+// FIXME: When commented out features are supported in LLVM, enable them here.
+CPU_SPECIFIC("generic", 'A', "")

a.elovikov wrote:
> craig.topper wrote:
> > erichkeane wrote:
> > > RKSimon wrote:
> > > > what commented out features?
> > > So this is copy/pasted from: 
> > > https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/X86Target.def#L70
> > >  (where it will probably be removed in a future patch?).
> > > 
> > > That comment came from here: https://reviews.llvm.org/D47474
> > > 
> > > If you look at the 'diff' here: 
> > > https://reviews.llvm.org/D47474?vs=148894&id=156484#toc (1st patch vs 
> > > last)  You can see that the original used a bitmask to create the values 
> > > rather than the string list (as suggested by @craig.topper in the 
> > > review).  That version had some commented out in the bitmasks.
> > > 
> > > However, I never removed the comment!  So this comment likely should just 
> > > be deleted.
> > I'm not sure the commented out features made it over. For example, 
> > FEATURE_TSX was one of the commented out values, but +tsx doesn't appear in 
> > these strings.
> > where it will probably be removed in a future patch?
> 
> Not sure what you mean - the whole file is being removed as part of this 
> change.
> > where it will probably be removed in a future patch?
> 
> Not sure what you mean - the whole file is being removed as part of this 
> change.

Ah! Missed that!  Phab seems to have changed how it displays deleted files!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108422

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


[PATCH] D108469: Improve handling of static assert messages.

2021-08-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D108469#2957652 , @jfb wrote:

> I worry that changing the general `static_assert` printing (adding a colon, 
> and dropping the quotes) will get @hwright's law to drop on us. We can try 
> and see if e.g. users of clang have automated checks for `static_assert` in 
> their CI pipelines or something. I think your new format looks better, but 
> Hyrum is finicky that way... What do others think?
>
> Can you add tests for other special characters, to make sure they're all 
> handled properly? Just copy/paste my twitter shitpost might be sufficient? I 
> think I covered all the corner cases in it, gotta be thorough!

It's funny that you mention that because my code filters out LTR/RTL... I 
should probably change that!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

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


[PATCH] D108422: [NFC][clang] Move remaining part of X86Target.def to llvm/Support/X86TargetParser.def

2021-08-20 Thread Andrei Elovikov via Phabricator via cfe-commits
a.elovikov added inline comments.



Comment at: llvm/include/llvm/Support/X86TargetParser.def:220
+
+// FIXME: When commented out features are supported in LLVM, enable them here.
+CPU_SPECIFIC("generic", 'A', "")

craig.topper wrote:
> erichkeane wrote:
> > RKSimon wrote:
> > > what commented out features?
> > So this is copy/pasted from: 
> > https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/X86Target.def#L70
> >  (where it will probably be removed in a future patch?).
> > 
> > That comment came from here: https://reviews.llvm.org/D47474
> > 
> > If you look at the 'diff' here: 
> > https://reviews.llvm.org/D47474?vs=148894&id=156484#toc (1st patch vs last) 
> >  You can see that the original used a bitmask to create the values rather 
> > than the string list (as suggested by @craig.topper in the review).  That 
> > version had some commented out in the bitmasks.
> > 
> > However, I never removed the comment!  So this comment likely should just 
> > be deleted.
> I'm not sure the commented out features made it over. For example, 
> FEATURE_TSX was one of the commented out values, but +tsx doesn't appear in 
> these strings.
> where it will probably be removed in a future patch?

Not sure what you mean - the whole file is being removed as part of this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108422

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


[PATCH] D108380: [openmp][nfc] Refactor GridValues

2021-08-20 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

Failed a nvptx codegen test (maybe the change to calculate log2 at runtime), 
currently away from my desk but will revert when I get back unless beaten to it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108380

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


[PATCH] D108469: Improve handling of static assert messages.

2021-08-20 Thread JF Bastien via Phabricator via cfe-commits
jfb added a subscriber: hwright.
jfb added a comment.

I worry that changing the general `static_assert` printing (adding a colon, and 
dropping the quotes) will get @hwright's law to drop on us. We can try and see 
if e.g. users of clang have automated checks for `static_assert` in their CI 
pipelines or something. I think your new format looks better, but Hyrum is 
finicky that way... What do others think?

Can you add tests for other special characters, to make sure they're all 
handled properly? Just copy/paste my twitter shitpost might be sufficient? I 
think I covered all the corner cases in it, gotta be thorough!




Comment at: clang/lib/Basic/Diagnostic.cpp:818
+  llvm::raw_string_ostream stream(number);
+  stream << "";
+  OutStr.append(number.begin(), number.end());

We don't have a better hex formatter? 😟
Not a big deal, but I'd hoped that ADT had something!



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16361
+  if (AssertMessage) {
+assert(isa(AssertMessage));
+if (StringLiteral *MsgStr = cast(AssertMessage)) {

`cast` should already handle this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

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


[clang] 5cf5df8 - [X86] Add missing __inline__ to functions in amxintrin.h

2021-08-20 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2021-08-20T09:35:02-07:00
New Revision: 5cf5df8014acc21c95f05f74bccf26144f6be5dc

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

LOG: [X86] Add missing __inline__ to functions in amxintrin.h

Added: 


Modified: 
clang/lib/Headers/amxintrin.h

Removed: 




diff  --git a/clang/lib/Headers/amxintrin.h b/clang/lib/Headers/amxintrin.h
index ec601a58e7c3..4940666e8083 100644
--- a/clang/lib/Headers/amxintrin.h
+++ b/clang/lib/Headers/amxintrin.h
@@ -314,8 +314,8 @@ typedef struct __tile1024i_str {
 /// \param stride
 ///The stride between the rows' data to be loaded in memory.
 __DEFAULT_FN_ATTRS_TILE
-static void __tile_loadd(__tile1024i *dst, const void *base,
- __SIZE_TYPE__ stride) {
+static __inline__ void __tile_loadd(__tile1024i *dst, const void *base,
+__SIZE_TYPE__ stride) {
   dst->tile = _tile_loadd_internal(dst->row, dst->col, base, stride);
 }
 
@@ -335,8 +335,8 @@ static void __tile_loadd(__tile1024i *dst, const void *base,
 /// \param stride
 ///The stride between the rows' data to be loaded in memory.
 __DEFAULT_FN_ATTRS_TILE
-static void __tile_stream_loadd(__tile1024i *dst, const void *base,
-__SIZE_TYPE__ stride) {
+static __inline__ void __tile_stream_loadd(__tile1024i *dst, const void *base,
+   __SIZE_TYPE__ stride) {
   dst->tile = _tile_loaddt1_internal(dst->row, dst->col, base, stride);
 }
 
@@ -357,8 +357,8 @@ static void __tile_stream_loadd(__tile1024i *dst, const 
void *base,
 /// \param src1
 ///The 2nd source tile. Max size is 1024 Bytes.
 __DEFAULT_FN_ATTRS_INT8
-static void __tile_dpbssd(__tile1024i *dst, __tile1024i src0,
-  __tile1024i src1) {
+static __inline__ void __tile_dpbssd(__tile1024i *dst, __tile1024i src0,
+ __tile1024i src1) {
   dst->tile = _tile_dpbssd_internal(src0.row, src1.col, src0.col, dst->tile,
 src0.tile, src1.tile);
 }
@@ -380,8 +380,8 @@ static void __tile_dpbssd(__tile1024i *dst, __tile1024i 
src0,
 /// \param src1
 ///The 2nd source tile. Max size is 1024 Bytes.
 __DEFAULT_FN_ATTRS_INT8
-static void __tile_dpbsud(__tile1024i *dst, __tile1024i src0,
-  __tile1024i src1) {
+static __inline__ void __tile_dpbsud(__tile1024i *dst, __tile1024i src0,
+ __tile1024i src1) {
   dst->tile = _tile_dpbsud_internal(src0.row, src1.col, src0.col, dst->tile,
 src0.tile, src1.tile);
 }
@@ -403,8 +403,8 @@ static void __tile_dpbsud(__tile1024i *dst, __tile1024i 
src0,
 /// \param src1
 ///The 2nd source tile. Max size is 1024 Bytes.
 __DEFAULT_FN_ATTRS_INT8
-static void __tile_dpbusd(__tile1024i *dst, __tile1024i src0,
-  __tile1024i src1) {
+static __inline__ void __tile_dpbusd(__tile1024i *dst, __tile1024i src0,
+ __tile1024i src1) {
   dst->tile = _tile_dpbusd_internal(src0.row, src1.col, src0.col, dst->tile,
 src0.tile, src1.tile);
 }
@@ -426,8 +426,8 @@ static void __tile_dpbusd(__tile1024i *dst, __tile1024i 
src0,
 /// \param src1
 ///The 2nd source tile. Max size is 1024 Bytes.
 __DEFAULT_FN_ATTRS_INT8
-static void __tile_dpbuud(__tile1024i *dst, __tile1024i src0,
-  __tile1024i src1) {
+static __inline__ void __tile_dpbuud(__tile1024i *dst, __tile1024i src0,
+ __tile1024i src1) {
   dst->tile = _tile_dpbuud_internal(src0.row, src1.col, src0.col, dst->tile,
 src0.tile, src1.tile);
 }
@@ -446,7 +446,8 @@ static void __tile_dpbuud(__tile1024i *dst, __tile1024i 
src0,
 /// \param stride
 ///The stride between the rows' data to be stored in memory.
 __DEFAULT_FN_ATTRS_TILE
-static void __tile_stored(void *base, __SIZE_TYPE__ stride, __tile1024i src) {
+static __inline__ void __tile_stored(void *base, __SIZE_TYPE__ stride,
+ __tile1024i src) {
   _tile_stored_internal(src.row, src.col, base, stride, src.tile);
 }
 
@@ -459,7 +460,7 @@ static void __tile_stored(void *base, __SIZE_TYPE__ stride, 
__tile1024i src) {
 /// \param dst
 ///The destination tile to be zero. Max size is 1024 Bytes.
 __DEFAULT_FN_ATTRS_TILE
-static void __tile_zero(__tile1024i *dst) {
+static __inline__ void __tile_zero(__tile1024i *dst) {
   dst->tile = __builtin_ia32_tilezero_internal(dst->row, dst->col);
 }
 
@@ -479,8 +480,8 @@ static void __tile_zero(__tile1024i *dst) {
 /// \param src1
 ///The 2nd source tile. Max size is 1024 Bytes.
 __DEFAULT_FN_ATTRS_BF1

[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-08-20 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

In D104854#2957582 , @lebedev.ri 
wrote:

> In D104854#2957529 , @spatel wrote:
>
>> In D104854#2957471 , @sepavloff 
>> wrote:
>>
>>> In D104854#2957423 , @spatel 
>>> wrote:
>>>
 Is it intentional that we are not canonicalizing the intrinsic call back 
 to `fcmp uno` in the default FP environment?
>>>
>>> It is lowered to unordered comparison by default. Changing `llvm.isnan` to  
>>> `fcmp uno` somewhere in IR would make it possible to optimize out the 
>>> latter if fast-math mode is on. Preserving semantics of `isnan` when 
>>> fast-math is in effect was one of the goals of this change.
>>
>> I understand that the codegen was supposed to be no worse, but the 
>> difference in IR causes optimizer regressions like: 
>> https://llvm.org/PR51556
>>
>> If we want this intrinsic (and its siblings that haven't been created yet) 
>> to survive through IR, then we have to enhance IR passes to recognize the 
>> new patterns. 
>> It would be easier to do this in steps: (1) create the intrinsic only if not 
>> in the default FP env, (2) update IR analysis/passes to recognize the 
>> intrinsic, (3) create the intrinsic in the default FP env with no FMF, (4) 
>> create the intrinsic always.
>
> +1, but right now i'm not sold on the behavior of not optimizing away NaN 
> checks in no-NaN's mode.
> At least that part should be reconciled now. It *might* be an improvement, 
> but it caters to expectations
> of one group while catering away from the documentation and existing 
> expectations of other groups.
> This shouldn't be decided in a review, it should be driven by an RFC.

Agree. I think a revert followed by RFC to make sure there is consensus on 
semantics is needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[PATCH] D108469: Improve handling of static assert messages.

2021-08-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 367812.
cor3ntin added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
  clang/test/Lexer/null-character-in-literal.c
  clang/test/Misc/diag-special-chars.c
  clang/test/PCH/cxx-static_assert.cpp
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
  clang/test/SemaCXX/static-assert.cpp

Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -4,25 +4,25 @@
 
 static_assert(f(), "f"); // expected-error {{static_assert expression is not an integral constant expression}} expected-note {{non-constexpr function 'f' cannot be used in a constant expression}}
 static_assert(true, "true is not false");
-static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
+static_assert(false, "false is false"); // expected-error {{static_assert failed: false is false}}
 
 void g() {
-static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
+static_assert(false, "false is false"); // expected-error {{static_assert failed: false is false}}
 }
 
 class C {
-static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
+static_assert(false, "false is false"); // expected-error {{static_assert failed: false is false}}
 };
 
 template struct T {
-static_assert(N == 2, "N is not 2!"); // expected-error {{static_assert failed due to requirement '1 == 2' "N is not 2!"}}
+static_assert(N == 2, "N is not 2!"); // expected-error {{static_assert failed due to requirement '1 == 2': N is not 2!}}
 };
 
 T<1> t1; // expected-note {{in instantiation of template class 'T<1>' requested here}}
 T<2> t2;
 
 template struct S {
-static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); // expected-error {{static_assert failed due to requirement 'sizeof(char) > sizeof(char)' "Type not big enough!"}}
+static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); // expected-error {{static_assert failed due to requirement 'sizeof(char) > sizeof(char)': Type not big enough!}}
 };
 
 S s1; // expected-note {{in instantiation of template class 'S' requested here}}
@@ -67,7 +67,7 @@
   static const bool value = false;
 };
 
-static_assert(first_trait::value && second_trait::value, "message"); // expected-error{{static_assert failed due to requirement 'second_trait::value' "message"}}
+static_assert(first_trait::value && second_trait::value, "message"); // expected-error{{static_assert failed due to requirement 'second_trait::value': message}}
 
 namespace std {
 
@@ -111,29 +111,29 @@
 };
 
 static_assert(std::is_same::value, "message");
-// expected-error@-1{{static_assert failed due to requirement 'std::is_same::value' "message"}}
+// expected-error@-1{{static_assert failed due to requirement 'std::is_same::value': message}}
 static_assert(std::is_const::value, "message");
-// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value': message}}
 static_assert(!std::is_const::value, "message");
-// expected-error@-1{{static_assert failed due to requirement '!std::is_const::value' "message"}}
+// expected-error@-1{{static_assert failed due to requirement '!std::is_const::value': message}}
 static_assert(!(std::is_const::value), "message");
-// expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value)' "message"}}
+// expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value)': message}}
 static_assert(std::is_const::value == false, "message");
-// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value == false' "message"}}
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value == false': message}}
 static_assert(!(std::is_const::value == true), "message");
-// expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value == true)' "message"}}
+// expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value == true)': message}}
 static_assert(std::is_const(), "message");
-// expected-error@-1{{static_assert failed due to requirement 'std::is_const()' "message"}}
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const()': message}}
 static_assert(!(std::is_const()()), "message");
-// expected-error@-1{{static_assert failed due to requirement '!(std::is_const()())' "

[PATCH] D105759: [WIP] Implement P2361 Unevaluated string literals

2021-08-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 367811.
cor3ntin added a comment.

Fix diagnostic for avaibility attributes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105759

Files:
  clang-tools-extra/test/clang-tidy/checkers/modernize-unary-static-assert.cpp
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Lex/Pragma.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
  clang/test/CXX/dcl.dcl/p4-0x.cpp
  clang/test/FixIt/fixit-static-assert.cpp
  clang/test/Parser/asm.c
  clang/test/Parser/asm.cpp
  clang/test/Parser/attr-availability-xcore.c
  clang/test/Parser/attr-availability.c
  clang/test/Sema/asm.c
  clang/test/SemaCXX/static-assert.cpp

Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -28,12 +28,12 @@
 S s1; // expected-note {{in instantiation of template class 'S' requested here}}
 S s2;
 
-static_assert(false, L"\x"); // expected-error {{static_assert failed L"\x"}}
-static_assert(false, u"\U000317FF"); // expected-error {{static_assert failed u"\U000317FF"}}
+static_assert(false, L"\x"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}} expected-error {{hex escape sequence out of range}}
+static_assert(false, u"\U000317FF"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
 // FIXME: render this as u8"\u03A9"
-static_assert(false, u8"Ω"); // expected-error {{static_assert failed u8"\316\251"}}
-static_assert(false, L"\u1234"); // expected-error {{static_assert failed L"\x1234"}}
-static_assert(false, L"\x1ff" "0\x123" "fx\xf" "goop"); // expected-error {{static_assert failed L"\x1FF""0\x123""fx\xFgoop"}}
+static_assert(false, u8"Ω"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
+static_assert(false, L"\u1234"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
+static_assert(false, L"\x1ff" "0\x123" "fx\xf" "goop"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}} expected-error 3{{hex escape sequence out of range}}
 
 template struct AlwaysFails {
   // Only give one error here.
Index: clang/test/Sema/asm.c
===
--- clang/test/Sema/asm.c
+++ clang/test/Sema/asm.c
@@ -37,14 +37,17 @@
   asm ("nop" : "=c" (a) : "r" (no_clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
   asm ("nop" : "=r" (no_clobber_conflict) : "c" (c) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
   asm ("nop" : "=r" (clobber_conflict) : "c" (c) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
-  asm ("nop" : "=a" (a) : "b" (b) : "%rcx", "%rbx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}} 
+  asm("nop"
+  : "=a"(a)
+  : "b"(b)
+  : "%rcx", "%rbx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
 }
 
 // rdar://6094010
 void test3() {
   int x;
-  asm(L"foo" : "=r"(x)); // expected-error {{wide string}}
-  asm("foo" : L"=r"(x)); // expected-error {{wide string}}
+  asm(L"foo" : "=r"(x)); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
+  asm("foo" : L"=r"(x)); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
 }
 
 // 
Index: clang/test/Parser/attr-availability.c
===
--- clang/test/Parser/attr-availability.c
+++ clang/test/Parser/attr-availability.c
@@ -18,21 +18,25 @@
 
 void f6() __attribute__((availability(macosx,unavailable,introduced=10.5))); // expected-warning{{'unavailable' availability overrides all other availability information}}
 
-void f7() __attribute__((availability(macosx,message=L"wide"))); // expected-error {{expected string literal for optional message in 'availability' attribute}}
+void f7()

[PATCH] D108387: [WebAssembly] Restore builtins and intrinsics for pmin/pmax

2021-08-20 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG88962cea4680: [WebAssembly] Restore builtins and intrinsics 
for pmin/pmax (authored by tlively).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108387

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/wasm_simd128.h
  clang/test/CodeGen/builtins-wasm.c
  clang/test/Headers/wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -540,6 +540,26 @@
   ret <4 x float> %a
 }
 
+; CHECK-LABEL: pmin_v4f32:
+; CHECK-NEXT: .functype pmin_v4f32 (v128, v128) -> (v128){{$}}
+; CHECK-NEXT: f32x4.pmin $push[[R:[0-9]+]]=, $0, $1{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+declare <4 x float> @llvm.wasm.pmin.v4f32(<4 x float>, <4 x float>)
+define <4 x float> @pmin_v4f32(<4 x float> %a, <4 x float> %b) {
+  %v = call <4 x float> @llvm.wasm.pmin.v4f32(<4 x float> %a, <4 x float> %b)
+  ret <4 x float> %v
+}
+
+; CHECK-LABEL: pmax_v4f32:
+; CHECK-NEXT: .functype pmax_v4f32 (v128, v128) -> (v128){{$}}
+; CHECK-NEXT: f32x4.pmax $push[[R:[0-9]+]]=, $0, $1{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+declare <4 x float> @llvm.wasm.pmax.v4f32(<4 x float>, <4 x float>)
+define <4 x float> @pmax_v4f32(<4 x float> %a, <4 x float> %b) {
+  %v = call <4 x float> @llvm.wasm.pmax.v4f32(<4 x float> %a, <4 x float> %b)
+  ret <4 x float> %v
+}
+
 ; CHECK-LABEL: ceil_v4f32:
 ; CHECK-NEXT: .functype ceil_v4f32 (v128) -> (v128){{$}}
 ; CHECK-NEXT: f32x4.ceil $push[[R:[0-9]+]]=, $0{{$}}
@@ -595,6 +615,26 @@
   ret <2 x double> %a
 }
 
+; CHECK-LABEL: pmin_v2f64:
+; CHECK-NEXT: .functype pmin_v2f64 (v128, v128) -> (v128){{$}}
+; CHECK-NEXT: f64x2.pmin $push[[R:[0-9]+]]=, $0, $1{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+declare <2 x double> @llvm.wasm.pmin.v2f64(<2 x double>, <2 x double>)
+define <2 x double> @pmin_v2f64(<2 x double> %a, <2 x double> %b) {
+  %v = call <2 x double> @llvm.wasm.pmin.v2f64(<2 x double> %a, <2 x double> %b)
+  ret <2 x double> %v
+}
+
+; CHECK-LABEL: pmax_v2f64:
+; CHECK-NEXT: .functype pmax_v2f64 (v128, v128) -> (v128){{$}}
+; CHECK-NEXT: f64x2.pmax $push[[R:[0-9]+]]=, $0, $1{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+declare <2 x double> @llvm.wasm.pmax.v2f64(<2 x double>, <2 x double>)
+define <2 x double> @pmax_v2f64(<2 x double> %a, <2 x double> %b) {
+  %v = call <2 x double> @llvm.wasm.pmax.v2f64(<2 x double> %a, <2 x double> %b)
+  ret <2 x double> %v
+}
+
 ; CHECK-LABEL: ceil_v2f64:
 ; CHECK-NEXT: .functype ceil_v2f64 (v128) -> (v128){{$}}
 ; CHECK-NEXT: f64x2.ceil $push[[R:[0-9]+]]=, $0{{$}}
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
===
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
@@ -1175,6 +1175,16 @@
   (pmax $lhs, $rhs)>;
 }
 
+// And match the pmin/pmax LLVM intrinsics as well
+def : Pat<(v4f32 (int_wasm_pmin (v4f32 V128:$lhs), (v4f32 V128:$rhs))),
+  (PMIN_F32x4 V128:$lhs, V128:$rhs)>;
+def : Pat<(v4f32 (int_wasm_pmax (v4f32 V128:$lhs), (v4f32 V128:$rhs))),
+  (PMAX_F32x4 V128:$lhs, V128:$rhs)>;
+def : Pat<(v2f64 (int_wasm_pmin (v2f64 V128:$lhs), (v2f64 V128:$rhs))),
+  (PMIN_F64x2 V128:$lhs, V128:$rhs)>;
+def : Pat<(v2f64 (int_wasm_pmax (v2f64 V128:$lhs), (v2f64 V128:$rhs))),
+  (PMAX_F64x2 V128:$lhs, V128:$rhs)>;
+
 //===--===//
 // Conversions
 //===--===//
Index: llvm/include/llvm/IR/IntrinsicsWebAssembly.td
===
--- llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -164,6 +164,15 @@
 [llvm_v8i16_ty, llvm_v8i16_ty],
 [IntrNoMem, IntrSpeculatable]>;
 
+def int_wasm_pmin :
+  Intrinsic<[llvm_anyvector_ty],
+[LLVMMatchType<0>, LLVMMatchType<0>],
+[IntrNoMem, IntrSpeculatable]>;
+def int_wasm_pmax :
+  Intrinsic<[llvm_anyvector_ty],
+[LLVMMatchType<0>, LLVMMatchType<0>],
+[IntrNoMem, IntrSpeculatable]>;
+
 def int_wasm_extadd_pairwise_signed :
   Intrinsic<[llvm_anyvector_ty],
 [LLVMSubdivide2VectorType<0>],
Index: clang/test/Headers/wasm.c
===
--- clang/test/Headers/wasm.c
+++ clang/test/Headers/wasm.c
@@ -2424,11 +2424,11 @@
 
 // CHECK-LABEL: @test_f32x

[clang] 88962ce - [WebAssembly] Restore builtins and intrinsics for pmin/pmax

2021-08-20 Thread Thomas Lively via cfe-commits

Author: Thomas Lively
Date: 2021-08-20T09:21:31-07:00
New Revision: 88962cea46805dbcc60524f7107030c986833052

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

LOG: [WebAssembly] Restore builtins and intrinsics for pmin/pmax

Partially reverts 85157c007903, which had removed these builtins and intrinsics
in favor of normal codegen patterns. It turns out that it is possible for the
patterns to be split over multiple basic blocks, however, which means that DAG
ISel is not able to select them to the pmin/pmax instructions. To make sure the
SIMD intrinsics generate the correct instructions in these cases, reintroduce
the clang builtins and corresponding LLVM intrinsics, but also keep the normal
pattern matching as well.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/wasm_simd128.h
clang/test/CodeGen/builtins-wasm.c
clang/test/Headers/wasm.c
llvm/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index 51a819efdee0..f5120b23f811 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -129,8 +129,12 @@ TARGET_BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc", 
"simd128")
 
 TARGET_BUILTIN(__builtin_wasm_min_f32x4, "V4fV4fV4f", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_max_f32x4, "V4fV4fV4f", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_pmin_f32x4, "V4fV4fV4f", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_pmax_f32x4, "V4fV4fV4f", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_min_f64x2, "V2dV2dV2d", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_max_f64x2, "V2dV2dV2d", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_pmin_f64x2, "V2dV2dV2d", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_pmax_f64x2, "V2dV2dV2d", "nc", "simd128")
 
 TARGET_BUILTIN(__builtin_wasm_ceil_f32x4, "V4fV4f", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_floor_f32x4, "V4fV4f", "nc", "simd128")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d74209ae27a4..89b773fc5f97 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17822,6 +17822,22 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 CGM.getIntrinsic(Intrinsic::maximum, ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_pmin_f32x4:
+  case WebAssembly::BI__builtin_wasm_pmin_f64x2: {
+Value *LHS = EmitScalarExpr(E->getArg(0));
+Value *RHS = EmitScalarExpr(E->getArg(1));
+Function *Callee =
+CGM.getIntrinsic(Intrinsic::wasm_pmin, ConvertType(E->getType()));
+return Builder.CreateCall(Callee, {LHS, RHS});
+  }
+  case WebAssembly::BI__builtin_wasm_pmax_f32x4:
+  case WebAssembly::BI__builtin_wasm_pmax_f64x2: {
+Value *LHS = EmitScalarExpr(E->getArg(0));
+Value *RHS = EmitScalarExpr(E->getArg(1));
+Function *Callee =
+CGM.getIntrinsic(Intrinsic::wasm_pmax, ConvertType(E->getType()));
+return Builder.CreateCall(Callee, {LHS, RHS});
+  }
   case WebAssembly::BI__builtin_wasm_ceil_f32x4:
   case WebAssembly::BI__builtin_wasm_floor_f32x4:
   case WebAssembly::BI__builtin_wasm_trunc_f32x4:

diff  --git a/clang/lib/Headers/wasm_simd128.h 
b/clang/lib/Headers/wasm_simd128.h
index 438a54526b33..3889a2769faf 100644
--- a/clang/lib/Headers/wasm_simd128.h
+++ b/clang/lib/Headers/wasm_simd128.h
@@ -1297,14 +1297,12 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS 
wasm_f32x4_max(v128_t __a,
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_f32x4_pmin(v128_t __a,
 v128_t __b) {
-  __i32x4 __mask = (__i32x4)((__f32x4)__b < (__f32x4)__a);
-  return (v128_t)__i32x4)__b) & __mask) | (((__i32x4)__a) & ~__mask));
+  return (v128_t)__builtin_wasm_pmin_f32x4((__f32x4)__a, (__f32x4)__b);
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_f32x4_pmax(v128_t __a,
 v128_t __b) {
-  __i32x4 __mask = (__i32x4)((__f32x4)__a < (__f32x4)__b);
-  return (v128_t)__i32x4)__b) & __mask) | (((__i32x4)__a) & ~__mask));
+  return (v128_t)__builtin_wasm_pmax_f32x4((__f32x4)__a, (__f32x4)__b);
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_f64x2_abs(v128_t __a) {
@@ -1367,14 +1365,12 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS 
wasm_f64x2_max(v128_t __a,
 
 static __inline__ v128_t __D

[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-08-20 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D104854#2957529 , @spatel wrote:

> In D104854#2957471 , @sepavloff 
> wrote:
>
>> In D104854#2957423 , @spatel wrote:
>>
>>> Is it intentional that we are not canonicalizing the intrinsic call back to 
>>> `fcmp uno` in the default FP environment?
>>
>> It is lowered to unordered comparison by default. Changing `llvm.isnan` to  
>> `fcmp uno` somewhere in IR would make it possible to optimize out the latter 
>> if fast-math mode is on. Preserving semantics of `isnan` when fast-math is 
>> in effect was one of the goals of this change.
>
> I understand that the codegen was supposed to be no worse, but the difference 
> in IR causes optimizer regressions like: 
> https://llvm.org/PR51556
>
> If we want this intrinsic (and its siblings that haven't been created yet) to 
> survive through IR, then we have to enhance IR passes to recognize the new 
> patterns. 
> It would be easier to do this in steps: (1) create the intrinsic only if not 
> in the default FP env, (2) update IR analysis/passes to recognize the 
> intrinsic, (3) create the intrinsic in the default FP env with no FMF, (4) 
> create the intrinsic always.

+1, but right now i'm not sold on the behavior of not optimizing away NaN 
checks in no-NaN's mode.
At least that part should be reconciled now. It *might* be an improvement, but 
it caters to expectations
of one group while catering away from the documentation and existing 
expectations of other groups.
This shouldn't be decided in a review, it should be driven by an RFC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[PATCH] D108301: [MSP430][Clang] Update hard-coded MCU data

2021-08-20 Thread Jozef Lawrynowicz via Phabricator via cfe-commits
jozefl updated this revision to Diff 367805.
jozefl added a comment.

Here's an updated patch to fix the win64 failure.

MSVC can't handle the conversion from a ForwardIterator to a const pointer when
the container being searched with std::lower_bound is a std::array. Meanwhile
clang-tidy warns when the type assigned to with the return value of
std::lower_bound is not a pointer, so I can't just change the type declaration
to a lone "auto", and surpressing the clang-tidy warning for this warning
doesn't seem like the best option either.

So I've changed the data type used to store the MCUData to a C-style array, and
also moved its definition into loadMCUData.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108301

Files:
  clang/include/clang/Basic/MSP430Target.def
  clang/lib/Driver/ToolChains/MSP430.cpp
  clang/test/Driver/msp430-hwmult.c
  clang/test/Driver/msp430-mmcu.c
  clang/test/Driver/msp430-toolchain.c

Index: clang/test/Driver/msp430-toolchain.c
===
--- clang/test/Driver/msp430-toolchain.c
+++ clang/test/Driver/msp430-toolchain.c
@@ -253,6 +253,10 @@
 // RUN:   | FileCheck -check-prefix=HWMult-32BIT %s
 // HWMult-32BIT: "--start-group" "-lmul_32"
 
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430fr5969 --sysroot="" 2>&1 \
+// RUN:   | FileCheck -check-prefix=HWMult-F5 %s
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430fr5969 -mhwmult=auto --sysroot="" 2>&1 \
+// RUN:   | FileCheck -check-prefix=HWMult-F5 %s
 // RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=f5series --sysroot="" 2>&1 \
 // RUN:   | FileCheck -check-prefix=HWMult-F5 %s
 // HWMult-F5: "--start-group" "-lmul_f5"
@@ -261,4 +265,10 @@
 // RUN:   | FileCheck -check-prefix=HWMult-NONE %s
 // RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=none -mmcu=msp430f4783 --sysroot="" 2>&1 \
 // RUN:   | FileCheck -check-prefix=HWMult-NONE %s
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=auto -mmcu=msp430 --sysroot="" 2>&1 \
+// RUN:   | FileCheck -check-prefix=HWMult-NONE %s
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=auto -mmcu=msp430x --sysroot="" 2>&1 \
+// RUN:   | FileCheck -check-prefix=HWMult-NONE %s
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430xv2 --sysroot="" 2>&1 \
+// RUN:   | FileCheck -check-prefix=HWMult-NONE %s
 // HWMult-NONE: "--start-group" "-lmul_none"
Index: clang/test/Driver/msp430-mmcu.c
===
--- clang/test/Driver/msp430-mmcu.c
+++ clang/test/Driver/msp430-mmcu.c
@@ -1,15 +1,62 @@
+// This file tests that various different values passed to -mmcu= select the
+// correct target features and linker scripts, and create MCU-specific defines.
+
+// Test the lexicographic ordering of MCUs in MSP430Target.def.
+//
+// The MCU "msp430f110" should appear before "msp430f1101" when the data has
+// been sorted lexicographically. Some sorts will put "msp430f110" *after*
+// "msp430f1101", so when this happens, Clang will not be able to find this MCU.
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f110 2>&1 \
+// RUN:   | FileCheck %s
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f1101 2>&1 \
+// RUN:   | FileCheck %s
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f1101a 2>&1 \
+// RUN:   | FileCheck %s
+
+// CHECK-NOT: error: the clang compiler does not support
+
+// Test the symbol definitions, linker scripts and hardware multiply features
+// selected for different MCUs.
+
 // RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430c111 2>&1 \
 // RUN:   | FileCheck -check-prefix=MSP430-C111 %s
 
 // MSP430-C111: clang{{.*}} "-cc1" {{.*}} "-D__MSP430C111__"
+// MSP430-C111-NOT: "-target-feature" "+hwmult16"
+// MSP430-C111-NOT: "-target-feature" "+hwmult32"
+// MSP430-C111-NOT: "-target-feature" "+hwmultf5"
 // MSP430-C111: msp430-elf-ld{{.*}} "-Tmsp430c111.ld"
 
 // RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430i2020 2>&1 \
 // RUN:   | FileCheck -check-prefix=MSP430-I2020 %s
 
 // MSP430-I2020: clang{{.*}} "-cc1" {{.*}} "-D__MSP430i2020__"
+// MSP430-I2020: "-target-feature" "+hwmult16"
 // MSP430-I2020: msp430-elf-ld{{.*}} "-Tmsp430i2020.ld"
 
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f47126 2>&1 \
+// RUN:   | FileCheck -check-prefix=MSP430-F47126 %s
+
+// MSP430-F47126: clang{{.*}} "-cc1" {{.*}} "-D__MSP430F47126__"
+// MSP430-F47126: "-target-feature" "+hwmult32"
+// MSP430-F47126: msp430-elf-ld{{.*}} "-Tmsp430f47126.ld"
+
+// RAN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430fr5969 2>&1 \
+// RAN:   | FileCheck -check-prefix=MSP430-FR5969 %s
+
+// MSP430-FR5969: clang{{.*}} "-

[PATCH] D108470: [OpenCL] Fix as_type3 invalid store creation

2021-08-20 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: Anastasia, jaykang10.
svenvh added a project: clang.
Herald added subscribers: ldrumm, yaxunl.
svenvh requested review of this revision.
Herald added a subscriber: cfe-commits.

With -fpreserve-vec3-type enabled, a cast was not created when
converting from a non-vec3 type to a vec3 type, even though a
conversion to vec3 was performed.  This resulted in creation of
invalid store instructions.

Related to D107963 , but now for the to-vec3 
case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108470

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGenOpenCL/preserve_vec3.cl


Index: clang/test/CodeGenOpenCL/preserve_vec3.cl
===
--- clang/test/CodeGenOpenCL/preserve_vec3.cl
+++ clang/test/CodeGenOpenCL/preserve_vec3.cl
@@ -53,3 +53,11 @@
   // CHECK: store <4 x i16> %[[ASTYPE]], <4 x i16> addrspace(1)* %[[OUT_BC]]
   *out = __builtin_astype(a, long);
 }
+
+void to_char3(int a, global char3 *out) {
+  // CHECK-LABEL: void @to_char3
+  // CHECK: %[[IN_BC:.*]] = bitcast i32 %a to <4 x i8>
+  // CHECK: %[[ASTYPE:.*]] = shufflevector <4 x i8> %[[IN_BC]], <4 x i8> 
poison, <3 x i32> 
+  // CHECK: store <3 x i8> %[[ASTYPE]], <3 x i8> addrspace(1)* %out
+  *out = __builtin_astype(a, char3);
+}
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -4796,12 +4796,10 @@
   // to vec4 if the original type is not vec4, then a shuffle vector to
   // get a vec3.
   if (NumElementsSrc != 3 && NumElementsDst == 3) {
-if (!CGF.CGM.getCodeGenOpts().PreserveVec3Type) {
-  auto *Vec4Ty = llvm::FixedVectorType::get(
-  cast(DstTy)->getElementType(), 4);
-  Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src,
- Vec4Ty);
-}
+auto *Vec4Ty = llvm::FixedVectorType::get(
+cast(DstTy)->getElementType(), 4);
+Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src,
+   Vec4Ty);
 
 Src = ConvertVec3AndVec4(Builder, CGF, Src, 3);
 Src->setName("astype");


Index: clang/test/CodeGenOpenCL/preserve_vec3.cl
===
--- clang/test/CodeGenOpenCL/preserve_vec3.cl
+++ clang/test/CodeGenOpenCL/preserve_vec3.cl
@@ -53,3 +53,11 @@
   // CHECK: store <4 x i16> %[[ASTYPE]], <4 x i16> addrspace(1)* %[[OUT_BC]]
   *out = __builtin_astype(a, long);
 }
+
+void to_char3(int a, global char3 *out) {
+  // CHECK-LABEL: void @to_char3
+  // CHECK: %[[IN_BC:.*]] = bitcast i32 %a to <4 x i8>
+  // CHECK: %[[ASTYPE:.*]] = shufflevector <4 x i8> %[[IN_BC]], <4 x i8> poison, <3 x i32> 
+  // CHECK: store <3 x i8> %[[ASTYPE]], <3 x i8> addrspace(1)* %out
+  *out = __builtin_astype(a, char3);
+}
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -4796,12 +4796,10 @@
   // to vec4 if the original type is not vec4, then a shuffle vector to
   // get a vec3.
   if (NumElementsSrc != 3 && NumElementsDst == 3) {
-if (!CGF.CGM.getCodeGenOpts().PreserveVec3Type) {
-  auto *Vec4Ty = llvm::FixedVectorType::get(
-  cast(DstTy)->getElementType(), 4);
-  Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src,
- Vec4Ty);
-}
+auto *Vec4Ty = llvm::FixedVectorType::get(
+cast(DstTy)->getElementType(), 4);
+Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src,
+   Vec4Ty);
 
 Src = ConvertVec3AndVec4(Builder, CGF, Src, 3);
 Src->setName("astype");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-08-20 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D104854#2957529 , @spatel wrote:

> In D104854#2957471 , @sepavloff 
> wrote:
>
>> In D104854#2957423 , @spatel wrote:
>>
>>> Is it intentional that we are not canonicalizing the intrinsic call back to 
>>> `fcmp uno` in the default FP environment?
>>
>> It is lowered to unordered comparison by default. Changing `llvm.isnan` to  
>> `fcmp uno` somewhere in IR would make it possible to optimize out the latter 
>> if fast-math mode is on. Preserving semantics of `isnan` when fast-math is 
>> in effect was one of the goals of this change.
>
> I understand that the codegen was supposed to be no worse, but the difference 
> in IR causes optimizer regressions like: 
> https://llvm.org/PR51556
>
> If we want this intrinsic (and its siblings that haven't been created yet) to 
> survive through IR, then we have to enhance IR passes to recognize the new 
> patterns. 
> It would be easier to do this in steps: (1) create the intrinsic only if not 
> in the default FP env, (2) update IR analysis/passes to recognize the 
> intrinsic, (3) create the intrinsic in the default FP env with no FMF, (4) 
> create the intrinsic always.

Meanwhile this should be reverted..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[PATCH] D108415: [WebAssembly] Make shift values unsigned in wasm_simd128.h

2021-08-20 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG64a9957bf7b6: [WebAssembly] Make shift values unsigned in 
wasm_simd128.h (authored by tlively).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108415

Files:
  clang/lib/Headers/wasm_simd128.h
  clang/test/Headers/wasm.c

Index: clang/test/Headers/wasm.c
===
--- clang/test/Headers/wasm.c
+++ clang/test/Headers/wasm.c
@@ -1603,7 +1603,7 @@
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[SHL_I]] to <4 x i32>
 // CHECK-NEXT:ret <4 x i32> [[TMP3]]
 //
-v128_t test_i8x16_shl(v128_t a, int32_t b) {
+v128_t test_i8x16_shl(v128_t a, uint32_t b) {
   return wasm_i8x16_shl(a, b);
 }
 
@@ -1617,7 +1617,7 @@
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[SHR_I]] to <4 x i32>
 // CHECK-NEXT:ret <4 x i32> [[TMP3]]
 //
-v128_t test_i8x16_shr(v128_t a, int32_t b) {
+v128_t test_i8x16_shr(v128_t a, uint32_t b) {
   return wasm_i8x16_shr(a, b);
 }
 
@@ -1631,7 +1631,7 @@
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[SHR_I]] to <4 x i32>
 // CHECK-NEXT:ret <4 x i32> [[TMP3]]
 //
-v128_t test_u8x16_shr(v128_t a, int32_t b) {
+v128_t test_u8x16_shr(v128_t a, uint32_t b) {
   return wasm_u8x16_shr(a, b);
 }
 
@@ -1824,7 +1824,7 @@
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <8 x i16> [[SHL_I]] to <4 x i32>
 // CHECK-NEXT:ret <4 x i32> [[TMP3]]
 //
-v128_t test_i16x8_shl(v128_t a, int32_t b) {
+v128_t test_i16x8_shl(v128_t a, uint32_t b) {
   return wasm_i16x8_shl(a, b);
 }
 
@@ -1838,7 +1838,7 @@
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <8 x i16> [[SHR_I]] to <4 x i32>
 // CHECK-NEXT:ret <4 x i32> [[TMP3]]
 //
-v128_t test_i16x8_shr(v128_t a, int32_t b) {
+v128_t test_i16x8_shr(v128_t a, uint32_t b) {
   return wasm_i16x8_shr(a, b);
 }
 
@@ -1852,7 +1852,7 @@
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <8 x i16> [[SHR_I]] to <4 x i32>
 // CHECK-NEXT:ret <4 x i32> [[TMP3]]
 //
-v128_t test_u16x8_shr(v128_t a, int32_t b) {
+v128_t test_u16x8_shr(v128_t a, uint32_t b) {
   return wasm_u16x8_shr(a, b);
 }
 
@@ -2048,7 +2048,7 @@
 // CHECK-NEXT:[[SHL_I:%.*]] = shl <4 x i32> [[A:%.*]], [[SPLAT_SPLAT_I]]
 // CHECK-NEXT:ret <4 x i32> [[SHL_I]]
 //
-v128_t test_i32x4_shl(v128_t a, int32_t b) {
+v128_t test_i32x4_shl(v128_t a, uint32_t b) {
   return wasm_i32x4_shl(a, b);
 }
 
@@ -2059,7 +2059,7 @@
 // CHECK-NEXT:[[SHR_I:%.*]] = ashr <4 x i32> [[A:%.*]], [[SPLAT_SPLAT_I]]
 // CHECK-NEXT:ret <4 x i32> [[SHR_I]]
 //
-v128_t test_i32x4_shr(v128_t a, int32_t b) {
+v128_t test_i32x4_shr(v128_t a, uint32_t b) {
   return wasm_i32x4_shr(a, b);
 }
 
@@ -2070,7 +2070,7 @@
 // CHECK-NEXT:[[SHR_I:%.*]] = lshr <4 x i32> [[A:%.*]], [[SPLAT_SPLAT_I]]
 // CHECK-NEXT:ret <4 x i32> [[SHR_I]]
 //
-v128_t test_u32x4_shr(v128_t a, int32_t b) {
+v128_t test_u32x4_shr(v128_t a, uint32_t b) {
   return wasm_u32x4_shr(a, b);
 }
 
@@ -2198,42 +2198,42 @@
 // CHECK-LABEL: @test_i64x2_shl(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <2 x i64>
-// CHECK-NEXT:[[CONV_I:%.*]] = sext i32 [[B:%.*]] to i64
+// CHECK-NEXT:[[CONV_I:%.*]] = zext i32 [[B:%.*]] to i64
 // CHECK-NEXT:[[SPLAT_SPLATINSERT_I:%.*]] = insertelement <2 x i64> poison, i64 [[CONV_I]], i32 0
 // CHECK-NEXT:[[SPLAT_SPLAT_I:%.*]] = shufflevector <2 x i64> [[SPLAT_SPLATINSERT_I]], <2 x i64> poison, <2 x i32> zeroinitializer
 // CHECK-NEXT:[[SHL_I:%.*]] = shl <2 x i64> [[TMP0]], [[SPLAT_SPLAT_I]]
 // CHECK-NEXT:[[TMP1:%.*]] = bitcast <2 x i64> [[SHL_I]] to <4 x i32>
 // CHECK-NEXT:ret <4 x i32> [[TMP1]]
 //
-v128_t test_i64x2_shl(v128_t a, int32_t b) {
+v128_t test_i64x2_shl(v128_t a, uint32_t b) {
   return wasm_i64x2_shl(a, b);
 }
 
 // CHECK-LABEL: @test_i64x2_shr(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <2 x i64>
-// CHECK-NEXT:[[CONV_I:%.*]] = sext i32 [[B:%.*]] to i64
+// CHECK-NEXT:[[CONV_I:%.*]] = zext i32 [[B:%.*]] to i64
 // CHECK-NEXT:[[SPLAT_SPLATINSERT_I:%.*]] = insertelement <2 x i64> poison, i64 [[CONV_I]], i32 0
 // CHECK-NEXT:[[SPLAT_SPLAT_I:%.*]] = shufflevector <2 x i64> [[SPLAT_SPLATINSERT_I]], <2 x i64> poison, <2 x i32> zeroinitializer
 // CHECK-NEXT:[[SHR_I:%.*]] = ashr <2 x i64> [[TMP0]], [[SPLAT_SPLAT_I]]
 // CHECK-NEXT:[[TMP1:%.*]] = bitcast <2 x i64> [[SHR_I]] to <4 x i32>
 // CHECK-NEXT:ret <4 x i32> [[TMP1]]
 //
-v128_t test_i64x2_shr(v128_t a, int32_t b) {
+v128_t test_i64x2_shr(v128_t a, uint32_t b) {
   return wasm_i64x2_shr(a, b);
 }
 
 // CHECK-LABEL: @test_u64x2_shr(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <2 x i64>
-// CHECK-NEXT:[[CONV_I:%.*]] = sext i32 [[B:%.*]] to i64
+// CHECK-NEXT:[[CONV_I:%.*]] = zext i32 [[B:%.*]] to i64
 // CHECK-NEXT:[[SPLAT_SPLATINS

[clang] 64a9957 - [WebAssembly] Make shift values unsigned in wasm_simd128.h

2021-08-20 Thread Thomas Lively via cfe-commits

Author: Thomas Lively
Date: 2021-08-20T09:10:37-07:00
New Revision: 64a9957bf7b65a0d10819918ac2a565d69e9c4bb

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

LOG: [WebAssembly] Make shift values unsigned in wasm_simd128.h

On some platforms, negative shift values mean to shift in the opposite
direction, but this is not true with WebAssembly. To avoid confusion, make the
shift values in the shift intrinsics unsigned.

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

Added: 


Modified: 
clang/lib/Headers/wasm_simd128.h
clang/test/Headers/wasm.c

Removed: 




diff  --git a/clang/lib/Headers/wasm_simd128.h 
b/clang/lib/Headers/wasm_simd128.h
index 498898acaf8a..438a54526b33 100644
--- a/clang/lib/Headers/wasm_simd128.h
+++ b/clang/lib/Headers/wasm_simd128.h
@@ -960,17 +960,17 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS 
wasm_i8x16_popcnt(v128_t __a) {
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_shl(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__i8x16)__a << __b);
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_shr(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__i8x16)__a >> __b);
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_shr(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__u8x16)__a >> __b);
 }
 
@@ -1046,17 +1046,17 @@ static __inline__ uint32_t __DEFAULT_FN_ATTRS 
wasm_i16x8_bitmask(v128_t __a) {
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_shl(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__i16x8)__a << __b);
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_shr(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__i16x8)__a >> __b);
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u16x8_shr(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__u16x8)__a >> __b);
 }
 
@@ -1137,17 +1137,17 @@ static __inline__ uint32_t __DEFAULT_FN_ATTRS 
wasm_i32x4_bitmask(v128_t __a) {
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i32x4_shl(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__i32x4)__a << __b);
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i32x4_shr(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__i32x4)__a >> __b);
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u32x4_shr(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__u32x4)__a >> __b);
 }
 
@@ -1208,17 +1208,17 @@ static __inline__ uint32_t __DEFAULT_FN_ATTRS 
wasm_i64x2_bitmask(v128_t __a) {
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i64x2_shl(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__i64x2)__a << (int64_t)__b);
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i64x2_shr(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__i64x2)__a >> (int64_t)__b);
 }
 
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u64x2_shr(v128_t __a,
-   int32_t __b) {
+   uint32_t __b) {
   return (v128_t)((__u64x2)__a >> (int64_t)__b);
 }
 

diff  --git a/clang/test/Headers/wasm.c b/clang/test/Headers/wasm.c
index 72f20b1520fd..ba7d3dc71f2b 100644
--- a/clang/test/Headers/wasm.c
+++ b/clang/test/Headers/wasm.c
@@ -1603,7 +1603,7 @@ v128_t test_i8x16_popcnt(v128_t a) {
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[SHL_I]] to <4 x

[PATCH] D108469: Improve handling of static assert messages.

2021-08-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 367802.
cor3ntin retitled this revision from "Improve handling of static assert 
messages.

Instead of dumping the string literal (which
quotes it and escape every non-ascii symbol),
we can use the content of the string
(which we know is valid UTF-8 by virtue if being a
unevaluated string)." to "Improve handling of static assert messages.".
cor3ntin edited the summary of this revision.
cor3ntin added a comment.

Fix avaibility attribute diagnostics


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
  clang/test/Lexer/null-character-in-literal.c
  clang/test/Misc/diag-special-chars.c
  clang/test/PCH/cxx-static_assert.cpp
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
  clang/test/SemaCXX/static-assert.cpp

Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -4,25 +4,25 @@
 
 static_assert(f(), "f"); // expected-error {{static_assert expression is not an integral constant expression}} expected-note {{non-constexpr function 'f' cannot be used in a constant expression}}
 static_assert(true, "true is not false");
-static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
+static_assert(false, "false is false"); // expected-error {{static_assert failed: false is false}}
 
 void g() {
-static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
+static_assert(false, "false is false"); // expected-error {{static_assert failed: false is false}}
 }
 
 class C {
-static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
+static_assert(false, "false is false"); // expected-error {{static_assert failed: false is false}}
 };
 
 template struct T {
-static_assert(N == 2, "N is not 2!"); // expected-error {{static_assert failed due to requirement '1 == 2' "N is not 2!"}}
+static_assert(N == 2, "N is not 2!"); // expected-error {{static_assert failed due to requirement '1 == 2': N is not 2!}}
 };
 
 T<1> t1; // expected-note {{in instantiation of template class 'T<1>' requested here}}
 T<2> t2;
 
 template struct S {
-static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); // expected-error {{static_assert failed due to requirement 'sizeof(char) > sizeof(char)' "Type not big enough!"}}
+static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); // expected-error {{static_assert failed due to requirement 'sizeof(char) > sizeof(char)': Type not big enough!}}
 };
 
 S s1; // expected-note {{in instantiation of template class 'S' requested here}}
@@ -67,7 +67,7 @@
   static const bool value = false;
 };
 
-static_assert(first_trait::value && second_trait::value, "message"); // expected-error{{static_assert failed due to requirement 'second_trait::value' "message"}}
+static_assert(first_trait::value && second_trait::value, "message"); // expected-error{{static_assert failed due to requirement 'second_trait::value': message}}
 
 namespace std {
 
@@ -111,29 +111,29 @@
 };
 
 static_assert(std::is_same::value, "message");
-// expected-error@-1{{static_assert failed due to requirement 'std::is_same::value' "message"}}
+// expected-error@-1{{static_assert failed due to requirement 'std::is_same::value': message}}
 static_assert(std::is_const::value, "message");
-// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value': message}}
 static_assert(!std::is_const::value, "message");
-// expected-error@-1{{static_assert failed due to requirement '!std::is_const::value' "message"}}
+// expected-error@-1{{static_assert failed due to requirement '!std::is_const::value': message}}
 static_assert(!(std::is_const::value), "message");
-// expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value)' "message"}}
+// expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value)': message}}
 static_assert(std::is_const::value == false, "message");
-// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value == false' "message"}}
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value == false': message}}
 static_assert(!(std::is_const::value == true), "message");
-// expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value == true)' "message"}}
+// expected-error@-1{{static_assert failed due to requirement

[PATCH] D108422: [NFC][clang] Move remaining part of X86Target.def to llvm/Support/X86TargetParser.def

2021-08-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a subscriber: LuoYuanke.
erichkeane added a comment.

In D108422#2957528 , @RKSimon wrote:

> There's nothing later than CannonLake here - does Intel need to at least 
> reference up to Tiger/Rocketlake?

@LuoYuanke ^^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108422

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


[PATCH] D108469: Improve handling of static assert messages. Instead of dumping the string literal (which quotes it and escape every non-ascii symbol), we can use the content of the string (which we

2021-08-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a subscriber: martong.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

...g).

`FormatDiagnostic` is modified to escape
non printable characters and invalid UTF-8.

This ensures that unicode characters, spaces and new
lines are properly rendered in static messages.
This make clang more consistent with other implementation
and fixes this tweet
https://twitter.com/jfbastien/status/1298307325443231744 :)

Of note, `PaddingChecker` did print out new lines that were 
later remove by the diagnostic printing code.
To be consistent with its tests, the new lines are removed
from the diagnostic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108469

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
  clang/test/Lexer/null-character-in-literal.c
  clang/test/Misc/diag-special-chars.c
  clang/test/PCH/cxx-static_assert.cpp
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
  clang/test/SemaCXX/static-assert.cpp

Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -4,25 +4,25 @@
 
 static_assert(f(), "f"); // expected-error {{static_assert expression is not an integral constant expression}} expected-note {{non-constexpr function 'f' cannot be used in a constant expression}}
 static_assert(true, "true is not false");
-static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
+static_assert(false, "false is false"); // expected-error {{static_assert failed: false is false}}
 
 void g() {
-static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
+static_assert(false, "false is false"); // expected-error {{static_assert failed: false is false}}
 }
 
 class C {
-static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
+static_assert(false, "false is false"); // expected-error {{static_assert failed: false is false}}
 };
 
 template struct T {
-static_assert(N == 2, "N is not 2!"); // expected-error {{static_assert failed due to requirement '1 == 2' "N is not 2!"}}
+static_assert(N == 2, "N is not 2!"); // expected-error {{static_assert failed due to requirement '1 == 2': N is not 2!}}
 };
 
 T<1> t1; // expected-note {{in instantiation of template class 'T<1>' requested here}}
 T<2> t2;
 
 template struct S {
-static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); // expected-error {{static_assert failed due to requirement 'sizeof(char) > sizeof(char)' "Type not big enough!"}}
+static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); // expected-error {{static_assert failed due to requirement 'sizeof(char) > sizeof(char)': Type not big enough!}}
 };
 
 S s1; // expected-note {{in instantiation of template class 'S' requested here}}
@@ -67,7 +67,7 @@
   static const bool value = false;
 };
 
-static_assert(first_trait::value && second_trait::value, "message"); // expected-error{{static_assert failed due to requirement 'second_trait::value' "message"}}
+static_assert(first_trait::value && second_trait::value, "message"); // expected-error{{static_assert failed due to requirement 'second_trait::value': message}}
 
 namespace std {
 
@@ -111,29 +111,29 @@
 };
 
 static_assert(std::is_same::value, "message");
-// expected-error@-1{{static_assert failed due to requirement 'std::is_same::value' "message"}}
+// expected-error@-1{{static_assert failed due to requirement 'std::is_same::value': message}}
 static_assert(std::is_const::value, "message");
-// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value': message}}
 static_assert(!std::is_const::value, "message");
-// expected-error@-1{{static_assert failed due to requirement '!std::is_const::value' "message"}}
+// expected-error@-1{{static_assert failed due to requirement '!std::is_const::value': message}}
 static_assert(!(std::is_const::value), "message");
-// expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value)' "message"}}
+// expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value)': message}}
 static_assert(std::is_const::value == false, "message");
-// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value == false' "message"}}
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value == false': message}}
 static_assert(!(std::is_const::value == true), "message");
-// expected-error@-1{{s

[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-08-20 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

In D104854#2957471 , @sepavloff wrote:

> In D104854#2957423 , @spatel wrote:
>
>> Is it intentional that we are not canonicalizing the intrinsic call back to 
>> `fcmp uno` in the default FP environment?
>
> It is lowered to unordered comparison by default. Changing `llvm.isnan` to  
> `fcmp uno` somewhere in IR would make it possible to optimize out the latter 
> if fast-math mode is on. Preserving semantics of `isnan` when fast-math is in 
> effect was one of the goals of this change.

I understand that the codegen was supposed to be no worse, but the difference 
in IR causes optimizer regressions like: 
https://llvm.org/PR51556

If we want this intrinsic (and its siblings that haven't been created yet) to 
survive through IR, then we have to enhance IR passes to recognize the new 
patterns. 
It would be easier to do this in steps: (1) create the intrinsic only if not in 
the default FP env, (2) update IR analysis/passes to recognize the intrinsic, 
(3) create the intrinsic in the default FP env with no FMF, (4) create the 
intrinsic always.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[PATCH] D108422: [NFC][clang] Move remaining part of X86Target.def to llvm/Support/X86TargetParser.def

2021-08-20 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

There's nothing later than CannonLake here - does Intel need to at least 
reference up to Tiger/Rocketlake?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108422

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


[PATCH] D108403: Fix assertion when generating diagnostic for inline namespaces

2021-08-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/DeclBase.cpp:1222
+  DeclContext *DC = this;
+  while (DC && DC->isTransparentContext())
+DC = DC->getParent();

erichkeane wrote:
> cor3ntin wrote:
> > Can getParent() be null? If it cam, then this function can return null 
> > which you don't check when you call that function. Or it can't and your 
> > test is not doing anything.
> I don't think it can ever be null, a DC of transparent-context type is always 
> going to have at least a TranslationUnit as a parent.
> 
> I might think an assertion here to replace the `DC &&` part might be worth it.
Thanks for the suggestions! I switched to an assert in 
65bcdeaa15b729dae40190c6a990cd67c12e9f10.


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

https://reviews.llvm.org/D108403

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


[clang] 65bcdea - Replace an unnecessary null check with an assert; NFC

2021-08-20 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-08-20T12:04:46-04:00
New Revision: 65bcdeaa15b729dae40190c6a990cd67c12e9f10

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

LOG: Replace an unnecessary null check with an assert; NFC

Added: 


Modified: 
clang/lib/AST/DeclBase.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 53dd2ae3cbd3..e042ae8dae4a 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1219,8 +1219,10 @@ bool DeclContext::Encloses(const DeclContext *DC) const {
 
 DeclContext *DeclContext::getNonTransparentContext() {
   DeclContext *DC = this;
-  while (DC && DC->isTransparentContext())
+  while (DC->isTransparentContext()) {
 DC = DC->getParent();
+assert(DC && "All transparent contexts should have a parent!");
+  }
   return DC;
 }
 



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


[PATCH] D108422: [NFC][clang] Move remaining part of X86Target.def to llvm/Support/X86TargetParser.def

2021-08-20 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I'm not opposed either.




Comment at: llvm/include/llvm/Support/X86TargetParser.def:220
+
+// FIXME: When commented out features are supported in LLVM, enable them here.
+CPU_SPECIFIC("generic", 'A', "")

erichkeane wrote:
> RKSimon wrote:
> > what commented out features?
> So this is copy/pasted from: 
> https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/X86Target.def#L70
>  (where it will probably be removed in a future patch?).
> 
> That comment came from here: https://reviews.llvm.org/D47474
> 
> If you look at the 'diff' here: 
> https://reviews.llvm.org/D47474?vs=148894&id=156484#toc (1st patch vs last)  
> You can see that the original used a bitmask to create the values rather than 
> the string list (as suggested by @craig.topper in the review).  That version 
> had some commented out in the bitmasks.
> 
> However, I never removed the comment!  So this comment likely should just be 
> deleted.
I'm not sure the commented out features made it over. For example, FEATURE_TSX 
was one of the commented out values, but +tsx doesn't appear in these strings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108422

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


[PATCH] D106616: [Clang][LLVM] generate btf_tag annotations for DIDerived types

2021-08-20 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@dblaikie could you take a look at this patch? The same as previous DIComposite 
patch (D106615 ), if the patch is accepted, I 
will break into llvm part and clang part and commit them separately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106616

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


[PATCH] D108412: [WebAssembly] Add SIMD intrinsics using unsigned integers

2021-08-20 Thread Thomas Lively 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 rG2456e11614c1: [WebAssembly] Add SIMD intrinsics using 
unsigned integers (authored by tlively).

Changed prior to commit:
  https://reviews.llvm.org/D108412?vs=367622&id=367798#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108412

Files:
  clang/lib/Headers/wasm_simd128.h
  clang/test/Headers/wasm.c

Index: clang/test/Headers/wasm.c
===
--- clang/test/Headers/wasm.c
+++ clang/test/Headers/wasm.c
@@ -3,7 +3,7 @@
 
 // FIXME: This should not be using -O2 and implicitly testing the entire IR opt pipeline.
 
-// RUN: %clang %s -O2 -emit-llvm -S -o - -target wasm32-unknown-unknown -msimd128 -Wcast-qual -fno-lax-vector-conversions -Werror | FileCheck %s
+// RUN: %clang %s -O2 -emit-llvm -S -o - -target wasm32-unknown-unknown -msimd128 -Wall -Weverything -Wno-missing-prototypes -fno-lax-vector-conversions -Werror | FileCheck %s
 
 #include 
 
@@ -213,7 +213,7 @@
 // CHECK-NEXT:ret void
 //
 void test_v128_store(void *mem, v128_t a) {
-  return wasm_v128_store(mem, a);
+  wasm_v128_store(mem, a);
 }
 
 // CHECK-LABEL: @test_v128_store8_lane(
@@ -224,7 +224,7 @@
 // CHECK-NEXT:ret void
 //
 void test_v128_store8_lane(uint8_t *ptr, v128_t vec) {
-  return wasm_v128_store8_lane(ptr, vec, 15);
+  wasm_v128_store8_lane(ptr, vec, 15);
 }
 
 // CHECK-LABEL: @test_v128_store16_lane(
@@ -235,7 +235,7 @@
 // CHECK-NEXT:ret void
 //
 void test_v128_store16_lane(uint16_t *ptr, v128_t vec) {
-  return wasm_v128_store16_lane(ptr, vec, 7);
+  wasm_v128_store16_lane(ptr, vec, 7);
 }
 
 // CHECK-LABEL: @test_v128_store32_lane(
@@ -245,7 +245,7 @@
 // CHECK-NEXT:ret void
 //
 void test_v128_store32_lane(uint32_t *ptr, v128_t vec) {
-  return wasm_v128_store32_lane(ptr, vec, 3);
+  wasm_v128_store32_lane(ptr, vec, 3);
 }
 
 // CHECK-LABEL: @test_v128_store64_lane(
@@ -256,7 +256,7 @@
 // CHECK-NEXT:ret void
 //
 void test_v128_store64_lane(uint64_t *ptr, v128_t vec) {
-  return wasm_v128_store64_lane(ptr, vec, 1);
+  wasm_v128_store64_lane(ptr, vec, 1);
 }
 
 // CHECK-LABEL: @test_i8x16_make(
@@ -284,6 +284,31 @@
   return wasm_i8x16_make(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15);
 }
 
+// CHECK-LABEL: @test_u8x16_make(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <16 x i8> undef, i8 [[C0:%.*]], i32 0
+// CHECK-NEXT:[[VECINIT1_I:%.*]] = insertelement <16 x i8> [[VECINIT_I]], i8 [[C1:%.*]], i32 1
+// CHECK-NEXT:[[VECINIT2_I:%.*]] = insertelement <16 x i8> [[VECINIT1_I]], i8 [[C2:%.*]], i32 2
+// CHECK-NEXT:[[VECINIT3_I:%.*]] = insertelement <16 x i8> [[VECINIT2_I]], i8 [[C3:%.*]], i32 3
+// CHECK-NEXT:[[VECINIT4_I:%.*]] = insertelement <16 x i8> [[VECINIT3_I]], i8 [[C4:%.*]], i32 4
+// CHECK-NEXT:[[VECINIT5_I:%.*]] = insertelement <16 x i8> [[VECINIT4_I]], i8 [[C5:%.*]], i32 5
+// CHECK-NEXT:[[VECINIT6_I:%.*]] = insertelement <16 x i8> [[VECINIT5_I]], i8 [[C6:%.*]], i32 6
+// CHECK-NEXT:[[VECINIT7_I:%.*]] = insertelement <16 x i8> [[VECINIT6_I]], i8 [[C7:%.*]], i32 7
+// CHECK-NEXT:[[VECINIT8_I:%.*]] = insertelement <16 x i8> [[VECINIT7_I]], i8 [[C8:%.*]], i32 8
+// CHECK-NEXT:[[VECINIT9_I:%.*]] = insertelement <16 x i8> [[VECINIT8_I]], i8 [[C9:%.*]], i32 9
+// CHECK-NEXT:[[VECINIT10_I:%.*]] = insertelement <16 x i8> [[VECINIT9_I]], i8 [[C10:%.*]], i32 10
+// CHECK-NEXT:[[VECINIT11_I:%.*]] = insertelement <16 x i8> [[VECINIT10_I]], i8 [[C11:%.*]], i32 11
+// CHECK-NEXT:[[VECINIT12_I:%.*]] = insertelement <16 x i8> [[VECINIT11_I]], i8 [[C12:%.*]], i32 12
+// CHECK-NEXT:[[VECINIT13_I:%.*]] = insertelement <16 x i8> [[VECINIT12_I]], i8 [[C13:%.*]], i32 13
+// CHECK-NEXT:[[VECINIT14_I:%.*]] = insertelement <16 x i8> [[VECINIT13_I]], i8 [[C14:%.*]], i32 14
+// CHECK-NEXT:[[VECINIT15_I:%.*]] = insertelement <16 x i8> [[VECINIT14_I]], i8 [[C15:%.*]], i32 15
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[VECINIT15_I]] to <4 x i32>
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+v128_t test_u8x16_make(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5, uint8_t c6, uint8_t c7, uint8_t c8, uint8_t c9, uint8_t c10, uint8_t c11, uint8_t c12, uint8_t c13, uint8_t c14, uint8_t c15) {
+  return wasm_u8x16_make(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15);
+}
+
 // CHECK-LABEL: @test_i16x8_make(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <8 x i16> undef, i16 [[C0:%.*]], i32 0
@@ -301,6 +326,23 @@
   return wasm_i16x8_make(c0, c1, c2, c3, c4, c5, c6, c7);
 }
 
+// CHECK-LABEL: @test_u16x8_make(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <8 x i16> undef, i16 [[C0:%.*]], i32 0
+// CHECK-NEXT:[[VEC

[clang] 2456e11 - [WebAssembly] Add SIMD intrinsics using unsigned integers

2021-08-20 Thread Thomas Lively via cfe-commits

Author: Thomas Lively
Date: 2021-08-20T08:56:51-07:00
New Revision: 2456e11614c10a2e648005e27e3213c77b7ab7a4

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

LOG: [WebAssembly] Add SIMD intrinsics using unsigned integers

For each SIMD intrinsic function that takes or returns a scalar signed integer
value, ensure there is a corresponding intrinsic that returns or an
unsigned value. This is a convenience for users who use -Wsign-conversion so
they don't have to insert explicit casts, especially when the intrinsic
arguments are integer literals that fit into the unsigned integer type but not
the signed type.

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

Added: 


Modified: 
clang/lib/Headers/wasm_simd128.h
clang/test/Headers/wasm.c

Removed: 




diff  --git a/clang/lib/Headers/wasm_simd128.h 
b/clang/lib/Headers/wasm_simd128.h
index e43c31a36e77..498898acaf8a 100644
--- a/clang/lib/Headers/wasm_simd128.h
+++ b/clang/lib/Headers/wasm_simd128.h
@@ -276,12 +276,28 @@ wasm_i8x16_make(int8_t __c0, int8_t __c1, int8_t __c2, 
int8_t __c3, int8_t __c4,
__c12, __c13, __c14, __c15};
 }
 
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_u8x16_make(uint8_t __c0, uint8_t __c1, uint8_t __c2, uint8_t __c3,
+uint8_t __c4, uint8_t __c5, uint8_t __c6, uint8_t __c7,
+uint8_t __c8, uint8_t __c9, uint8_t __c10, uint8_t __c11,
+uint8_t __c12, uint8_t __c13, uint8_t __c14, uint8_t __c15) {
+  return (v128_t)(__u8x16){__c0,  __c1,  __c2,  __c3, __c4,  __c5,
+   __c6,  __c7,  __c8,  __c9, __c10, __c11,
+   __c12, __c13, __c14, __c15};
+}
+
 static __inline__ v128_t __DEFAULT_FN_ATTRS
 wasm_i16x8_make(int16_t __c0, int16_t __c1, int16_t __c2, int16_t __c3,
 int16_t __c4, int16_t __c5, int16_t __c6, int16_t __c7) {
   return (v128_t)(__i16x8){__c0, __c1, __c2, __c3, __c4, __c5, __c6, __c7};
 }
 
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_u16x8_make(uint16_t __c0, uint16_t __c1, uint16_t __c2, uint16_t __c3,
+uint16_t __c4, uint16_t __c5, uint16_t __c6, uint16_t __c7) {
+  return (v128_t)(__u16x8){__c0, __c1, __c2, __c3, __c4, __c5, __c6, __c7};
+}
+
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i32x4_make(int32_t __c0,
 int32_t __c1,
 int32_t __c2,
@@ -289,11 +305,23 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS 
wasm_i32x4_make(int32_t __c0,
   return (v128_t)(__i32x4){__c0, __c1, __c2, __c3};
 }
 
+static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u32x4_make(uint32_t __c0,
+uint32_t __c1,
+uint32_t __c2,
+uint32_t __c3) {
+  return (v128_t)(__u32x4){__c0, __c1, __c2, __c3};
+}
+
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i64x2_make(int64_t __c0,
 int64_t __c1) {
   return (v128_t)(__i64x2){__c0, __c1};
 }
 
+static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u64x2_make(uint64_t __c0,
+uint64_t __c1) {
+  return (v128_t)(__u64x2){__c0, __c1};
+}
+
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_f32x4_make(float __c0,
 float __c1,
 float __c2,
@@ -324,6 +352,24 @@ wasm_i8x16_const(int8_t __c0, int8_t __c1, int8_t __c2, 
int8_t __c3,
__c12, __c13, __c14, __c15};
 }
 
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_u8x16_const(uint8_t __c0, uint8_t __c1, uint8_t __c2, uint8_t __c3,
+ uint8_t __c4, uint8_t __c5, uint8_t __c6, uint8_t __c7,
+ uint8_t __c8, uint8_t __c9, uint8_t __c10, uint8_t __c11,
+ uint8_t __c12, uint8_t __c13, uint8_t __c14, uint8_t __c15)
+__REQUIRE_CONSTANT(__c0) __REQUIRE_CONSTANT(__c1) __REQUIRE_CONSTANT(__c2)
+__REQUIRE_CONSTANT(__c3) __REQUIRE_CONSTANT(__c4)
+__REQUIRE_CONSTANT(__c5) __REQUIRE_CONSTANT(__c6)
+__REQUIRE_CONSTANT(__c7) __REQUIRE_CONSTANT(__c8)
+__REQUIRE_CONSTANT(__c9) __REQUIRE_CONSTANT(__c10)
+__REQUIRE_CONSTANT(__c11) __REQUIRE_CONSTANT(__c12)
+__REQUIRE_CONSTANT(__c13) __REQUIRE_CONSTANT(__c14)
+__REQUIRE_CONSTANT(__c15) {
+  return (v128_t)(__u8x16){__c0,  __c1,  __c2,  __c3, __c4,  __c5,
+   __c6,  _

[PATCH] D106616: [Clang][LLVM] generate btf_tag annotations for DIDerived types

2021-08-20 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 367797.
yonghong-song added a comment.

- fix clang-format warnings


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106616

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/attr-btf_tag-field.c
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/test/Bitcode/attr-btf_tag-field.ll

Index: llvm/test/Bitcode/attr-btf_tag-field.ll
===
--- /dev/null
+++ llvm/test/Bitcode/attr-btf_tag-field.ll
@@ -0,0 +1,91 @@
+; REQUIRES: x86-registered-target
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+%struct.t1 = type { i32 }
+%struct.t2 = type { i8, [3 x i8] }
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local i32 @foo(%struct.t1* %arg) #0 !dbg !9 {
+entry:
+  %arg.addr = alloca %struct.t1*, align 8
+  store %struct.t1* %arg, %struct.t1** %arg.addr, align 8
+  call void @llvm.dbg.declare(metadata %struct.t1** %arg.addr, metadata !20, metadata !DIExpression()), !dbg !21
+  %0 = load %struct.t1*, %struct.t1** %arg.addr, align 8, !dbg !22
+  %a = getelementptr inbounds %struct.t1, %struct.t1* %0, i32 0, i32 0, !dbg !23
+  %1 = load i32, i32* %a, align 4, !dbg !23
+  ret i32 %1, !dbg !24
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local i32 @foo2(%struct.t2* %arg) #0 !dbg !25 {
+entry:
+  %arg.addr = alloca %struct.t2*, align 8
+  store %struct.t2* %arg, %struct.t2** %arg.addr, align 8
+  call void @llvm.dbg.declare(metadata %struct.t2** %arg.addr, metadata !32, metadata !DIExpression()), !dbg !33
+  %0 = load %struct.t2*, %struct.t2** %arg.addr, align 8, !dbg !34
+  %1 = bitcast %struct.t2* %0 to i8*, !dbg !35
+  %bf.load = load i8, i8* %1, align 4, !dbg !35
+  %bf.shl = shl i8 %bf.load, 7, !dbg !35
+  %bf.ashr = ashr i8 %bf.shl, 7, !dbg !35
+  %bf.cast = sext i8 %bf.ashr to i32, !dbg !35
+  ret i32 %bf.cast, !dbg !36
+}
+
+attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
+attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5, !6, !7}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git 4cbaee98885ead226304e8836090069db6596965)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "attr-btf_tag-field.c", directory: "/home/yhs/work/tests/llvm/btf_tag")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{i32 7, !"uwtable", i32 1}
+!7 = !{i32 7, !"frame-pointer", i32 2}
+!8 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 4cbaee98885ead226304e8836090069db6596965)"}
+!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 11, type: !10, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!10 = !DISubroutineType(types: !11)
+!11 = !{!12, !13}
+!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64)
+!14 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", file: !1, line: 7, size: 32, elements: !15)
+!15 = !{!16}
+!16 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !14, file: !1, line: 8, baseType: !12, size: 32, annotations: !17)
+!17 = !{!18, !19}
+!18 = !{!"btf_tag", !"tag1"}
+!19 = !{!"btf_tag", !"tag2"}
+
+; CHECK:!DIDerivedType(tag: DW_TAG_member, name: "a"
+; CHECK-SAME:   annotations: ![[ANNOT:[0-9]+]]
+; CHECK:![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
+; CHECK:![[TAG1]] = !{!"btf_tag", !"tag1"}
+; CHECK:![[TAG2]] = !{!"btf_tag", !"tag2"}
+
+!20 = !DILocalVariable(name: "arg", arg: 1, scope: !9, file: !1, line: 11, type: !13)
+!21 = !DILocation(line: 11, column: 20, scope: !9)
+!22 = !DILocation(line: 12, column: 10, scope: !9)
+!23 = !DILocation(line: 12, column: 15, scope: !9)
+!24 = !DILocation(line: 12, column: 3, scope: !9)
+!25 = distinct !DISubprogram(name: "foo2", scope: !1, file: !1, line: 19, type: !26, scopeLine: 19,

[PATCH] D108403: Fix assertion when generating diagnostic for inline namespaces

2021-08-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/DeclBase.cpp:1222
+  DeclContext *DC = this;
+  while (DC && DC->isTransparentContext())
+DC = DC->getParent();

cor3ntin wrote:
> Can getParent() be null? If it cam, then this function can return null which 
> you don't check when you call that function. Or it can't and your test is not 
> doing anything.
I don't think it can ever be null, a DC of transparent-context type is always 
going to have at least a TranslationUnit as a parent.

I might think an assertion here to replace the `DC &&` part might be worth it.


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

https://reviews.llvm.org/D108403

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


  1   2   >