aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/JSONNodeDumper.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-08-24Revert "[clang] - Add missing builtin name to AtomicExpr JSON dump"Douglas Yung1-4/+0
This reverts commit dbccf3c6f13d2afeecec77136460c5e359164eae. The test added is failing on many bots including: - https://lab.llvm.org/buildbot/#/builders/164/builds/42716 - https://lab.llvm.org/buildbot/#/builders/188/builds/34429 - https://lab.llvm.org/buildbot/#/builders/245/builds/13103 - https://lab.llvm.org/buildbot/#/builders/258/builds/6002 - https://lab.llvm.org/buildbot/#/builders/230/builds/17690 - https://lab.llvm.org/buildbot/#/builders/91/builds/17722 - https://lab.llvm.org/buildbot/#/builders/67/builds/12466 - https://lab.llvm.org/buildbot/#/builders/109/builds/72108 - https://lab.llvm.org/buildbot/#/builders/139/builds/48265 - https://lab.llvm.org/buildbot/#/builders/216/builds/26208 - https://lab.llvm.org/buildbot/#/builders/36/builds/36964 - https://lab.llvm.org/buildbot/#/builders/247/builds/8222
2023-08-24[clang] - Add missing builtin name to AtomicExpr JSON dumpserge-sans-paille1-0/+4
As a side effect, introduce AtomicExpr::getOpAsString() to dump the AtomicOp string representation. Differential Revision: https://reviews.llvm.org/D158558
2023-08-15[clang] Add missing field to TLSModelAttr json AST dumpserge-sans-paille1-0/+4
Recommit with test case updated. Differential Revision: https://reviews.llvm.org/D157814
2023-08-15[clang] Add missing field to VisibilityAttr json AST dumpserge-sans-paille1-0/+5
Recommit with test file updated. Differential Revision: https://reviews.llvm.org/D157808
2023-08-14Revert "[clang] Add missing field to VisibilityAttr json AST dump"Douglas Yung1-5/+0
This reverts commit 2107d87c5a9103ffc4c0f76fc00ab203603f9df1. Change is causing test failures on many bots: - https://lab.llvm.org/buildbot/#/builders/164/builds/42180 - https://lab.llvm.org/buildbot/#/builders/188/builds/33880 - https://lab.llvm.org/buildbot/#/builders/245/builds/12558 - https://lab.llvm.org/buildbot/#/builders/258/builds/5404 - https://lab.llvm.org/buildbot/#/builders/249/builds/8049 - https://lab.llvm.org/buildbot/#/builders/230/builds/17170 - https://lab.llvm.org/buildbot/#/builders/91/builds/17108 - https://lab.llvm.org/buildbot/#/builders/109/builds/71264 - https://lab.llvm.org/buildbot/#/builders/139/builds/47461 - https://lab.llvm.org/buildbot/#/builders/216/builds/25598 - https://lab.llvm.org/buildbot/#/builders/36/builds/36549 - https://lab.llvm.org/buildbot/#/builders/247/builds/7747
2023-08-14Revert "[clang] Add missing field to TLSModelAttr json AST dump"Douglas Yung1-4/+0
This reverts commit 2105c32b32bf3360f524f1f3a1e5af605821eff8. Reverting this follow-up commit as a prior commit (2107d87) is causing build bot test failures.
2023-08-14[clang] Add missing field to TLSModelAttr json AST dumpserge-sans-paille1-0/+4
Differential Revision: https://reviews.llvm.org/D157814
2023-08-14[clang] Add missing field to VisibilityAttr json AST dumpserge-sans-paille1-0/+5
Differential Revision: https://reviews.llvm.org/D157808
2023-08-14[clang] Add missing field to SectionAttr json AST dumpserge-sans-paille1-0/+4
Differential Revision: https://reviews.llvm.org/D157795
2023-08-14[clang] Add missing fields to DeprecatedAttr and Unavailable json AST dumpserge-sans-paille1-0/+12
Differential Revision: https://reviews.llvm.org/D157783
2023-08-14[clang] Add cleanup_function field to CleanupAttr json AST dumpserge-sans-paille1-0/+4
Differential Revision: https://reviews.llvm.org/D157781
2023-08-14[clang] Add aliasee field to AliasAttr json AST dumpserge-sans-paille1-0/+4
Differential Revision: https://reviews.llvm.org/D157775
2023-06-25[llvm] Add missing StringExtras.h includesElliot Goodrich1-0/+1
In preparation for removing the `#include "llvm/ADT/StringExtras.h"` from the header to source file of `llvm/Support/Error.h`, first add in all the missing includes that were previously included transitively through this header.
2023-06-07[clang] Implement P2564 "consteval must propagate up"Corentin Jabot1-0/+3
Reviewed By: aaron.ballman, #clang-language-wg Differential Revision: https://reviews.llvm.org/D151094
2023-04-28[RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 ↵Craig Topper1-0/+3
arm_sve_vector_bits. This allows the user to set the size of the scalable vector so they can be used in structs and as the type of global variables. This works by representing the type as a fixed vector instead of a scalable vector in IR. Conversions to and from scalable vectors are made where necessary like function arguments/returns and intrinsics. This features has been requested here https://github.com/riscv-non-isa/rvv-intrinsic-doc/issues/176 I know arm_sve_vector_bits is used by the Eigen library so this could be used to port Eigen to RVV. This patch adds a new preprocessor define `__riscv_v_fixed_vlen` that is set when -mrvv_vector_bits is passed on the command line. The code is largely based on the AArch64 code. A lot of code was copy/pasted and then modiied to RVV. There may be some opportunities for sharing. This first patch only supports the LMUL=1 types. Additional changes will be needed to support other LMULs. I have also not supported mask vectors. Differential Revision: https://reviews.llvm.org/D145088
2023-04-06Fix a failed assertion when dumping the AST to JSONAaron Ballman1-0/+6
We were trying to mangle templated names and the Microsoft mangler does not have an implementation for mangling dependent names. Instead, we now skip trying to print the mangled name if the AST node is still a templated node rather than a fully resolved node. Fixes https://github.com/llvm/llvm-project/issues/61440
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-1/+1
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-12[clang] Reland parenthesized aggregate init patchesAlan Zhao1-0/+3
This commit relands the patches for implementing P0960R3 and P1975R0, which describe initializing aggregates via a parenthesized list. The relanded commits are: * 40c52159d3ee - P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values * c77a91bb7ba7 - Remove overly restrictive aggregate paren init logic * 32d7aae04fdb - Fix a clang crash on invalid code in C++20 mode This patch also fixes a crash in the original implementation. Previously, if the input tried to call an implicitly deleted copy or move constructor of a union, we would then try to initialize the union by initializing it's first element with a reference to a union. This behavior is incorrect (we should fail to initialize) and if the type of the first element has a constructor with a single template typename parameter, then Clang will explode. This patch fixes that issue by checking that constructor overload resolution did not result in a deleted function before attempting parenthesized aggregate initialization. Additionally, this patch also includes D140159, which contains some minor fixes made in response to code review comments in the original implementation that were made after that patch was submitted. Co-authored-by: Sheng <ox59616e@gmail.com> Fixes #54040, Fixes #59675 Reviewed By: ilya-biryukov Differential Revision: https://reviews.llvm.org/D141546
2023-01-04[clang] Revert parentesized aggregate initalization patchesAlan Zhao1-3/+0
This feature causes clang to crash when compiling Chrome - see https://crbug.com/1405031 and https://github.com/llvm/llvm-project/issues/59675 Revert "[clang] Fix a clang crash on invalid code in C++20 mode." This reverts commit 32d7aae04fdb58e65a952f281ff2f2c3f396d98f. Revert "[clang] Remove overly restrictive aggregate paren init logic" This reverts commit c77a91bb7ba793ec3a6a5da3743ed55056291658. Revert "[clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values" This reverts commit 40c52159d3ee337dbed14e4c73b5616ea354c337.
2022-12-14[clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a ↵Alan Zhao1-0/+3
parenthesized list of values This patch implements P0960R3, which allows initialization of aggregates via parentheses. As an example: ``` struct S { int i, j; }; S s1(1, 1); int arr1[2](1, 2); ``` This patch also implements P1975R0, which fixes the wording of P0960R3 for single-argument parenthesized lists so that statements like the following are allowed: ``` S s2(1); S s3 = static_cast<S>(1); S s4 = (S)1; int (&&arr2)[] = static_cast<int[]>(1); int (&&arr3)[2] = static_cast<int[2]>(1); ``` This patch was originally authored by @0x59616e and completed by @ayzhao. Fixes #54040, Fixes #54041 Co-authored-by: Sheng <ox59616e@gmail.com> Full write up : https://discourse.llvm.org/t/c-20-rfc-suggestion-desired-regarding-the-implementation-of-p0960r3/63744 Reviewed By: ilya-biryukov Differential Revision: https://reviews.llvm.org/D129531
2022-11-24[clang] Add [is|set]Nested methods to NamespaceDeclNathan James1-0/+1
Adds support for NamespaceDecl to inform if its part of a nested namespace. This flag only corresponds to the inner namespaces in a nested namespace declaration. In this example: namespace <X>::<Y>::<Z> {} Only <Y> and <Z> will be classified as nested. This flag isn't meant for assisting in building the AST, more for static analysis and refactorings. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D90568
2022-10-15[clang] Track the templated entity in type substitution.Matheus Izvekov1-0/+6
This is a change to how we represent type subsitution in the AST. Instead of only storing the replaced type, we track the templated entity we are substituting, plus an index. We modify MLTAL to track the templated entity at each level. Otherwise, it's much more expensive to go from the template parameter back to the templated entity, and not possible to do in some cases, as when we instantiate outer templates, parameters might still reference the original entity. This also allows us to very cheaply lookup the templated entity we saw in the naming context and find the corresponding argument it was replaced from, such as for implementing template specialization resugaring. Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D131858
2022-10-03[clang] Implement divergence for TypedefType and UsingTypeMatheus Izvekov1-0/+8
With this patch, TypedefTypes and UsingTypes can have an underlying type which diverges from their corresponding declarations. For the TypedefType case, this can be seen when getting the common sugared type between two redeclarations with different sugar. For both cases, this will become important as resugaring is implemented, as this will allow us to resugar these when they were dependent before instantiation. Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D133468
2022-09-21[HLSL] Support cbuffer/tbuffer for hlsl.Xiang Li1-0/+5
This is first part for support cbuffer/tbuffer. The format for cbuffer/tbuffer is BufferType [Name] [: register(b#)] { VariableDeclaration [: packoffset(c#.xyzw)]; ... }; More details at https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-constants New keyword 'cbuffer' and 'tbuffer' are added. New AST node HLSLBufferDecl is added. Build AST for simple cbuffer/tbuffer without attribute support. The special thing is variables declared inside cbuffer is exposed into global scope. So isTransparentContext should return true for HLSLBuffer. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D129883
2022-09-18[clang] Don't include StringSwitch.h (NFC)Kazu Hirata1-1/+0
These files don't seem to use StringSwitch.
2022-09-17[clang] Fix AST representation of expanded template arguments.Matheus Izvekov1-0/+6
Extend clang's SubstTemplateTypeParm to represent the pack substitution index. Fixes PR56099. Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D128113
2022-08-26Revert "Clang: fix AST representation of expanded template arguments."Matheus Izvekov1-6/+0
This reverts commit 1d1a56929b725f9a79d98877f12d0a14f8418b38.
2022-08-22[clang] adds unary type transformations as compiler built-insChristopher Di Bella1-2/+5
Adds * `__add_lvalue_reference` * `__add_pointer` * `__add_rvalue_reference` * `__decay` * `__make_signed` * `__make_unsigned` * `__remove_all_extents` * `__remove_extent` * `__remove_const` * `__remove_volatile` * `__remove_cv` * `__remove_pointer` * `__remove_reference` * `__remove_cvref` These are all compiler built-in equivalents of the unary type traits found in [[meta.trans]][1]. The compiler already has all of the information it needs to answer these transformations, so we can skip needing to make partial specialisations in standard library implementations (we already do this for a lot of the query traits). This will hopefully improve compile times, as we won't need use as much memory in such a base part of the standard library. [1]: http://wg21.link/meta.trans Co-authored-by: zoecarver Reviewed By: aaron.ballman, rsmith Differential Revision: https://reviews.llvm.org/D116203
2022-08-14Revert "[clang] adds unary type transformations as compiler built-ins"Nico Weber1-5/+2
This reverts commit bc60cf2368de90918719dc7e3d7c63a72cc007ad. Doesn't build on Windows and breaks gcc 9 build, see https://reviews.llvm.org/D116203#3722094 and https://reviews.llvm.org/D116203#3722128 Also revert two follow-ups. One fixed a warning added in bc60cf2368de90918719dc7e3d7c63a72cc007ad, the other makes use of the feature added in bc60cf2368de90918719dc7e3d7c63a72cc007ad in libc++: Revert "[libcxx][NFC] utilises compiler builtins for unary transform type-traits" This reverts commit 06a1d917ef1f507aaa2f6891bb654696c866ea3a. Revert "[Sema] Fix a warning" This reverts commit c85abbe879ef3257de4db862ce249b060cc3d2a4.
2022-08-14[clang] adds unary type transformations as compiler built-insChristopher Di Bella1-2/+5
Adds * `__add_lvalue_reference` * `__add_pointer` * `__add_rvalue_reference` * `__decay` * `__make_signed` * `__make_unsigned` * `__remove_all_extents` * `__remove_extent` * `__remove_const` * `__remove_volatile` * `__remove_cv` * `__remove_pointer` * `__remove_reference` * `__remove_cvref` These are all compiler built-in equivalents of the unary type traits found in [[meta.trans]][1]. The compiler already has all of the information it needs to answer these transformations, so we can skip needing to make partial specialisations in standard library implementations (we already do this for a lot of the query traits). This will hopefully improve compile times, as we won't need use as much memory in such a base part of the standard library. [1]: http://wg21.link/meta.trans Co-authored-by: zoecarver Reviewed By: aaron.ballman, rsmith Differential Revision: https://reviews.llvm.org/D116203
2022-08-09Clang: fix AST representation of expanded template arguments.Matheus Izvekov1-0/+6
Extend clang's SubstTemplateTypeParm to represent the pack substitution index. Fixes PR56099. Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D128113
2022-07-03[FPEnv] Allow CompoundStmt to keep FP optionsSerge Pavlov1-0/+15
This is a recommit of b822efc7404bf09ccfdc1ab7657475026966c3b2, reverted in dc34d8df4c48b3a8f474360970cae8a58e6c84f0. The commit caused fails because the test ast-print-fp-pragmas.c did not specify particular target, and it failed on targets which do not support constrained intrinsics. The original commit message is below. AST does not have special nodes for pragmas. Instead a pragma modifies some state variables of Sema, which in turn results in modified attributes of AST nodes. This technique applies to floating point operations as well. Every AST node that can depend on FP options keeps current set of them. This technique works well for options like exception behavior or fast math options. They represent instructions to the compiler how to modify code generation for the affected nodes. However treatment of FP control modes has problems with this technique. Modifying FP control mode (like rounding direction) usually requires operations on hardware, like writing to control registers. It must be done prior to the first operation that depends on the control mode. In particular, such operations are required for implementation of `pragma STDC FENV_ROUND`, compiler should set up necessary rounding direction at the beginning of compound statement where the pragma occurs. As there is no representation for pragmas in AST, the code generation becomes a complicated task in this case. To solve this issue FP options are kept inside CompoundStmt. Unlike to FP options in expressions, these does not affect any operation on FP values, but only inform the codegen about the FP options that act in the body of the statement. As all pragmas that modify FP environment may occurs only at the start of compound statement or at global level, such solution works for all relevant pragmas. The options are kept as a difference from the options in the enclosing compound statement or default options, it helps codegen to set only changed control modes. Differential Revision: https://reviews.llvm.org/D123952
2022-07-01Revert "[FPEnv] Allow CompoundStmt to keep FP options"Serge Pavlov1-15/+0
On some buildbots test `ast-print-fp-pragmas.c` fails, need to investigate it. This reverts commit 0401fd12d4aa0553347fe34d666fb236d8719173. This reverts commit b822efc7404bf09ccfdc1ab7657475026966c3b2.
2022-07-01[FPEnv] Allow CompoundStmt to keep FP optionsSerge Pavlov1-0/+15
AST does not have special nodes for pragmas. Instead a pragma modifies some state variables of Sema, which in turn results in modified attributes of AST nodes. This technique applies to floating point operations as well. Every AST node that can depend on FP options keeps current set of them. This technique works well for options like exception behavior or fast math options. They represent instructions to the compiler how to modify code generation for the affected nodes. However treatment of FP control modes has problems with this technique. Modifying FP control mode (like rounding direction) usually requires operations on hardware, like writing to control registers. It must be done prior to the first operation that depends on the control mode. In particular, such operations are required for implementation of `pragma STDC FENV_ROUND`, compiler should set up necessary rounding direction at the beginning of compound statement where the pragma occurs. As there is no representation for pragmas in AST, the code generation becomes a complicated task in this case. To solve this issue FP options are kept inside CompoundStmt. Unlike to FP options in expressions, these does not affect any operation on FP values, but only inform the codegen about the FP options that act in the body of the statement. As all pragmas that modify FP environment may occurs only at the start of compound statement or at global level, such solution works for all relevant pragmas. The options are kept as a difference from the options in the enclosing compound statement or default options, it helps codegen to set only changed control modes. Differential Revision: https://reviews.llvm.org/D123952
2021-12-23[JSONNodeDumper] Do not print mangled names for local variables (PR49111)Nikita Popov1-5/+12
Mangled names are not meaningful for variables with local storage, and may not be well defined (getting the mangled name for VLA crashes the mangler). As such, do not include them in the JSON dump. This allows running update_cc_test_checks on some OpenMP tests again. Fixes https://github.com/llvm/llvm-project/issues/49111. Differential Revision: https://reviews.llvm.org/D116169
2021-10-05Implement if consteval (P1938)Corentin Jabot1-0/+2
Modify the IfStmt node to suppoort constant evaluated expressions. Add a new ExpressionEvaluationContext::ImmediateFunctionContext to keep track of immediate function contexts. This proved easier/better/probably more efficient than walking the AST backward as it allows diagnosing nested if consteval statements.
2021-06-30Add dumping support for RequiresExpr.Richard Smith1-3/+41
In passing, fix an ast-print bug that inserted a spurious extra `;` after a concept definition.
2021-06-09[clang] NFC: Rename rvalue to prvalueMatheus Izvekov1-1/+3
This renames the expression value categories from rvalue to prvalue, keeping nomenclature consistent with C++11 onwards. C++ has the most complicated taxonomy here, and every other language only uses a subset of it, so it's less confusing to use the C++ names consistently, and mentally remap to the C names when working on that context (prvalue -> rvalue, no xvalues, etc). Renames: * VK_RValue -> VK_PRValue * Expr::isRValue -> Expr::isPRValue * SK_QualificationConversionRValue -> SK_QualificationConversionPRValue * JSON AST Dumper Expression nodes value category: "rvalue" -> "prvalue" Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D103720
2021-06-09JSONNodeDumper.cpp - VisitIntegerLiteral - avoid APSInt::toString ↵Simon Pilgrim1-3/+4
std::string wrapper. NFCI Pulled out of D103888 - use the underlying SmallString version directly
2021-06-08[clang] p1099 using enum part 2Nathan Sidwell1-0/+4
This implements the 'using enum maybe-qualified-enum-tag ;' part of 1099. It introduces a new 'UsingEnumDecl', subclassed from 'BaseUsingDecl'. Much of the diff is the boilerplate needed to get the new class set up. There is one case where we accept ill-formed, but I believe this is merely an extended case of an existing bug, so consider it orthogonal. AFAICT in class-scope the c++20 rule is that no 2 using decls can bring in the same target decl ([namespace.udecl]/8). But we already accept: struct A { enum { a }; }; struct B : A { using A::a; }; struct C : B { using A::a; using B::a; }; // same enumerator this patch permits mixtures of 'using enum Bob;' and 'using Bob::member;' in the same way. Differential Revision: https://reviews.llvm.org/D102241
2021-05-27Reimplement __builtin_unique_stable_name-Erich Keane1-0/+6
The original version of this was reverted, and @rjmcall provided some advice to architect a new solution. This is that solution. This implements a builtin to provide a unique name that is stable across compilations of this TU for the purposes of implementing the library component of the unnamed kernel feature of SYCL. It does this by running the Itanium mangler with a few modifications. Because it is somewhat common to wrap non-kernel-related lambdas in macros that aren't present on the device (such as for logging), this uniquely generates an ID for all lambdas involved in the naming of a kernel. It uses the lambda-mangling number to do this, except replaces this with its own number (starting at 10000 for readabililty reasons) for lambdas used to name a kernel. Additionally, this implements itself as constexpr with a slight catch: if a name would be invalidated by the use of this lambda in a later kernel invocation, it is diagnosed as an error (see the Sema tests). Differential Revision: https://reviews.llvm.org/D103112
2021-05-17[Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 1Ten Tzen1-0/+1
This patch is the Part-1 (FE Clang) implementation of HW Exception handling. This new feature adds the support of Hardware Exception for Microsoft Windows SEH (Structured Exception Handling). This is the first step of this project; only X86_64 target is enabled in this patch. Compiler options: For clang-cl.exe, the option is -EHa, the same as MSVC. For clang.exe, the extra option is -fasync-exceptions, plus -triple x86_64-windows -fexceptions and -fcxx-exceptions as usual. NOTE:: Without the -EHa or -fasync-exceptions, this patch is a NO-DIFF change. The rules for C code: For C-code, one way (MSVC approach) to achieve SEH -EHa semantic is to follow three rules: * First, no exception can move in or out of _try region., i.e., no "potential faulty instruction can be moved across _try boundary. * Second, the order of exceptions for instructions 'directly' under a _try must be preserved (not applied to those in callees). * Finally, global states (local/global/heap variables) that can be read outside of _try region must be updated in memory (not just in register) before the subsequent exception occurs. The impact to C++ code: Although SEH is a feature for C code, -EHa does have a profound effect on C++ side. When a C++ function (in the same compilation unit with option -EHa ) is called by a SEH C function, a hardware exception occurs in C++ code can also be handled properly by an upstream SEH _try-handler or a C++ catch(...). As such, when that happens in the middle of an object's life scope, the dtor must be invoked the same way as C++ Synchronous Exception during unwinding process. Design: A natural way to achieve the rules above in LLVM today is to allow an EH edge added on memory/computation instruction (previous iload/istore idea) so that exception path is modeled in Flow graph preciously. However, tracking every single memory instruction and potential faulty instruction can create many Invokes, complicate flow graph and possibly result in negative performance impact for downstream optimization and code generation. Making all optimizations be aware of the new semantic is also substantial. This design does not intend to model exception path at instruction level. Instead, the proposed design tracks and reports EH state at BLOCK-level to reduce the complexity of flow graph and minimize the performance-impact on CPP code under -EHa option. One key element of this design is the ability to compute State number at block-level. Our algorithm is based on the following rationales: A _try scope is always a SEME (Single Entry Multiple Exits) region as jumping into a _try is not allowed. The single entry must start with a seh_try_begin() invoke with a correct State number that is the initial state of the SEME. Through control-flow, state number is propagated into all blocks. Side exits marked by seh_try_end() will unwind to parent state based on existing SEHUnwindMap[]. Note side exits can ONLY jump into parent scopes (lower state number). Thus, when a block succeeds various states from its predecessors, the lowest State triumphs others. If some exits flow to unreachable, propagation on those paths terminate, not affecting remaining blocks. For CPP code, object lifetime region is usually a SEME as SEH _try. However there is one rare exception: jumping into a lifetime that has Dtor but has no Ctor is warned, but allowed: Warning: jump bypasses variable with a non-trivial destructor In that case, the region is actually a MEME (multiple entry multiple exits). Our solution is to inject a eha_scope_begin() invoke in the side entry block to ensure a correct State. Implementation: Part-1: Clang implementation described below. Two intrinsic are created to track CPP object scopes; eha_scope_begin() and eha_scope_end(). _scope_begin() is immediately added after ctor() is called and EHStack is pushed. So it must be an invoke, not a call. With that it's also guaranteed an EH-cleanup-pad is created regardless whether there exists a call in this scope. _scope_end is added before dtor(). These two intrinsics make the computation of Block-State possible in downstream code gen pass, even in the presence of ctor/dtor inlining. Two intrinsic, seh_try_begin() and seh_try_end(), are added for C-code to mark _try boundary and to prevent from exceptions being moved across _try boundary. All memory instructions inside a _try are considered as 'volatile' to assure 2nd and 3rd rules for C-code above. This is a little sub-optimized. But it's acceptable as the amount of code directly under _try is very small. Part-2 (will be in Part-2 patch): LLVM implementation described below. For both C++ & C-code, the state of each block is computed at the same place in BE (WinEHPreparing pass) where all other EH tables/maps are calculated. In addition to _scope_begin & _scope_end, the computation of block state also rely on the existing State tracking code (UnwindMap and InvokeStateMap). For both C++ & C-code, the state of each block with potential trap instruction is marked and reported in DAG Instruction Selection pass, the same place where the state for -EHsc (synchronous exceptions) is done. If the first instruction in a reported block scope can trap, a Nop is injected before this instruction. This nop is needed to accommodate LLVM Windows EH implementation, in which the address in IPToState table is offset by +1. (note the purpose of that is to ensure the return address of a call is in the same scope as the call address. The handler for catch(...) for -EHa must handle HW exception. So it is 'adjective' flag is reset (it cannot be IsStdDotDot (0x40) that only catches C++ exceptions). Suppress push/popTerminate() scope (from noexcept/noTHrow) so that HW exceptions can be passed through. Original llvm-dev [RFC] discussions can be found in these two threads below: https://lists.llvm.org/pipermail/llvm-dev/2020-March/140541.html https://lists.llvm.org/pipermail/llvm-dev/2020-April/141338.html Differential Revision: https://reviews.llvm.org/D80344/new/
2021-04-24Fix null ptr crash dumping TemplateTemplateParmDeclDavid Tolnay1-2/+3
The following program winds up with D->getDefaultArgStorage().getInheritedFrom() == nullptr during dumping the TemplateTemplateParmDecl corresponding to the template parameter of i. template <typename> struct R; template <template <typename> class = R> void i(); This patch fixes the null pointer dereference.
2021-01-04Revert "[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped ↵Thorsten Schütt1-2/+2
enum (II)" This reverts commit efc82c4ad2bcb256a4f4c20238d08cd3afba4d2d.
2021-01-04[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)Thorsten Schütt1-2/+2
Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D93765
2020-11-17[clang][NFC] Use SmallString instead of SmallVector<charNathan James1-1/+1
Simplifies code in some places and is more explicit about what is being used. No additional includes were added here so no impact on compile time.
2020-08-27[Sema][AArch64] Support arm_sve_vector_bits attributeCullen Rhodes1-0/+6
This patch implements the semantics for the 'arm_sve_vector_bits' type attribute, defined by the Arm C Language Extensions (ACLE) for SVE [1]. The purpose of this attribute is to define vector-length-specific (VLS) versions of existing vector-length-agnostic (VLA) types. The semantics were already implemented by D83551, although the implementation approach has since changed to represent VLSTs as VectorType in the AST and fixed-length vectors in the IR everywhere except in function args/returns. This is described in the prototype patch D85128 demonstrating the new approach. The semantic changes added in D83551 are changed since the AttributedType is replaced by VectorType in the AST. Minimal changes were necessary in the previous patch as the canonical type for both VLA and VLS was the same (i.e. sizeless), except in constructs such as globals and structs where sizeless types are unsupported. This patch reverts the changes that permitted VLS types that were represented as sizeless types in such circumstances, and adds support for implicit casting between VLA <-> VLS types as described in section 3.7.3.2 of the ACLE. Since the SVE builtin types for bool and uint8 are both represented as BuiltinType::UChar in VLSTs, two new vector kinds are implemented to distinguish predicate and data vectors. [1] https://developer.arm.com/documentation/100987/latest Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D85736
2020-07-06[clang] Rework how and when APValues are dumpedBruno Ricci1-6/+9
Currently APValues are dumped as a single string. This becomes quickly completely unreadable since APValue is a tree-like structure. Even a simple example is not pretty: struct S { int arr[4]; float f; }; constexpr S s = { .arr = {1,2}, .f = 3.1415f }; // Struct fields: Array: Int: 1, Int: 2, 2 x Int: 0, Float: 3.141500e+00 With this patch this becomes: -Struct |-field: Array size=4 | |-elements: Int 1, Int 2 | `-filler: 2 x Int 0 `-field: Float 3.141500e+00 Additionally APValues are currently only dumped as part of visiting a ConstantExpr. This patch also dump the value of the initializer of constexpr variable declarations: constexpr int foo(int a, int b) { return a + b - 42; } constexpr int a = 1, b = 2; constexpr int c = foo(a, b) > 0 ? foo(a, b) : foo(b, a); // VarDecl 0x62100008aec8 <col:3, col:57> col:17 c 'const int' constexpr cinit // |-value: Int -39 // `-ConditionalOperator 0x62100008b4d0 <col:21, col:57> 'int' // <snip> Do the above by moving the dump functions to TextNodeDumper which already has the machinery to display trees. The cases APValue::LValue, APValue::MemberPointer and APValue::AddrLabelDiff are left as they were before (unimplemented). We try to display multiple elements on the same line if they are considered to be "simple". This is to avoid wasting large amounts of vertical space in an example like: constexpr int arr[8] = {0,1,2,3,4,5,6,7}; // VarDecl 0x62100008bb78 <col:3, col:42> col:17 arr 'int const[8]' constexpr cinit // |-value: Array size=8 // | |-elements: Int 0, Int 1, Int 2, Int 3 // | `-elements: Int 4, Int 5, Int 6, Int 7 Differential Revision: https://reviews.llvm.org/D83183 Reviewed By: aaron.ballman
2020-06-19[AST] Dump containsErrors bit for the Type.Haojian Wu1-0/+1
Reviewers: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D81912