[PATCH] D110216: [clang] retain type sugar in auto / template argument deduction

2021-10-30 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:3285
   }
-  if (const TypedefType *TypedefT =
-  dyn_cast(FromFPT->getReturnType())) {
-TypedefNameDecl *TD = TypedefT->getDecl();
+  if (const auto *TypedefT = dyn_cast(FromFPT->getReturnType())) {
+const TypedefNameDecl *TD = TypedefT->getDecl();

rsmith wrote:
> (Preparing for D112374)
Good catch, thanks :)



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1385-1388
+P = P.getUnqualifiedType();
 // - If A is a cv-qualified type, A is replaced by the cv-unqualified
 //   version of A.
+A = A.getUnqualifiedType();

rsmith wrote:
> Do we need to use `Context.getUnqualifiedArrayType` here, for cases like:
> ```
> typedef const int CInt;
> // Partial ordering should deduce `T = int` from both parameters here,
> // even though `T = const int` might make more sense for the first one.
> template void f(CInt (&)[N], int*);
> template void f(T (&)[N], T*);
> CInt arr[5];
> void g() { f(arr, arr); }
> ```
> ? I think `getUnqualifiedType()` on `CInt[N]` will not remove the indirect 
> `const` qualifier.
I see, that is true, if P and A could be sugared here, we would need 
`getUnqualifiedArrayType`.

But this issue had been sidestepped because we were not handling sugar in the 
PartialOrdering case, because that was only used in the isAtLeastAsSpecialized 
path where we were still using the canonical type, as we don't care about what 
types where actually deduced there.

I just changed it to not use the canonical type anymore and took this change.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:1546-1568
+  QualType CanP = P.getCanonicalType();
+  // If the parameter type is not dependent, there is nothing to deduce.
+  if (!P->isDependentType()) {
+if (TDF & TDF_SkipNonDependent)
   return Sema::TDK_Success;
+
+QualType CanA = A.getCanonicalType();

rsmith wrote:
> I think we can excise `CanA` and `CanP` entirely here so people aren't 
> tempted to use them and lose sugar.
Nice suggestion!

Though we must keep the last return as conditional, as I did there, otherwise we
break a test case such as the one from PR12132:
```
template void fun(const int* const S::* member) {}
struct A { int* x; };
void foo() {
fun(::x);
}
```
When ignoring qualifiers, hasSameUnqualifiedType being false is not enough to 
deduce a mismatch, so this is the one corner case where we analyze with a 
non-dependent parameter type.

That is what I tried to explain in that comment, but I have just reworded it to 
be clearer on this point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110216

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


[PATCH] D112883: [bazel] Re-introduce `copts` hacks for lib/AST includes.

2021-10-30 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc created this revision.
chandlerc added reviewers: GMNGeoffrey, dblaikie.
Herald added a subscriber: mcrosier.
chandlerc requested review of this revision.

Sadly, these are necessary AFAICT. There is a file `lib/AST/CXXABI.h`.
On case insensitive file systems like macOS this will collide with
`cxxabi.h` on the system if we use the `includes` trick to allow
file-relative `#include` of generated files.

I've tested this on both Linux and Windows to make sure it remains
reasonably portable.


https://reviews.llvm.org/D112883

Files:
  utils/bazel/llvm-project-overlay/clang/BUILD.bazel


Index: utils/bazel/llvm-project-overlay/clang/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -691,14 +691,25 @@
 "lib/AST/*.h",
 "lib/AST/Interp/*.cpp",
 "lib/AST/Interp/*.h",
-]),
+]) + [
+"lib/AST/AttrDocTable.inc",
+"lib/AST/Interp/Opcodes.inc",
+],
 hdrs = glob([
 "include/clang/AST/*.h",
 ]),
-includes = [
-"include",
-"lib/AST",
-"lib/AST/Interp",
+copts = [
+# FIXME: This is necessary to allow "file relative" include paths from
+# non-generated `srcs` to find generated `srcs` above. Bazel should
+# either make this work automatically by creating a unified tree of
+# `srcs` or at least provide a `local_includes` that has the path
+# translation logic of `includes` but is only used locally (similar to
+# `local_defines` vs. `defines`). Until one of those lands, this is the
+# least bad approach. Using `includes` is *specifically* problematic 
for
+# this library because it contains files that collide easily with 
system
+# headers such as `CXXABI.h`.
+"-I$(GENDIR)/external/llvm-project/clang/lib/AST",
+"-I$(GENDIR)/external/llvm-project/clang/lib/AST/Interp",
 ],
 textual_hdrs = [
 "include/clang/AST/AttrImpl.inc",
@@ -715,8 +726,6 @@
 "include/clang/AST/DeclNodes.inc",
 "include/clang/AST/StmtDataCollectors.inc",
 "include/clang/AST/StmtNodes.inc",
-"lib/AST/AttrDocTable.inc",
-"lib/AST/Interp/Opcodes.inc",
 ] + glob([
 "include/clang/AST/*.def",
 ]),


Index: utils/bazel/llvm-project-overlay/clang/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -691,14 +691,25 @@
 "lib/AST/*.h",
 "lib/AST/Interp/*.cpp",
 "lib/AST/Interp/*.h",
-]),
+]) + [
+"lib/AST/AttrDocTable.inc",
+"lib/AST/Interp/Opcodes.inc",
+],
 hdrs = glob([
 "include/clang/AST/*.h",
 ]),
-includes = [
-"include",
-"lib/AST",
-"lib/AST/Interp",
+copts = [
+# FIXME: This is necessary to allow "file relative" include paths from
+# non-generated `srcs` to find generated `srcs` above. Bazel should
+# either make this work automatically by creating a unified tree of
+# `srcs` or at least provide a `local_includes` that has the path
+# translation logic of `includes` but is only used locally (similar to
+# `local_defines` vs. `defines`). Until one of those lands, this is the
+# least bad approach. Using `includes` is *specifically* problematic for
+# this library because it contains files that collide easily with system
+# headers such as `CXXABI.h`.
+"-I$(GENDIR)/external/llvm-project/clang/lib/AST",
+"-I$(GENDIR)/external/llvm-project/clang/lib/AST/Interp",
 ],
 textual_hdrs = [
 "include/clang/AST/AttrImpl.inc",
@@ -715,8 +726,6 @@
 "include/clang/AST/DeclNodes.inc",
 "include/clang/AST/StmtDataCollectors.inc",
 "include/clang/AST/StmtNodes.inc",
-"lib/AST/AttrDocTable.inc",
-"lib/AST/Interp/Opcodes.inc",
 ] + glob([
 "include/clang/AST/*.def",
 ]),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112399: Get Bazel building `//clang` on Windows with clang-cl.

2021-10-30 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc requested review of this revision.
chandlerc added a comment.

PTAL, and thanks for feedback so far!




Comment at: clang/include/clang/Basic/Builtins.def:1059
+#undef strcasecmp
+#undef strncasecmp
+

rnk wrote:
> thakis wrote:
> > GMNGeoffrey wrote:
> > > chandlerc wrote:
> > > > thakis wrote:
> > > > > Why do we need this with bazel but not with other windows builds?
> > > > I don't know how this never was hit by other builders. I don't usually 
> > > > develop on Windows so I have very little experience with different 
> > > > builds there.
> > > > 
> > > > My guess is that it is the particular way that Bazel+clang-cl compile 
> > > > on Windows causes sligthtly more to be transitively included with 
> > > > `#include ` and that grows the number of functions hit with 
> > > > this. I thought about trying to "fix" that, but the existing `#undef` 
> > > > lines made me think it wouldn't be completely successful.
> > > > 
> > > > Are you worried about the change? Looking for a different fix?
> > > Yeah I want to note that my review is basically only for the Bazel stuff. 
> > > This looked fine to me based on the existing `undef`s, but mostly 
> > > trusting Chandler to determine that this is OK and isn't in the territory 
> > > of the Bazel build requiring unsavory things in the core project.
> > Worried is a strong word :) It just feels off. The redundant build system 
> > config changes shouldn't need changes to LLVM's code itself imho. If 
> > there's some difference in build behavior here, it feels like we should fix 
> > that on the build config side of things, else we'll have weird one-off 
> > fixes like this in other places potentially. I feel we should at least 
> > understand what's going on.
> > 
> > (This isn't a terribly strong opinion fwiw.)
> Does Bazel build clang with modules? That could lead to windows.h 
> proliferation.
> 
> If you are motivated to investigate, you can re-run the failing compile 
> command with /showIncludes to work out where the windows.h include comes in. 
> Take the corresponding object file, build it with cmake ninja, extract the 
> compile command there, run it with showincludes, and compare the output.
I figured this all out. It was right in front of me. New patch fixes.



Comment at: utils/bazel/.bazelrc:113-116
 # Use Clang's internal warning flags instead of the ones that sometimes map
 # through to MSVC's flags.
 build:clang-cl --copt=/clang:-Wall --host_copt=/clang:-Wall
 build:clang-cl --copt=/clang:-Werror --host_copt=/clang:-Werror

rnk wrote:
> It is true that MSVC's -Wall is Clang's -Weverything, so this needs a prefix. 
> -Werror could be -WX, but it's just cosmetic.
Yeah, I just figured it was more readable in this section to consistently use 
`/clang:-W`.



Comment at: utils/bazel/.bazelrc:125
+# Disable some warnings hit even with `clang-cl` in Clang's own code.
+build:clang-cl --copt=/clang:-Wno-inconsistent-dllimport 
--host_copt=/clang:-Wno-inconsistent-dllimport
+build:clang-cl --cxxopt=/clang:-Wno-c++11-narrowing 
--host_cxxopt=/clang:-Wno-c++11-narrowing

rnk wrote:
> You shouldn't need to prefix warning flags with `/clang:`, those are 
> supported out of the box.
Again, this just seemed more consistent. I can change if you think the other is 
better though.



Comment at: 
utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h:81
 /* The LLVM product name and version */
 #define BACKEND_PACKAGE_STRING "LLVM 12.0.0git"
 

GMNGeoffrey wrote:
> rnk wrote:
> > Unrelated to your change, but is this stale?
> Yes and we don't currently have a good way to keep it up to date. The overall 
> problem of how to make sure we keep up to date with CMake configure knobs is 
> unsolved. I wonder if we could run CMake in some limited capacity, but that's 
> a whole can of worms...
I'll just commit an update to this separately. I assume that doesn't need 
separate review? ;]


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

https://reviews.llvm.org/D112399

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


[PATCH] D112399: Get Bazel building `//clang` on Windows with clang-cl.

2021-10-30 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc updated this revision to Diff 383634.
chandlerc marked 5 inline comments as done.
chandlerc edited the summary of this revision.
chandlerc added a reviewer: rnk.
chandlerc added a comment.

Major update to better fix some of the issues here. No longer requires any 
changes outside of Bazel.


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

https://reviews.llvm.org/D112399

Files:
  utils/bazel/.bazelrc
  utils/bazel/llvm-project-overlay/clang/BUILD.bazel
  utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h
  utils/bazel/llvm-project-overlay/clang/unittests/BUILD.bazel
  utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl
  utils/bazel/llvm-project-overlay/llvm/config.bzl
  utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h

Index: utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
===
--- utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
+++ utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
@@ -352,10 +352,10 @@
 #define HAVE_STD_IS_TRIVIALLY_COPYABLE 1
 
 /* Define to a function implementing stricmp */
-/* stricmp defined in Bazel */
+/* stricmp defined conditionally below. */
 
 /* Define to a function implementing strdup */
-/* strdup defined in Bazel */
+/* strdup defined conditionally below. */
 
 /* Whether GlobalISel rule coverage is being collected */
 #define LLVM_GISEL_COV_ENABLED 0
@@ -368,4 +368,17 @@
 
 /* HAVE_PROC_PID_RUSAGE defined in Bazel */
 
+/* Directly provide definitions here behind platform preprocessor definitions.
+ * The preprocessor conditions are sufficient to handle all of the configuration
+ * on platforms targeted by Bazel, and defining these here more faithfully
+ * matches how the users of this header expect things to work with CMake.
+ * FIXME: We should consider moving other platform defines to use this technique
+ * as well.
+ */
+
+#ifdef _WIN32
+#define stricmp _stricmp
+#define strdup _strdup
+#endif
+
 #endif
Index: utils/bazel/llvm-project-overlay/llvm/config.bzl
===
--- utils/bazel/llvm-project-overlay/llvm/config.bzl
+++ utils/bazel/llvm-project-overlay/llvm/config.bzl
@@ -57,9 +57,15 @@
 ]
 
 win32_defines = [
-# MSVC specific
-"stricmp=_stricmp",
-"strdup=_strdup",
+# Windows system library specific defines.
+"_CRT_SECURE_NO_DEPRECATE",
+"_CRT_SECURE_NO_WARNINGS",
+"_CRT_NONSTDC_NO_DEPRECATE",
+"_CRT_NONSTDC_NO_WARNINGS",
+"_SCL_SECURE_NO_DEPRECATE",
+"_SCL_SECURE_NO_WARNINGS",
+"UNICODE",
+"_UNICODE",
 
 # LLVM features
 r'LTDL_SHLIB_EXT=\".dll\"',
Index: utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl
===
--- utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl
+++ utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl
@@ -4,51 +4,72 @@
 
 """A macro to produce a loadable plugin library for the target OS.
 
-This macro produces a `cc_binary` rule with the name `name + "_impl"`. It
-forces the rule to statically link in its dependencies but to be linked as a
-shared "plugin" library. It then creates binary aliases to `.so`, `.dylib`
-,and `.dll` suffixed names for use on various platforms and selects between
-these into a filegroup with the exact name passed to the macro.
+This macro produces a set of platform-specific `cc_binary` rules, by appending
+the platform suffix (`.dll`, `.dylib`, or `.so`) to the provided `name`. It then
+connects these to a `cc_import` rule with `name` exactly and `hdrs` that can be
+used by other Bazel rules to depend on the plugin library.
+
+The `srcs` attribute for the `cc_binary` rules is `srcs + hdrs`. Other explicit
+arguments are passed to all of the rules where they apply, and can be used to
+configure generic aspects of all generated rules such as `testonly`. Lastly,
+`kwargs` is expanded into all the `cc_binary` rules.
 """
 
-load("@rules_cc//cc:defs.bzl", "cc_binary")
-load(":binary_alias.bzl", "binary_alias")
+load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_import", "cc_library")
 
-def cc_plugin_library(name, **kwargs):
+def cc_plugin_library(name, srcs, hdrs, include_prefix = None, strip_include_prefix = None, alwayslink = False, features = [], tags = [], testonly = False, **kwargs):
 # Neither the name of the plugin binary nor tags on whether it is built are
-# configurable. Instead, we build a `cc_binary` that implements the plugin
-# library using a `_impl` suffix. Bazel will use appropriate flags to cause
-# this file to be a plugin library regardless of its name. We then create
-# binary aliases in the different possible platform names, and select
-# between these different names into a filegroup. The macro's name becomes
-# the filegroup name and it contains exactly one target that is the target
- 

[PATCH] D112864: [clang-tidy] Fix lint warnings in clang-tidy source code (NFC)

2021-10-30 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz added a comment.

In D112864#3098351 , @carlosgalvezp 
wrote:

> Looks great, thanks for fixing! I'm surprised we don't have a CI bot running 
> these checks post-merge?

You would think so, but it looks like automatic checking during CI was disabled 
in this commit:
https://github.com/google/llvm-premerge-checks/commit/b69eb6f3647ecb67ff85e551323b3445acde684b

Anyway, even if you run clang-tidy manually, you could miss many issues. A 
number of warnings are in the header files, and they only get revealed if you 
set `--header-filter` properly to look at them.

I will leave this review open for a few days in case other people have comments 
to add. This patch isn't urgent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112864

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


[PATCH] D112881: [clang-tidy] Allow disabling integer to floating-point narrowing conversions for cppcoreguidelines-narrowing-conversions

2021-10-30 Thread Paul Altin via Phabricator via cfe-commits
paulaltin updated this revision to Diff 383631.

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

https://reviews.llvm.org/D112881

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-narrowingintegertofloatingpoint-option.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-narrowingintegertofloatingpoint-option.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-narrowingintegertofloatingpoint-option.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy -check-suffix=DEFAULT %s \
+// RUN: cppcoreguidelines-narrowing-conversions %t -- \
+// RUN: -config='{CheckOptions: [{key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion, value: true}]}'
+
+// RUN: %check_clang_tidy -check-suffix=DISABLED %s \
+// RUN: cppcoreguidelines-narrowing-conversions %t -- \
+// RUN: -config='{CheckOptions: [{key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion, value: false}]}'
+
+void foo(size_t value) {
+  double a = value;
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:14: warning: narrowing conversion from 'size_t' (aka 'unsigned long') to 'double' [cppcoreguidelines-narrowing-conversions]
+  // DISABLED: No warning for integer to floating-point narrowing conversions when WarnOnIntegerToFloatingPointNarrowingConversion = false.
+}
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.rst
@@ -15,7 +15,8 @@
 We enforce only part of the guideline, more specifically, we flag narrowing conversions from:
  - an integer to a narrower integer (e.g. ``char`` to ``unsigned char``)
if WarnOnIntegerNarrowingConversion Option is set,
- - an integer to a narrower floating-point (e.g. ``uint64_t`` to ``float``),
+ - an integer to a narrower floating-point (e.g. ``uint64_t`` to ``float``)
+   if WarnOnIntegerToFloatingPointNarrowingConversion Option is set,
  - a floating-point to an integer (e.g. ``double`` to ``int``),
  - a floating-point to a narrower floating-point (e.g. ``double`` to ``float``)
if WarnOnFloatingPointNarrowingConversion Option is set.
@@ -36,6 +37,11 @@
 When `true`, the check will warn on narrowing integer conversion
 (e.g. ``int`` to ``size_t``). `true` by default.
 
+.. option:: WarnOnIntegerToFloatingPointNarrowingConversion
+
+When `true`, the check will warn on narrowing integer to floating-point
+conversion (e.g. ``size_t`` to ``double``). `true` by default.
+
 .. option:: WarnOnFloatingPointNarrowingConversion
 
 When `true`, the check will warn on narrowing floating point conversion
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -37,6 +37,8 @@
 : ClangTidyCheck(Name, Context),
   WarnOnIntegerNarrowingConversion(
   Options.get("WarnOnIntegerNarrowingConversion", true)),
+  WarnOnIntegerToFloatingPointNarrowingConversion(
+  Options.get("WarnOnIntegerToFloatingPointNarrowingConversion", true)),
   WarnOnFloatingPointNarrowingConversion(
   Options.get("WarnOnFloatingPointNarrowingConversion", true)),
   WarnWithinTemplateInstantiation(
@@ -49,6 +51,8 @@
 ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "WarnOnIntegerNarrowingConversion",
 WarnOnIntegerNarrowingConversion);
+  Options.store(Opts, "WarnOnIntegerToFloatingPointNarrowingConversion",
+WarnOnIntegerToFloatingPointNarrowingConversion);
   Options.store(Opts, "WarnOnFloatingPointNarrowingConversion",
 WarnOnFloatingPointNarrowingConversion);
   Options.store(Opts, "WarnWithinTemplateInstantiation",
@@ -376,19 +380,21 @@
 void NarrowingConversionsCheck::handleIntegralToFloating(
 const ASTContext , SourceLocation SourceLoc, const Expr ,
 const Expr ) {
-  const BuiltinType *ToType = getBuiltinType(Lhs);
-  llvm::APSInt IntegerConstant;
-  if (getIntegerConstantExprValue(Context, Rhs, IntegerConstant)) {
-if (!isWideEnoughToHold(Context, IntegerConstant, *ToType))
-  diagNarrowIntegerConstant(SourceLoc, Lhs, Rhs, IntegerConstant);
-return;

[PATCH] D112881: Allow disabling integer to floating-point narrowing conversions for cppcoreguidelines-narrowing-conversions

2021-10-30 Thread Paul Altin via Phabricator via cfe-commits
paulaltin created this revision.
Herald added subscribers: carlosgalvezp, shchenz, kbarton, nemanjai.
paulaltin requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112881

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-narrowingintegertofloatingpoint-option.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-narrowingintegertofloatingpoint-option.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-narrowingintegertofloatingpoint-option.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy -check-suffix=DEFAULT %s \
+// RUN: cppcoreguidelines-narrowing-conversions %t -- \
+// RUN: -config='{CheckOptions: [{key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion, value: true}]}'
+
+// RUN: %check_clang_tidy -check-suffix=DISABLED %s \
+// RUN: cppcoreguidelines-narrowing-conversions %t -- \
+// RUN: -config='{CheckOptions: [{key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion, value: false}]}'
+
+void foo(size_t value) {
+  double a = value;
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:11: warning: narrowing conversion from 'size_t' (aka 'unsigned long') to 'double' [cppcoreguidelines-narrowing-conversions]
+  // DISABLED: No warning for integer to floating-point narrowing conversions when WarnOnIntegerToFloatingPointNarrowingConversion = false.
+}
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-narrowing-conversions.rst
@@ -15,7 +15,8 @@
 We enforce only part of the guideline, more specifically, we flag narrowing conversions from:
  - an integer to a narrower integer (e.g. ``char`` to ``unsigned char``)
if WarnOnIntegerNarrowingConversion Option is set,
- - an integer to a narrower floating-point (e.g. ``uint64_t`` to ``float``),
+ - an integer to a narrower floating-point (e.g. ``uint64_t`` to ``float``)
+   if WarnOnIntegerToFloatingPointNarrowingConversion Option is set,
  - a floating-point to an integer (e.g. ``double`` to ``int``),
  - a floating-point to a narrower floating-point (e.g. ``double`` to ``float``)
if WarnOnFloatingPointNarrowingConversion Option is set.
@@ -36,6 +37,11 @@
 When `true`, the check will warn on narrowing integer conversion
 (e.g. ``int`` to ``size_t``). `true` by default.
 
+.. option:: WarnOnIntegerToFloatingPointNarrowingConversion
+
+When `true`, the check will warn on narrowing integer to floating-point
+conversion (e.g. ``size_t`` to ``double``). `true` by default.
+
 .. option:: WarnOnFloatingPointNarrowingConversion
 
 When `true`, the check will warn on narrowing floating point conversion
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h
@@ -98,6 +98,7 @@
   const BuiltinType ) const;
 
   const bool WarnOnIntegerNarrowingConversion;
+  const bool WarnOnIntegerToFloatingPointNarrowingConversion;
   const bool WarnOnFloatingPointNarrowingConversion;
   const bool WarnWithinTemplateInstantiation;
   const bool WarnOnEquivalentBitWidth;
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -37,6 +37,8 @@
 : ClangTidyCheck(Name, Context),
   WarnOnIntegerNarrowingConversion(
   Options.get("WarnOnIntegerNarrowingConversion", true)),
+  WarnOnIntegerToFloatingPointNarrowingConversion(
+  Options.get("WarnOnIntegerToFloatingPointNarrowingConversion", true)),
   WarnOnFloatingPointNarrowingConversion(
   Options.get("WarnOnFloatingPointNarrowingConversion", true)),
   WarnWithinTemplateInstantiation(
@@ -49,6 +51,8 @@
 ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "WarnOnIntegerNarrowingConversion",
 

[clang] c8b1ed5 - [clang, llvm] Use Optional::getValueOr (NFC)

2021-10-30 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2021-10-30T19:00:21-07:00
New Revision: c8b1ed5fb2da8f030cb3c9d8a361ea7420e42da1

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

LOG: [clang, llvm] Use Optional::getValueOr (NFC)

Added: 


Modified: 
clang/include/clang/Analysis/PathDiagnostic.h
llvm/include/llvm/Analysis/ProfileSummaryInfo.h
llvm/lib/Analysis/ProfileSummaryInfo.cpp
llvm/lib/Transforms/IPO/PartialInlining.cpp
llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/PathDiagnostic.h 
b/clang/include/clang/Analysis/PathDiagnostic.h
index 14860c1168e21..235d26083191d 100644
--- a/clang/include/clang/Analysis/PathDiagnostic.h
+++ b/clang/include/clang/Analysis/PathDiagnostic.h
@@ -553,7 +553,7 @@ class PathDiagnosticEventPiece : public 
PathDiagnosticSpotPiece {
 
   /// Return true if the diagnostic piece is prunable.
   bool isPrunable() const {
-return IsPrunable.hasValue() ? IsPrunable.getValue() : false;
+return IsPrunable.getValueOr(false);
   }
 
   void dump() const override;

diff  --git a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h 
b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
index 8a5ab1ba6303d..886800d8a0f59 100644
--- a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
+++ b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
@@ -170,11 +170,11 @@ class ProfileSummaryInfo {
   uint64_t getOrCompColdCountThreshold() const;
   /// Returns HotCountThreshold if set.
   uint64_t getHotCountThreshold() const {
-return HotCountThreshold ? HotCountThreshold.getValue() : 0;
+return HotCountThreshold.getValueOr(0);
   }
   /// Returns ColdCountThreshold if set.
   uint64_t getColdCountThreshold() const {
-return ColdCountThreshold ? ColdCountThreshold.getValue() : 0;
+return ColdCountThreshold.getValueOr(0);
   }
 
  private:

diff  --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp 
b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
index 6dda0bf0a1b4a..69ca5502e5753 100644
--- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp
+++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
@@ -316,11 +316,11 @@ bool ProfileSummaryInfo::isColdCountNthPercentile(int 
PercentileCutoff,
 }
 
 uint64_t ProfileSummaryInfo::getOrCompHotCountThreshold() const {
-  return HotCountThreshold ? HotCountThreshold.getValue() : UINT64_MAX;
+  return HotCountThreshold.getValueOr(UINT64_MAX);
 }
 
 uint64_t ProfileSummaryInfo::getOrCompColdCountThreshold() const {
-  return ColdCountThreshold ? ColdCountThreshold.getValue() : 0;
+  return ColdCountThreshold.getValueOr(0);
 }
 
 bool ProfileSummaryInfo::isHotBlock(const BasicBlock *BB,

diff  --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp 
b/llvm/lib/Transforms/IPO/PartialInlining.cpp
index d517de38ace3e..6921c46be7a8e 100644
--- a/llvm/lib/Transforms/IPO/PartialInlining.cpp
+++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp
@@ -441,9 +441,7 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(
   };
 
   auto BBProfileCount = [BFI](BasicBlock *BB) {
-return BFI->getBlockProfileCount(BB)
-   ? BFI->getBlockProfileCount(BB).getValue()
-   : 0;
+return BFI->getBlockProfileCount(BB).getValueOr(0);
   };
 
   // Use the same computeBBInlineCost function to compute the cost savings of

diff  --git a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp 
b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
index 08d316337ef55..21395460bccba 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -415,9 +415,7 @@ void PseudoProbeUpdatePass::runOnFunction(Function ,
   FunctionAnalysisManager ) {
   BlockFrequencyInfo  = FAM.getResult(F);
   auto BBProfileCount = [](BasicBlock *BB) {
-return BFI.getBlockProfileCount(BB)
-   ? BFI.getBlockProfileCount(BB).getValue()
-   : 0;
+return BFI.getBlockProfileCount(BB).getValueOr(0);
   };
 
   // Collect the sum of execution weight for each probe.

diff  --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp 
b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
index 3b4d80dc80232..440fc8e805975 100644
--- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
@@ -1752,7 +1752,7 @@ void CHR::transformScopes(CHRScope *Scope, 
DenseSet ) {
   // Create the combined branch condition and constant-fold the 
branches/selects
   // in the hot path.
   fixupBranchesAndSelects(Scope, PreEntryBlock, MergedBr,
-  ProfileCount ? ProfileCount.getValue() : 0);
+  ProfileCount.getValueOr(0));
 }
 
 

[clang-tools-extra] 4db2e4c - Use {DenseSet,SetVector,SmallPtrSet}::contains (NFC)

2021-10-30 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2021-10-30T19:00:19-07:00
New Revision: 4db2e4cebe9c542b58aee26c556c84bd12aa6780

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

LOG: Use {DenseSet,SetVector,SmallPtrSet}::contains (NFC)

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp

clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
clang/include/clang/Basic/TargetInfo.h
clang/include/clang/Sema/Scope.h
clang/lib/AST/ASTImporterLookupTable.cpp
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/AST/VTableBuilder.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
llvm/tools/llvm-objcopy/COFF/Object.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
index 7f851f0ba0237..c98a1ab7104fb 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
@@ -123,7 +123,7 @@ void 
ForwardDeclarationNamespaceCheck::onEndOfTranslationUnit() {
   if (CurDecl->hasDefinition() || CurDecl->isReferenced()) {
 continue; // Skip forward declarations that are used/referenced.
   }
-  if (FriendTypes.count(CurDecl->getTypeForDecl()) != 0) {
+  if (FriendTypes.contains(CurDecl->getTypeForDecl())) {
 continue; // Skip forward declarations referenced as friend.
   }
   if (CurDecl->getLocation().isMacroID() ||

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index 0c220e865ff48..aa9a0ca80458d 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -209,7 +209,7 @@ computeInsertions(const 
CXXConstructorDecl::init_const_range ,
   // Add all fields between current field up until the next initializer.
   for (; Decl != std::end(OrderedDecls) && *Decl != InitDecl; ++Decl) {
 if (const auto *D = dyn_cast(*Decl)) {
-  if (DeclsToInit.count(D) > 0)
+  if (DeclsToInit.contains(D))
 Insertions.back().Initializers.emplace_back(getName(D));
 }
   }
@@ -221,7 +221,7 @@ computeInsertions(const 
CXXConstructorDecl::init_const_range ,
   // Add remaining decls that require initialization.
   for (; Decl != std::end(OrderedDecls); ++Decl) {
 if (const auto *D = dyn_cast(*Decl)) {
-  if (DeclsToInit.count(D) > 0)
+  if (DeclsToInit.contains(D))
 Insertions.back().Initializers.emplace_back(getName(D));
 }
   }

diff  --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index ca96ab67090cc..04dff8dfefe06 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -172,7 +172,7 @@ void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl 
*D) {
   //
   // FIXME: Use a more efficient way to find a matching context.
   for (auto  : Contexts) {
-if (Context.UsingTargetDecls.count(D->getCanonicalDecl()) > 0)
+if (Context.UsingTargetDecls.contains(D->getCanonicalDecl()))
   Context.IsUsed = true;
   }
 }

diff  --git 
a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
index 9d467e54a98d8..1fcd1b76af852 100644
--- 
a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
@@ -303,7 +303,7 @@ void InconsistentDeclarationParameterNameCheck::check(
   const auto *OriginalDeclaration =
   Result.Nodes.getNodeAs("functionDecl");
 
-  if (VisitedDeclarations.count(OriginalDeclaration) > 0)
+  if (VisitedDeclarations.contains(OriginalDeclaration))
 return; // Avoid multiple warnings.
 
   const FunctionDecl *ParameterSourceDeclaration =

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 98a4f4a4343f8..77a510462a65e 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1013,8 

[PATCH] D111797: [clang][scan-build] Use uname -s to detect the operating system.

2021-10-30 Thread Frederic Cambus 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 rG6ecd4a4d01a3: [clang][scan-build] Use uname -s to detect the 
operating system. (authored by fcambus).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111797

Files:
  clang/tools/scan-build/libexec/ccc-analyzer


Index: clang/tools/scan-build/libexec/ccc-analyzer
===
--- clang/tools/scan-build/libexec/ccc-analyzer
+++ clang/tools/scan-build/libexec/ccc-analyzer
@@ -72,7 +72,7 @@
 # If on OSX, use xcrun to determine the SDK root.
 my $UseXCRUN = 0;
 
-if (`uname -a` =~ m/Darwin/) {
+if (`uname -s` =~ m/Darwin/) {
   $DefaultCCompiler = 'clang';
   $DefaultCXXCompiler = 'clang++';
   # Older versions of OSX do not have xcrun to
@@ -80,7 +80,7 @@
   if (-x "/usr/bin/xcrun") {
 $UseXCRUN = 1;
   }
-} elsif (`uname -a` =~ m/OpenBSD/) {
+} elsif (`uname -s` =~ m/OpenBSD/) {
   $DefaultCCompiler = 'cc';
   $DefaultCXXCompiler = 'c++';
 } else {


Index: clang/tools/scan-build/libexec/ccc-analyzer
===
--- clang/tools/scan-build/libexec/ccc-analyzer
+++ clang/tools/scan-build/libexec/ccc-analyzer
@@ -72,7 +72,7 @@
 # If on OSX, use xcrun to determine the SDK root.
 my $UseXCRUN = 0;
 
-if (`uname -a` =~ m/Darwin/) {
+if (`uname -s` =~ m/Darwin/) {
   $DefaultCCompiler = 'clang';
   $DefaultCXXCompiler = 'clang++';
   # Older versions of OSX do not have xcrun to
@@ -80,7 +80,7 @@
   if (-x "/usr/bin/xcrun") {
 $UseXCRUN = 1;
   }
-} elsif (`uname -a` =~ m/OpenBSD/) {
+} elsif (`uname -s` =~ m/OpenBSD/) {
   $DefaultCCompiler = 'cc';
   $DefaultCXXCompiler = 'c++';
 } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6ecd4a4 - [clang][scan-build] Use uname -s to detect the operating system.

2021-10-30 Thread Frederic Cambus via cfe-commits

Author: Frederic Cambus
Date: 2021-10-30T23:26:39+02:00
New Revision: 6ecd4a4d01a3f71dc6590194dd00f96550c2ab04

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

LOG: [clang][scan-build] Use uname -s to detect the operating system.

We only need the operating system name, not all information.

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

Added: 


Modified: 
clang/tools/scan-build/libexec/ccc-analyzer

Removed: 




diff  --git a/clang/tools/scan-build/libexec/ccc-analyzer 
b/clang/tools/scan-build/libexec/ccc-analyzer
index ed0d4d3d73f38..2a589a3a0ef5e 100755
--- a/clang/tools/scan-build/libexec/ccc-analyzer
+++ b/clang/tools/scan-build/libexec/ccc-analyzer
@@ -72,7 +72,7 @@ my $AnalyzerTarget;
 # If on OSX, use xcrun to determine the SDK root.
 my $UseXCRUN = 0;
 
-if (`uname -a` =~ m/Darwin/) {
+if (`uname -s` =~ m/Darwin/) {
   $DefaultCCompiler = 'clang';
   $DefaultCXXCompiler = 'clang++';
   # Older versions of OSX do not have xcrun to
@@ -80,7 +80,7 @@ if (`uname -a` =~ m/Darwin/) {
   if (-x "/usr/bin/xcrun") {
 $UseXCRUN = 1;
   }
-} elsif (`uname -a` =~ m/OpenBSD/) {
+} elsif (`uname -s` =~ m/OpenBSD/) {
   $DefaultCCompiler = 'cc';
   $DefaultCXXCompiler = 'c++';
 } else {



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


[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-30 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 383608.
eopXD added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -17,7 +17,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
-; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefix=RV64A %s
 ; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | FileCheck --check-prefix=RV64F %s
@@ -35,14 +35,14 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbr %s -o - | FileCheck 

[PATCH] D112359: [RISCV] Unify depedency check and extension implication parsing logics

2021-10-30 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 383607.
eopXD added a comment.

Address comment: Enforce user to specify version checks.

@asb Thank you for leaving comments for this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112359

Files:
  clang/test/CodeGen/RISCV/riscv-metadata.c
  clang/test/CodeGen/RISCV/riscv32-ilp32-ilp32f-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv32-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv32-ilp32f-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv64-lp64-lp64f-lp64d-abi.c
  clang/test/CodeGen/RISCV/riscv64-lp64d-abi.c
  clang/test/CodeGen/RISCV/riscv64-lp64f-lp64d-abi.c
  clang/test/CodeGen/riscv32-ilp32d-abi.cpp
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Index: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===
--- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -2062,7 +2062,11 @@
 "unexpected token in '.attribute' directive"))
 return true;
 
-  if (Tag == RISCVAttrs::ARCH) {
+  if (IsIntegerValue)
+getTargetStreamer().emitAttribute(Tag, IntegerValue);
+  else if (Tag != RISCVAttrs::ARCH)
+getTargetStreamer().emitTextAttribute(Tag, StringValue);
+  else {
 StringRef Arch = StringValue;
 for (auto Feature : RISCVFeatureKV)
   if (llvm::RISCVISAInfo::isSupportedExtensionFeature(Feature.Key))
@@ -2093,35 +2097,9 @@
   setFeatureBits(RISCV::Feature64Bit, "64bit");
 else
   return Error(ValueExprLoc, "bad arch string " + Arch);
-  }
 
-  if (IsIntegerValue)
-getTargetStreamer().emitAttribute(Tag, IntegerValue);
-  else {
-if (Tag != RISCVAttrs::ARCH) {
-  getTargetStreamer().emitTextAttribute(Tag, StringValue);
-} else {
-  std::vector FeatureVector;
-  RISCVFeatures::toFeatureVector(FeatureVector, getSTI().getFeatureBits());
-
-  // Parse that by RISCVISAInfo->
-  unsigned XLen = getFeatureBits(RISCV::Feature64Bit) ? 64 : 32;
-  auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, FeatureVector);
-  if (!ParseResult) {
-std::string Buffer;
-raw_string_ostream OutputErrMsg(Buffer);
-handleAllErrors(ParseResult.takeError(),
-[&](llvm::StringError ) {
-  OutputErrMsg << ErrMsg.getMessage();
-});
-
-return Error(ValueExprLoc, OutputErrMsg.str());
-  }
-  auto  = *ParseResult;
-
-  // Then emit the arch string.
-  getTargetStreamer().emitTextAttribute(Tag, ISAInfo->toString());
-}
+// Then emit the arch string.
+getTargetStreamer().emitTextAttribute(Tag, ISAInfo->toString());
   }
 
   return false;
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -411,7 +411,6 @@
   assert(XLen == 32 || XLen == 64);
   std::unique_ptr ISAInfo(new RISCVISAInfo(XLen));
 
-  bool HasE = false;
   for (auto  : Features) {
 StringRef ExtName = Feature;
 bool Experimental = false;
@@ -430,29 +429,19 @@
 if (ExtensionInfoIterator == ExtensionInfos.end())
   continue;
 
-if (Add) {
-  if (ExtName == "e") {
-if (XLen != 32)
-  return createStringError(
-  errc::invalid_argument,
-  "standard user-level extension 'e' requires 'rv32'");
-HasE = true;
-  }
-
+if (Add)
   ISAInfo->addExtension(ExtName, ExtensionInfoIterator->Version.Major,
 ExtensionInfoIterator->Version.Minor);
-} else
-  ISAInfo->Exts.erase(ExtName.str());
-  }
-  if (!HasE) {
-if (auto Version = findDefaultVersion("i"))
-  ISAInfo->addExtension("i", Version->Major, Version->Minor);
 else
-  llvm_unreachable("Default extension version for 'i' not found?");
+  ISAInfo->Exts.erase(ExtName.str());
   }
 
+  ISAInfo->updateImplication();
   ISAInfo->updateFLen();
 
+  if (Error Result = ISAInfo->checkDependency())
+return std::move(Result);
+
   return std::move(ISAInfo);
 }
 
@@ -478,7 +467,6 @@
   // The canonical order specified in ISA manual.
   // Ref: Table 22.1 in RISC-V User-Level ISA V2.2
   StringRef StdExts = AllStdExts;
-  bool HasF = false, HasD = false;
   char Baseline = Arch[4];
 
   // First letter should be 'e', 'i' or 'g'.
@@ -499,8 +487,6 @@
   case 'g':
 // g = imafd
 StdExts = StdExts.drop_front(4);
-HasF = true;
-HasD = true;
 break;
   }
 
@@ -581,34 +567,14 @@
 
 // The order is OK, then push it into features.
 // TODO: Use version number when setting target features
-switch (C) {
-default:
-  // Currently LLVM supports only "mafdcbv".
+// Currently LLVM supports only 

[PATCH] D112359: [RISCV] Unify depedency check and extension implication parsing logics

2021-10-30 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 383606.
eopXD added a comment.
Herald added subscribers: VincentWu, luke957.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112359

Files:
  clang/test/CodeGen/RISCV/riscv-metadata.c
  clang/test/CodeGen/RISCV/riscv32-ilp32-ilp32f-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv32-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv32-ilp32f-ilp32d-abi.c
  clang/test/CodeGen/RISCV/riscv64-lp64-lp64f-lp64d-abi.c
  clang/test/CodeGen/RISCV/riscv64-lp64d-abi.c
  clang/test/CodeGen/RISCV/riscv64-lp64f-lp64d-abi.c
  clang/test/CodeGen/riscv32-ilp32d-abi.cpp
  clang/test/Driver/riscv-arch.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Index: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===
--- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -2062,7 +2062,11 @@
 "unexpected token in '.attribute' directive"))
 return true;
 
-  if (Tag == RISCVAttrs::ARCH) {
+  if (IsIntegerValue)
+getTargetStreamer().emitAttribute(Tag, IntegerValue);
+  else if (Tag != RISCVAttrs::ARCH)
+getTargetStreamer().emitTextAttribute(Tag, StringValue);
+  else {
 StringRef Arch = StringValue;
 for (auto Feature : RISCVFeatureKV)
   if (llvm::RISCVISAInfo::isSupportedExtensionFeature(Feature.Key))
@@ -2070,7 +2074,7 @@
 
 auto ParseResult = llvm::RISCVISAInfo::parseArchString(
 StringValue, /*EnableExperimentalExtension=*/true,
-/*ExperimentalExtensionVersionCheck=*/false);
+/*ExperimentalExtensionVersionCheck=*/true);
 if (!ParseResult) {
   std::string Buffer;
   raw_string_ostream OutputErrMsg(Buffer);
@@ -2093,35 +2097,9 @@
   setFeatureBits(RISCV::Feature64Bit, "64bit");
 else
   return Error(ValueExprLoc, "bad arch string " + Arch);
-  }
 
-  if (IsIntegerValue)
-getTargetStreamer().emitAttribute(Tag, IntegerValue);
-  else {
-if (Tag != RISCVAttrs::ARCH) {
-  getTargetStreamer().emitTextAttribute(Tag, StringValue);
-} else {
-  std::vector FeatureVector;
-  RISCVFeatures::toFeatureVector(FeatureVector, getSTI().getFeatureBits());
-
-  // Parse that by RISCVISAInfo->
-  unsigned XLen = getFeatureBits(RISCV::Feature64Bit) ? 64 : 32;
-  auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, FeatureVector);
-  if (!ParseResult) {
-std::string Buffer;
-raw_string_ostream OutputErrMsg(Buffer);
-handleAllErrors(ParseResult.takeError(),
-[&](llvm::StringError ) {
-  OutputErrMsg << ErrMsg.getMessage();
-});
-
-return Error(ValueExprLoc, OutputErrMsg.str());
-  }
-  auto  = *ParseResult;
-
-  // Then emit the arch string.
-  getTargetStreamer().emitTextAttribute(Tag, ISAInfo->toString());
-}
+// Then emit the arch string.
+getTargetStreamer().emitTextAttribute(Tag, ISAInfo->toString());
   }
 
   return false;
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -360,6 +360,11 @@
 
 if (ExperimentalExtensionVersionCheck &&
 (MajorStr.empty() && MinorStr.empty())) {
+  if (auto DefaultVersion = findDefaultVersion(Ext)) {
+Major = DefaultVersion->Major;
+Minor = DefaultVersion->Minor;
+return Error::success();
+  }
   std::string Error =
   "experimental extension requires explicit version number `" +
   Ext.str() + "`";
@@ -411,7 +416,6 @@
   assert(XLen == 32 || XLen == 64);
   std::unique_ptr ISAInfo(new RISCVISAInfo(XLen));
 
-  bool HasE = false;
   for (auto  : Features) {
 StringRef ExtName = Feature;
 bool Experimental = false;
@@ -430,29 +434,19 @@
 if (ExtensionInfoIterator == ExtensionInfos.end())
   continue;
 
-if (Add) {
-  if (ExtName == "e") {
-if (XLen != 32)
-  return createStringError(
-  errc::invalid_argument,
-  "standard user-level extension 'e' requires 'rv32'");
-HasE = true;
-  }
-
+if (Add)
   ISAInfo->addExtension(ExtName, ExtensionInfoIterator->Version.Major,
 ExtensionInfoIterator->Version.Minor);
-} else
-  ISAInfo->Exts.erase(ExtName.str());
-  }
-  if (!HasE) {
-if (auto Version = findDefaultVersion("i"))
-  ISAInfo->addExtension("i", Version->Major, Version->Minor);
 else
-  llvm_unreachable("Default extension version for 'i' not found?");
+  ISAInfo->Exts.erase(ExtName.str());
   }
 
+  ISAInfo->updateImplication();
   ISAInfo->updateFLen();
 
+  if (Error Result = 

[PATCH] D109215: [RISCV] Fix arch string parsing for multi-character extensions

2021-10-30 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 383605.
eopXD added a comment.
Herald added subscribers: VincentWu, luke957.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109215

Files:
  clang/test/Driver/riscv-arch.c
  llvm/lib/Support/RISCVISAInfo.cpp


Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -71,6 +71,28 @@
   return Ext.consume_front("experimental-");
 }
 
+// This function finds the first character that doesn't belong to a version
+// (e.g. zbe0p93 is extension 'zbe' of version '0p93'). So the function will
+// consume [0-9]*p[0-9]* starting from the backward. An extension name will not
+// end with a digit or the letter 'p', so this function will parse correctly.
+// NOTE: This function is NOT able to take empty strings or strings that only
+// have version numbers and no extension name. It assumes the extension name
+// will be at least more than one character.
+static size_t findFirstNonVersionCharacter(const StringRef ) {
+  if (Ext.size() == 0)
+llvm_unreachable("Already guarded by if-statement in ::parseArchString");
+
+  int Pos = Ext.size() - 1;
+  while (Pos > 0 && isDigit(Ext[Pos]))
+Pos--;
+  if (Pos > 0 && Ext[Pos] == 'p' && isDigit(Ext[Pos - 1])) {
+Pos--;
+while (Pos > 0 && isDigit(Ext[Pos]))
+  Pos--;
+  }
+  return Pos;
+}
+
 struct FindByName {
   FindByName(StringRef Ext) : Ext(Ext){};
   StringRef Ext;
@@ -637,7 +659,7 @@
 
 StringRef Type = getExtensionType(Ext);
 StringRef Desc = getExtensionTypeDesc(Ext);
-auto Pos = Ext.find_if(isDigit);
+size_t Pos = findFirstNonVersionCharacter(Ext) + 1;
 StringRef Name(Ext.substr(0, Pos));
 StringRef Vers(Ext.substr(Pos));
 
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -392,7 +392,7 @@
 
 // RUN: %clang -target riscv32-unknown-elf -march=rv32izbb1p0zbp0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE %s
-// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb1p0zbp0p93', multi-character extensions must be separated by 
underscores
+// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb1p0zbp0p93', unsupported version number 0.93 for extension 'zbb1p0zbp'
 
 // RUN: %clang -target riscv32-unknown-elf -march=rv32izba1p0 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBA %s


Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -71,6 +71,28 @@
   return Ext.consume_front("experimental-");
 }
 
+// This function finds the first character that doesn't belong to a version
+// (e.g. zbe0p93 is extension 'zbe' of version '0p93'). So the function will
+// consume [0-9]*p[0-9]* starting from the backward. An extension name will not
+// end with a digit or the letter 'p', so this function will parse correctly.
+// NOTE: This function is NOT able to take empty strings or strings that only
+// have version numbers and no extension name. It assumes the extension name
+// will be at least more than one character.
+static size_t findFirstNonVersionCharacter(const StringRef ) {
+  if (Ext.size() == 0)
+llvm_unreachable("Already guarded by if-statement in ::parseArchString");
+
+  int Pos = Ext.size() - 1;
+  while (Pos > 0 && isDigit(Ext[Pos]))
+Pos--;
+  if (Pos > 0 && Ext[Pos] == 'p' && isDigit(Ext[Pos - 1])) {
+Pos--;
+while (Pos > 0 && isDigit(Ext[Pos]))
+  Pos--;
+  }
+  return Pos;
+}
+
 struct FindByName {
   FindByName(StringRef Ext) : Ext(Ext){};
   StringRef Ext;
@@ -637,7 +659,7 @@
 
 StringRef Type = getExtensionType(Ext);
 StringRef Desc = getExtensionTypeDesc(Ext);
-auto Pos = Ext.find_if(isDigit);
+size_t Pos = findFirstNonVersionCharacter(Ext) + 1;
 StringRef Name(Ext.substr(0, Pos));
 StringRef Vers(Ext.substr(Pos));
 
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -392,7 +392,7 @@
 
 // RUN: %clang -target riscv32-unknown-elf -march=rv32izbb1p0zbp0p93 -menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE %s
-// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 'rv32izbb1p0zbp0p93', multi-character extensions must be separated by underscores
+// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 'rv32izbb1p0zbp0p93', unsupported 

[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-30 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 383601.
eopXD added a comment.

Rebase to newest main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -17,7 +17,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
-; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefix=RV64A %s
 ; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | FileCheck --check-prefix=RV64F %s
@@ -35,14 +35,14 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbr %s -o - | FileCheck 

[PATCH] D112572: [docs][clang-format] warn on \code block indentation error

2021-10-30 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG931d20c5db05: [docs][clang-format] warn on \code block 
indentation error (authored by FederAndInk, committed by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112572

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3430,29 +3430,31 @@
   /// How many spaces are allowed at the start of a line comment. To disable the
   /// maximum set it to ``-1``, apart from that the maximum takes precedence
   /// over the minimum.
-  /// \code Minimum = 1 Maximum = -1
-  /// // One space is forced
+  /// \code
+  ///   Minimum = 1
+  ///   Maximum = -1
+  ///   // One space is forced
   ///
-  /// //  but more spaces are possible
+  ///   //  but more spaces are possible
   ///
-  /// Minimum = 0
-  /// Maximum = 0
-  /// //Forces to start every comment directly after the slashes
+  ///   Minimum = 0
+  ///   Maximum = 0
+  ///   //Forces to start every comment directly after the slashes
   /// \endcode
   ///
   /// Note that in line comment sections the relative indent of the subsequent
   /// lines is kept, that means the following:
   /// \code
-  /// before:   after:
-  /// Minimum: 1
-  /// //if (b) {// if (b) {
-  /// //  return true;  //   return true;
-  /// //}   // }
+  ///   before:   after:
+  ///   Minimum: 1
+  ///   //if (b) {// if (b) {
+  ///   //  return true;  //   return true;
+  ///   //}   // }
   ///
-  /// Maximum: 0
-  /// /// List: ///List:
-  /// ///  - Foo/// - Foo
-  /// ///- Bar  ///   - Bar
+  ///   Maximum: 0
+  ///   /// List: ///List:
+  ///   ///  - Foo/// - Foo
+  ///   ///- Bar  ///   - Bar
   /// \endcode
   /// \version 14
   SpacesInLineComment SpacesInLineCommentPrefix;
Index: clang/docs/tools/dump_format_style.py
===
--- clang/docs/tools/dump_format_style.py
+++ clang/docs/tools/dump_format_style.py
@@ -6,6 +6,8 @@
 import inspect
 import os
 import re
+import sys
+from io import TextIOWrapper
 from typing import Set
 
 CLANG_DIR = os.path.join(os.path.dirname(__file__), '../..')
@@ -40,7 +42,7 @@
 lineno = ''
 if cf and cf.f_back:
   lineno = ':' + str(cf.f_back.f_lineno)
-print(f'{__file__}{lineno} check if plural of {singular} is {plural}', file=os.sys.stderr)
+print(f'{__file__}{lineno} check if plural of {singular} is {plural}', file=sys.stderr)
   return plural
 
 def pluralize(word: str):
@@ -80,16 +82,16 @@
   return text
 
 def indent(text, columns, indent_first_line=True):
-  indent = ' ' * columns
-  s = re.sub(r'\n([^\n])', '\n' + indent + '\\1', text, flags=re.S)
+  indent_str = ' ' * columns
+  s = re.sub(r'\n([^\n])', '\n' + indent_str + '\\1', text, flags=re.S)
   if not indent_first_line or s.startswith('\n'):
 return s
-  return indent + s
+  return indent_str + s
 
 class Option(object):
-  def __init__(self, name, type, comment, version):
+  def __init__(self, name, opt_type, comment, version):
 self.name = name
-self.type = type
+self.type = opt_type
 self.comment = comment.strip()
 self.enum = None
 self.nested_struct = None
@@ -148,8 +150,8 @@
 s = '\n* ``%s %s``\n%s' % (to_yaml_type(self.type), self.name,
  doxygen2rst(indent(self.comment, 2)))
 s += indent('\nPossible values:\n\n', 2)
-s += indent('\n'.join(map(str, self.values)),2)
-return s;
+s += indent('\n'.join(map(str, self.values)), 2)
+return s
 
 class EnumValue(object):
   def __init__(self, name, comment, config):
@@ -163,148 +165,191 @@
 re.sub('.*_', '', self.config),
 doxygen2rst(indent(self.comment, 2)))
 
-def clean_comment_line(line):
-  match = re.match(r'^/// (?P +)?\\code(\{.(?P\w+)\})?$', line)
-  if match:
-indent = match.group('indent')
-if not indent:
-  indent = ''
-lang = match.group('lang')
-if not lang:
-  lang = 'c++'
-return '\n%s.. code-block:: %s\n\n' % (indent, lang)
-
-  endcode_match = re.match(r'^/// +\\endcode$', line)
-  if endcode_match:
-return ''
-
-  match = re.match(r'^/// \\warning$', line)
-  if match:
-return '\n.. warning:: \n\n'
-
-  

[clang] 931d20c - [docs][clang-format] warn on \code block indentation error

2021-10-30 Thread via cfe-commits

Author: Ludovic Jozeau
Date: 2021-10-30T17:45:39+01:00
New Revision: 931d20c5db05fc2e2f4071cc086fa3ff1b4aebdd

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

LOG: [docs][clang-format] warn on \code block indentation error

There is an indentation issue in Format.h causing the html to not render 
correctly
It's a `\code` block in the documentation of SpacesInLineComment

- fix intentation of `SpacesInLineComment`
- warn on indentation error
- also warn on `\code` `\endcode` mismatch
- generate precise warnings
- fix some minor and style issues:
  - avoid confusion with the built-in `type` function
  - fix wrong print on `os.sys.stderr` (instead of `sys.stderr`)
  - use `with as` pattern for files

Reviewed By: MyDeveloperDay, HazardyKnusperkeks

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/tools/dump_format_style.py
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index e2e044145018b..e9a381c93a46b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3807,30 +3807,34 @@ the configuration (without a prefix: ``Auto``).
   How many spaces are allowed at the start of a line comment. To disable the
   maximum set it to ``-1``, apart from that the maximum takes precedence
   over the minimum.
-  Minimum = 1 Maximum = -1
-  // One space is forced
 
-  //  but more spaces are possible
+  .. code-block:: c++
+
+Minimum = 1
+Maximum = -1
+// One space is forced
+
+//  but more spaces are possible
 
-  Minimum = 0
-  Maximum = 0
-  //Forces to start every comment directly after the slashes
+Minimum = 0
+Maximum = 0
+//Forces to start every comment directly after the slashes
 
   Note that in line comment sections the relative indent of the subsequent
   lines is kept, that means the following:
 
   .. code-block:: c++
 
-  before:   after:
-  Minimum: 1
-  //if (b) {// if (b) {
-  //  return true;  //   return true;
-  //}   // }
+before:   after:
+Minimum: 1
+//if (b) {// if (b) {
+//  return true;  //   return true;
+//}   // }
 
-  Maximum: 0
-  /// List: ///List:
-  ///  - Foo/// - Foo
-  ///- Bar  ///   - Bar
+Maximum: 0
+/// List: ///List:
+///  - Foo/// - Foo
+///- Bar  ///   - Bar
 
   Nested configuration flags:
 

diff  --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index a86b47bb27605..d04920987ec67 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -6,6 +6,8 @@
 import inspect
 import os
 import re
+import sys
+from io import TextIOWrapper
 from typing import Set
 
 CLANG_DIR = os.path.join(os.path.dirname(__file__), '../..')
@@ -40,7 +42,7 @@ def register_plural(singular: str, plural: str):
 lineno = ''
 if cf and cf.f_back:
   lineno = ':' + str(cf.f_back.f_lineno)
-print(f'{__file__}{lineno} check if plural of {singular} is {plural}', 
file=os.sys.stderr)
+print(f'{__file__}{lineno} check if plural of {singular} is {plural}', 
file=sys.stderr)
   return plural
 
 def pluralize(word: str):
@@ -80,16 +82,16 @@ def doxygen2rst(text):
   return text
 
 def indent(text, columns, indent_first_line=True):
-  indent = ' ' * columns
-  s = re.sub(r'\n([^\n])', '\n' + indent + '\\1', text, flags=re.S)
+  indent_str = ' ' * columns
+  s = re.sub(r'\n([^\n])', '\n' + indent_str + '\\1', text, flags=re.S)
   if not indent_first_line or s.startswith('\n'):
 return s
-  return indent + s
+  return indent_str + s
 
 class Option(object):
-  def __init__(self, name, type, comment, version):
+  def __init__(self, name, opt_type, comment, version):
 self.name = name
-self.type = type
+self.type = opt_type
 self.comment = comment.strip()
 self.enum = None
 self.nested_struct = None
@@ -148,8 +150,8 @@ def __str__(self):
 s = '\n* ``%s %s``\n%s' % (to_yaml_type(self.type), self.name,
  doxygen2rst(indent(self.comment, 2)))
 s += indent('\nPossible values:\n\n', 2)
-s += indent('\n'.join(map(str, self.values)),2)
-return s;
+s += indent('\n'.join(map(str, self.values)), 2)
+return 

[PATCH] D108694: [WIP][RISCV] Add the zvl extension according to the v1.0-rc2 spec

2021-10-30 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 383599.
eopXD added a comment.
Herald added subscribers: VincentWu, luke957.

Fix test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108694

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -34,7 +34,7 @@
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
@@ -70,7 +70,43 @@
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfh0p1"
 
 .attribute arch, "rv32ivzvamo_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
 
 .attribute arch, "rv32iv_zvamo0p10_zvlsseg"
-# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl64b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl128b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl256b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl512b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl1024b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl2048b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl4096b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl8192b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl16384b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl32768b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl8192b0p10_zvlsseg0p10"
+
+.attribute arch, "rv32iv_zvl65536b"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvl1024b0p10_zvl128b0p10_zvl16384b0p10_zvl2048b0p10_zvl256b0p10_zvl32768b0p10_zvl32b0p10_zvl4096b0p10_zvl512b0p10_zvl64b0p10_zvl65536b0p10_zvl8192b0p10_zvlsseg0p10"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -17,7 +17,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
-; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefix=RV64A %s
 ; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | FileCheck --check-prefix=RV64F %s
@@ -35,14 +35,14 @@
 ; RUN: llc -mtriple=riscv64 

[clang] bee61aa - [clang-format] Add --staged/--cached option to git-clang-format

2021-10-30 Thread via cfe-commits

Author: Erik Larsson
Date: 2021-10-30T17:37:58+01:00
New Revision: bee61aa7b638726c3e0eec017fbd89d79a181434

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

LOG: [clang-format] Add --staged/--cached option to git-clang-format

When running git-clang-format in a pre-commit hook it's very useful to be able 
to tell git-clang-format to only look at the --staged/--cached files and not 
the working directory.

Note this patch is a rebase/fork from {D41147 } which is a fork of {D15465 }

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, lodato

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

Co-authored-by: Mark Lodato 

Added: 


Modified: 
clang/tools/clang-format/git-clang-format

Removed: 




diff  --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index c7e15eb7b483..bb5b5546d6a5 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -32,12 +32,13 @@ import re
 import subprocess
 import sys
 
-usage = 'git clang-format [OPTIONS] [] [] [--] [...]'
+usage = ('git clang-format [OPTIONS] [] [|--staged] '
+ '[--] [...]')
 
 desc = '''
 If zero or one commits are given, run clang-format on all lines that 
diff er
 between the working directory and , which defaults to HEAD.  Changes 
are
-only applied to the working directory.
+only applied to the working directory, or in the stage/index.
 
 If two commits are given (requires --
diff ), run clang-format on all lines in the
 second  that 
diff er from the first .
@@ -112,6 +113,8 @@ def main():
  help='select hunks interactively')
   p.add_argument('-q', '--quiet', action='count', default=0,
  help='print less information')
+  p.add_argument('--staged', '--cached', action='store_true',
+ help='format lines in the stage instead of the working dir')
   p.add_argument('--style',
  default=config.get('clangformat.style', None),
  help='passed to clang-format'),
@@ -131,12 +134,14 @@ def main():
 
   commits, files = interpret_args(opts.args, dash_dash, opts.commit)
   if len(commits) > 1:
+if opts.staged:
+  die('--staged is not allowed when two commits are given')
 if not opts.
diff :
   die('--
diff  is required when two commits are given')
   else:
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
-  changed_lines = compute_
diff _and_extract_lines(commits, files)
+  changed_lines = compute_
diff _and_extract_lines(commits, files, opts.staged)
   if opts.verbose >= 1:
 ignored_files = set(changed_lines)
   filter_by_extension(changed_lines, opts.extensions.lower().split(','))
@@ -275,9 +280,9 @@ def get_object_type(value):
   return convert_string(stdout.strip())
 
 
-def compute_
diff _and_extract_lines(commits, files):
+def compute_
diff _and_extract_lines(commits, files, staged):
   """Calls compute_
diff () followed by extract_lines()."""
-  
diff _process = compute_
diff (commits, files)
+  
diff _process = compute_
diff (commits, files, staged)
   changed_lines = extract_lines(
diff _process.stdout)
   
diff _process.stdout.close()
   
diff _process.wait()
@@ -287,17 +292,21 @@ def compute_
diff _and_extract_lines(commits, files):
   return changed_lines
 
 
-def compute_
diff (commits, files):
+def compute_
diff (commits, files, staged):
   """Return a subprocess object producing the 
diff  from `commits`.
 
   The return value's `stdin` file object will produce a patch with the
-  
diff erences between the working directory and the first commit if a single
-  one was specified, or the 
diff erence between both specified commits, filtered
-  on `files` (if non-empty).  Zero context lines are used in the patch."""
+  
diff erences between the working directory (or stage if --staged is used) and
+  the first commit if a single one was specified, or the 
diff erence between
+  both specified commits, filtered on `files` (if non-empty).
+  Zero context lines are used in the patch."""
   git_tool = '
diff -index'
+  extra_args = []
   if len(commits) > 1:
 git_tool = '
diff -tree'
-  cmd = ['git', git_tool, '-p', '-U0'] + commits + ['--']
+  elif staged:
+extra_args += ['--cached']
+  cmd = ['git', git_tool, '-p', '-U0'] + extra_args + commits + ['--']
   cmd.extend(files)
   p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
   p.stdin.close()



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


[PATCH] D90996: [clang-format] Add --staged/--cached option to git-clang-format

2021-10-30 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbee61aa7b638: [clang-format] Add --staged/--cached option to 
git-clang-format (authored by ortogonal, committed by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90996

Files:
  clang/tools/clang-format/git-clang-format


Index: clang/tools/clang-format/git-clang-format
===
--- clang/tools/clang-format/git-clang-format
+++ clang/tools/clang-format/git-clang-format
@@ -32,12 +32,13 @@
 import subprocess
 import sys
 
-usage = 'git clang-format [OPTIONS] [] [] [--] [...]'
+usage = ('git clang-format [OPTIONS] [] [|--staged] '
+ '[--] [...]')
 
 desc = '''
 If zero or one commits are given, run clang-format on all lines that differ
 between the working directory and , which defaults to HEAD.  Changes 
are
-only applied to the working directory.
+only applied to the working directory, or in the stage/index.
 
 If two commits are given (requires --diff), run clang-format on all lines in 
the
 second  that differ from the first .
@@ -112,6 +113,8 @@
  help='select hunks interactively')
   p.add_argument('-q', '--quiet', action='count', default=0,
  help='print less information')
+  p.add_argument('--staged', '--cached', action='store_true',
+ help='format lines in the stage instead of the working dir')
   p.add_argument('--style',
  default=config.get('clangformat.style', None),
  help='passed to clang-format'),
@@ -131,12 +134,14 @@
 
   commits, files = interpret_args(opts.args, dash_dash, opts.commit)
   if len(commits) > 1:
+if opts.staged:
+  die('--staged is not allowed when two commits are given')
 if not opts.diff:
   die('--diff is required when two commits are given')
   else:
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
-  changed_lines = compute_diff_and_extract_lines(commits, files)
+  changed_lines = compute_diff_and_extract_lines(commits, files, opts.staged)
   if opts.verbose >= 1:
 ignored_files = set(changed_lines)
   filter_by_extension(changed_lines, opts.extensions.lower().split(','))
@@ -275,9 +280,9 @@
   return convert_string(stdout.strip())
 
 
-def compute_diff_and_extract_lines(commits, files):
+def compute_diff_and_extract_lines(commits, files, staged):
   """Calls compute_diff() followed by extract_lines()."""
-  diff_process = compute_diff(commits, files)
+  diff_process = compute_diff(commits, files, staged)
   changed_lines = extract_lines(diff_process.stdout)
   diff_process.stdout.close()
   diff_process.wait()
@@ -287,17 +292,21 @@
   return changed_lines
 
 
-def compute_diff(commits, files):
+def compute_diff(commits, files, staged):
   """Return a subprocess object producing the diff from `commits`.
 
   The return value's `stdin` file object will produce a patch with the
-  differences between the working directory and the first commit if a single
-  one was specified, or the difference between both specified commits, filtered
-  on `files` (if non-empty).  Zero context lines are used in the patch."""
+  differences between the working directory (or stage if --staged is used) and
+  the first commit if a single one was specified, or the difference between
+  both specified commits, filtered on `files` (if non-empty).
+  Zero context lines are used in the patch."""
   git_tool = 'diff-index'
+  extra_args = []
   if len(commits) > 1:
 git_tool = 'diff-tree'
-  cmd = ['git', git_tool, '-p', '-U0'] + commits + ['--']
+  elif staged:
+extra_args += ['--cached']
+  cmd = ['git', git_tool, '-p', '-U0'] + extra_args + commits + ['--']
   cmd.extend(files)
   p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
   p.stdin.close()


Index: clang/tools/clang-format/git-clang-format
===
--- clang/tools/clang-format/git-clang-format
+++ clang/tools/clang-format/git-clang-format
@@ -32,12 +32,13 @@
 import subprocess
 import sys
 
-usage = 'git clang-format [OPTIONS] [] [] [--] [...]'
+usage = ('git clang-format [OPTIONS] [] [|--staged] '
+ '[--] [...]')
 
 desc = '''
 If zero or one commits are given, run clang-format on all lines that differ
 between the working directory and , which defaults to HEAD.  Changes are
-only applied to the working directory.
+only applied to the working directory, or in the stage/index.
 
 If two commits are given (requires --diff), run clang-format on all lines in the
 second  that differ from the first .
@@ -112,6 +113,8 @@
  help='select hunks interactively')
   p.add_argument('-q', '--quiet', action='count', default=0,
  help='print less information')
+  p.add_argument('--staged', '--cached', action='store_true',

[PATCH] D112101: [AST] Fix the EndLoc calculation for ObjCObjectPointer

2021-10-30 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D112101#3097618 , @rsmith wrote:

> In D112101#3097387 , @rsmith wrote:
>
>> I think this is still not quite right
>
> Fixed in rG68ffcd521347e3c8b97ca233239d503beff239f4 
> .

Thanks for the quick fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112101

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


[PATCH] D112868: [Sema] Diagnose and reject non-function ifunc resolvers

2021-10-30 Thread Itay Bookstein via Phabricator via cfe-commits
ibookstein created this revision.
ibookstein added reviewers: MaskRay, aaron.ballman.
ibookstein requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Signed-off-by: Itay Bookstein 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112868

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Sema/attr-ifunc.c

Index: clang/test/Sema/attr-ifunc.c
===
--- clang/test/Sema/attr-ifunc.c
+++ clang/test/Sema/attr-ifunc.c
@@ -13,8 +13,7 @@
 void f1() __attribute__((ifunc("f1_ifunc")));
 //expected-error@-1 {{ifunc must point to a defined function}}
 
-void* f2_a() __attribute__((ifunc("f2_b")));
-//expected-error@-1 {{ifunc definition is part of a cycle}}
+void* f2_a() __attribute__((alias("f2_b")));
 void* f2_b() __attribute__((ifunc("f2_a")));
 //expected-error@-1 {{ifunc definition is part of a cycle}}
 
@@ -27,6 +26,15 @@
 void f4() __attribute__((ifunc("f4_ifunc")));
 //expected-error@-1 {{ifunc resolver function must return a pointer}}
 
+int f5_resolver_gvar;
+void f5() __attribute__((ifunc("f5_resolver_gvar")));
+//expected-error@-1 {{ifunc must point to a defined function}}
+
+void *f6_resolver_resolver() { return 0; }
+void *f6_resolver() __attribute__((ifunc("f6_resolver_resolver")));
+void f6() __attribute__((ifunc("f6_resolver")));
+//expected-error@-1 {{ifunc must point to a defined function}}
+
 #else
 void f1a() __asm("f1");
 void f1a() {}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -318,21 +318,58 @@
 // This is only used in aliases that we created and we know they have a
 // linear structure.
 static const llvm::GlobalValue *getAliasedGlobal(const llvm::GlobalValue *GV) {
-  llvm::SmallPtrSet Visited;
-  for (;;) {
-if (!GV || !Visited.insert(GV).second)
-  return nullptr;
-
-const llvm::Constant *C;
-if (auto *GA = dyn_cast(GV))
-  C = GA->getAliasee();
-else if (auto *GI = dyn_cast(GV))
-  C = GI->getResolver();
-else
-  return GV;
+  const llvm::Constant *C;
+  if (auto *GA = dyn_cast(GV))
+C = GA->getAliasee();
+  else if (auto *GI = dyn_cast(GV))
+C = GI->getResolver();
+  else
+return GV;
+
+  const auto *AliaseeGV = dyn_cast(C->stripPointerCasts());
+  if (!AliaseeGV)
+return nullptr;
+
+  const llvm::GlobalValue *FinalGV = AliaseeGV->getAliaseeObject();
+  if (FinalGV == GV)
+return nullptr;
+
+  return FinalGV;
+}
+
+static bool checkAliasedGlobal(const llvm::GlobalValue *Alias,
+   DiagnosticsEngine ,
+   SourceLocation Location,
+   const llvm::GlobalValue *) {
+  bool IsIFunc = isa(Alias);
+  GV = getAliasedGlobal(Alias);
+  if (!GV) {
+Diags.Report(Location, diag::err_cyclic_alias) << IsIFunc;
+return false;
+  }
+
+  if (GV->isDeclaration()) {
+Diags.Report(Location, diag::err_alias_to_undefined) << IsIFunc << IsIFunc;
+return false;
+  }
+
+  if (IsIFunc) {
+// Check resolver function type.
+const auto *F = dyn_cast(GV);
+if (!F) {
+  Diags.Report(Location, diag::err_alias_to_undefined)
+  << IsIFunc << IsIFunc;
+  return false;
+}
 
-GV = dyn_cast(C->stripPointerCasts());
+llvm::FunctionType *FTy = F->getFunctionType();
+if (!FTy->getReturnType()->isPointerTy()) {
+  Diags.Report(Location, diag::err_ifunc_resolver_return);
+  return false;
+}
   }
+
+  return true;
 }
 
 void CodeGenModule::checkAliases() {
@@ -344,30 +381,20 @@
   for (const GlobalDecl  : Aliases) {
 const auto *D = cast(GD.getDecl());
 SourceLocation Location;
-bool IsIFunc = D->hasAttr();
 if (const Attr *A = D->getDefiningAttr())
   Location = A->getLocation();
 else
   llvm_unreachable("Not an alias or ifunc?");
+
 StringRef MangledName = getMangledName(GD);
 llvm::GlobalValue *Alias = GetGlobalValue(MangledName);
-const llvm::GlobalValue *GV = getAliasedGlobal(Alias);
-if (!GV) {
-  Error = true;
-  Diags.Report(Location, diag::err_cyclic_alias) << IsIFunc;
-} else if (GV->isDeclaration()) {
+const llvm::GlobalValue *GV = nullptr;
+if (!checkAliasedGlobal(Alias, Diags, Location, GV)) {
   Error = true;
-  Diags.Report(Location, diag::err_alias_to_undefined)
-  << IsIFunc << IsIFunc;
-} else if (IsIFunc) {
-  // Check resolver function type.
-  llvm::FunctionType *FTy = dyn_cast(
-  GV->getType()->getPointerElementType());
-  assert(FTy);
-  if (!FTy->getReturnType()->isPointerTy())
-Diags.Report(Location, diag::err_ifunc_resolver_return);
+  continue;
 }
 
+bool IsIFunc = isa(Alias);
 llvm::Constant *Aliasee =
 IsIFunc ? cast(Alias)->getResolver()
 : 

[PATCH] D112804: [ASTImporter] Remove ASTNodeImporter::IsStructuralMatch overload for EnumConstantDecl

2021-10-30 Thread Raphael Isemann 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 rG01b3bd3992b4: [ASTImporter] Remove 
ASTNodeImporter::IsStructuralMatch overload for… (authored by teemperor).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112804

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -956,6 +956,48 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+struct StructuralEquivalenceEnumConstantTest : StructuralEquivalenceTest {};
+
+TEST_F(StructuralEquivalenceEnumConstantTest, EnumConstantsWithSameValues) {
+  auto t = makeNamedDecls("enum foo { foo = 1 };", "enum foo { foo = 1 };",
+  Lang_C89);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceEnumConstantTest,
+   EnumConstantsWithDifferentValues) {
+  auto t =
+  makeNamedDecls("enum e { foo = 1 };", "enum e { foo = 2 };", Lang_C89);
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceEnumConstantTest,
+   EnumConstantsWithDifferentExprsButSameValues) {
+  auto t = makeNamedDecls("enum e { foo = 1 + 1 };", "enum e { foo = 2 };",
+  Lang_CXX11);
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceEnumConstantTest,
+   EnumConstantsWithDifferentSignedness) {
+  auto t = makeNamedDecls("enum e : unsigned { foo = 1 };",
+  "enum e : int { foo = 1 };", Lang_CXX11);
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceEnumConstantTest, EnumConstantsWithDifferentWidth) {
+  auto t = makeNamedDecls("enum e : short { foo = 1 };",
+  "enum e : int { foo = 1 };", Lang_CXX11);
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceEnumConstantTest, EnumConstantsWithDifferentName) {
+  auto t =
+  makeDecls("enum e { foo = 1 };", "enum e { bar = 1 };",
+  Lang_CXX11, enumConstantDecl());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 struct StructuralEquivalenceTemplateTest : StructuralEquivalenceTest {};
 
 TEST_F(StructuralEquivalenceTemplateTest, ExactlySameTemplates) {
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1591,6 +1591,26 @@
   return true;
 }
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext ,
+ EnumConstantDecl *D1,
+ EnumConstantDecl *D2) {
+  const llvm::APSInt  = D1->getInitVal();
+  const llvm::APSInt  = D2->getInitVal();
+  if (FromVal.isSigned() != ToVal.isSigned())
+return false;
+  if (FromVal.getBitWidth() != ToVal.getBitWidth())
+return false;
+  if (FromVal != ToVal)
+return false;
+
+  if (!IsStructurallyEquivalent(D1->getIdentifier(), D2->getIdentifier()))
+return false;
+
+  // Init expressions are the most expensive check, so do them last.
+  return IsStructurallyEquivalent(Context, D1->getInitExpr(),
+  D2->getInitExpr());
+}
+
 /// Determine structural equivalence of two enums.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext ,
  EnumDecl *D1, EnumDecl *D2) {
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -468,7 +468,6 @@
 bool hasSameVisibilityContextAndLinkage(T *Found, T *From);
 
 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true);
-bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC);
 ExpectedDecl VisitDecl(Decl *D);
 ExpectedDecl VisitImportDecl(ImportDecl *D);
 ExpectedDecl VisitEmptyDecl(EmptyDecl *D);
@@ -2182,16 +2181,6 @@
   return Ctx.IsEquivalent(From, To);
 }
 
-bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC,
-EnumConstantDecl *ToEC) {
-  const llvm::APSInt  = FromEC->getInitVal();
-  const llvm::APSInt  = ToEC->getInitVal();
-
-  return FromVal.isSigned() == ToVal.isSigned() &&
- FromVal.getBitWidth() == ToVal.getBitWidth() &&
- FromVal == ToVal;
-}
-
 ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) {
   Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
 << D->getDeclKindName();

[clang] 01b3bd3 - [ASTImporter] Remove ASTNodeImporter::IsStructuralMatch overload for EnumConstantDecl

2021-10-30 Thread Raphael Isemann via cfe-commits

Author: Raphael Isemann
Date: 2021-10-30T13:12:12+02:00
New Revision: 01b3bd3992b4b79ef103558eccc49981e97be479

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

LOG: [ASTImporter] Remove ASTNodeImporter::IsStructuralMatch overload for 
EnumConstantDecl

1. Moves the check to ASTStructuralEquivalence.cpp like all the other checks.

2. Adds the missing checks for identifier and init expression. Also add the
respective tests for that stuff.

Reviewed By: martong

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

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/unittests/AST/StructuralEquivalenceTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 183849c86f01c..8062b4fcab532 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -468,7 +468,6 @@ namespace clang {
 bool hasSameVisibilityContextAndLinkage(T *Found, T *From);
 
 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true);
-bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC);
 ExpectedDecl VisitDecl(Decl *D);
 ExpectedDecl VisitImportDecl(ImportDecl *D);
 ExpectedDecl VisitEmptyDecl(EmptyDecl *D);
@@ -2182,16 +2181,6 @@ bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl 
*To, bool Complain) {
   return Ctx.IsEquivalent(From, To);
 }
 
-bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC,
-EnumConstantDecl *ToEC) {
-  const llvm::APSInt  = FromEC->getInitVal();
-  const llvm::APSInt  = ToEC->getInitVal();
-
-  return FromVal.isSigned() == ToVal.isSigned() &&
- FromVal.getBitWidth() == ToVal.getBitWidth() &&
- FromVal == ToVal;
-}
-
 ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) {
   Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
 << D->getDeclKindName();

diff  --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index c4ff05ba9325d..e85feb779190f 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1591,6 +1591,26 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
   return true;
 }
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext ,
+ EnumConstantDecl *D1,
+ EnumConstantDecl *D2) {
+  const llvm::APSInt  = D1->getInitVal();
+  const llvm::APSInt  = D2->getInitVal();
+  if (FromVal.isSigned() != ToVal.isSigned())
+return false;
+  if (FromVal.getBitWidth() != ToVal.getBitWidth())
+return false;
+  if (FromVal != ToVal)
+return false;
+
+  if (!IsStructurallyEquivalent(D1->getIdentifier(), D2->getIdentifier()))
+return false;
+
+  // Init expressions are the most expensive check, so do them last.
+  return IsStructurallyEquivalent(Context, D1->getInitExpr(),
+  D2->getInitExpr());
+}
+
 /// Determine structural equivalence of two enums.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext ,
  EnumDecl *D1, EnumDecl *D2) {

diff  --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index d416e9d301274..9ae0da8b9dd2c 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -956,6 +956,48 @@ TEST_F(StructuralEquivalenceEnumTest, 
EnumsWithDifferentBody) {
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+struct StructuralEquivalenceEnumConstantTest : StructuralEquivalenceTest {};
+
+TEST_F(StructuralEquivalenceEnumConstantTest, EnumConstantsWithSameValues) {
+  auto t = makeNamedDecls("enum foo { foo = 1 };", "enum foo { foo = 1 };",
+  Lang_C89);
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceEnumConstantTest,
+   EnumConstantsWithDifferentValues) {
+  auto t =
+  makeNamedDecls("enum e { foo = 1 };", "enum e { foo = 2 };", Lang_C89);
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceEnumConstantTest,
+   EnumConstantsWithDifferentExprsButSameValues) {
+  auto t = makeNamedDecls("enum e { foo = 1 + 1 };", "enum e { foo = 2 };",
+  Lang_CXX11);
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceEnumConstantTest,
+   EnumConstantsWithDifferentSignedness) {
+  auto t = makeNamedDecls("enum e : unsigned { foo = 1 };",
+  "enum e : int { foo = 1 };", Lang_CXX11);
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+

[PATCH] D112864: [clang-tidy] Fix lint warnings in clang-tidy source code (NFC)

2021-10-30 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

Looks great, thanks for fixing! I'm surprised we don't have a CI bot running 
these checks post-merge?

Since this is my first review it's probably good to wait for other reviewers 
before merging in case I missed something.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112864

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


[PATCH] D90996: [clang-format] Add --staged/--cached option to git-clang-format

2021-10-30 Thread Erik Larsson via Phabricator via cfe-commits
ortogonal added a comment.

@MyDeveloperDay Is everything okay with this? Can you help out with the next 
step in the process?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90996

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