aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-12-06Introduce _BitInt, deprecate _ExtIntAaron Ballman1-2/+2
WG14 adopted the _ExtInt feature from Clang for C23, but renamed the type to be _BitInt. This patch does the vast majority of the work to rename _ExtInt to _BitInt, which accounts for most of its size. The new type is exposed in older C modes and all C++ modes as a conforming extension. However, there are functional changes worth calling out: * Deprecates _ExtInt with a fix-it to help users migrate to _BitInt. * Updates the mangling for the type. * Updates the documentation and adds a release note to warn users what is going on. * Adds new diagnostics for use of _BitInt to call out when it's used as a Clang extension or as a pre-C23 compatibility concern. * Adds new tests for the new diagnostic behaviors. I want to call out the ABI break specifically. We do not believe that this break will cause a significant imposition for early adopters of the feature, and so this is being done as a full break. If it turns out there are critical uses where recompilation is not an option for some reason, we can consider using ABI tags to ease the transition.
2021-11-10[CFE][Codegen] Make sure to maintain the contiguity of all the static allocashsmahesha1-0/+8
at the start of the entry block, which in turn would aid better code transformation/optimization. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D110257
2021-11-02Fix inline builtin handling in case of redefinitionserge-sans-paille1-11/+33
Basically, inline builtin definition are shadowed by externally visible redefinition. This matches GCC behavior. The implementation has to workaround the fact that: 1. inline builtin are renamed at callsite during codegen, but 2. they may be shadowed by a later external definition As a consequence, during codegen, we need to walk redecls and eventually rewrite some call sites, which is totally inelegant. Differential Revision: https://reviews.llvm.org/D112059
2021-10-21[clang] Use StringRef::contains (NFC)Kazu Hirata1-2/+1
2021-10-09[CFE][Codegen][In-progress] Remove CodeGenFunction::InitTempAlloca()hsmahesha1-1/+2
CodeGenFunction::InitTempAlloca() inits the static alloca within the entry block which may *not* necessarily be correct always. For example, the current instruction insertion point (pointed by the instruction builder) could be a program point which is hit multiple times during the program execution, and it is expected that the static alloca is initialized every time the program point is hit. Hence remove CodeGenFunction::InitTempAlloca(), and initialize the static alloca where the instruction insertion point is at the moment. This patch, as a starting attempt, removes the calls to CodeGenFunction::InitTempAlloca() which do not have any side effect on the lit tests. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D111293
2021-10-04Update inline builtin handling to honor gnu inline attributeserge-sans-paille1-4/+17
Per the GCC info page: If the function is declared 'extern', then this definition of the function is used only for inlining. In no case is the function compiled as a standalone function, not even if you take its address explicitly. Such an address becomes an external reference, as if you had only declared the function, and had not defined it. Respect that behavior for inline builtins: keep the original definition, and generate a copy of the declaration suffixed by '.inline' that's only referenced in direct call. This fixes holes in c3717b6858d32d64514a187ede1a77be8ba4e542. Differential Revision: https://reviews.llvm.org/D111009
2021-09-28Simplify handling of builtin with inline redefinitionserge-sans-paille1-0/+5
(This is a recommit of 3d6f49a56995b845 that should no longer break validation since bd379915de38a9af3d65e1). It is a common practice in glibc header to provide an inline redefinition of an existing function. It is especially the case for fortified function. Clang currently has an imperfect approach to the problem, using a combination of trivially recursive function detection and noinline attribute. Simplify the logic by suffixing these functions by `.inline` during codegen, so that they are not recognized as builtin by llvm. After that patch, clang passes all tests from https://github.com/serge-sans-paille/fortify-test-suite Differential Revision: https://reviews.llvm.org/D109967
2021-09-28Revert "Simplify handling of builtin with inline redefinition"Kevin Athey1-5/+0
This reverts commit 3d6f49a56995b845c40be5827ded5d1e3f692cec. Broke bot: https://lab.llvm.org/buildbot/#/builders/5/builds/12360
2021-09-28DebugInfo: Use sugared function type when emitting function declarations for ↵David Blaikie1-10/+3
call sites Otherwise we're losing type information for these functions.
2021-09-28Simplify handling of builtin with inline redefinitionserge-sans-paille1-0/+5
It is a common practice in glibc header to provide an inline redefinition of an existing function. It is especially the case for fortified function. Clang currently has an imperfect approach to the problem, using a combination of trivially recursive function detection and noinline attribute. Simplify the logic by suffixing these functions by `.inline` during codegen, so that they are not recognized as builtin by llvm. After that patch, clang passes all tests from https://github.com/serge-sans-paille/fortify-test-suite Differential Revision: https://reviews.llvm.org/D109967
2021-09-01Ensure field-annotations on pointers properly match the AS of the field.Erich Keane1-4/+8
Discovered in SYCL, the field annotations were always cast to an i8*, which is an invalid bitcast for a pointer type with an address space. This patch makes sure that we create an intrinsic that takes a pointer to the correct address-space and properly do our casts. Differential Revision: https://reviews.llvm.org/D109003
2021-08-25[clang] Don't generate warn-stack-size when the warning is ignoredYi Kong1-1/+2
8ace12130526 introduced a regression for code that explicitly ignores the -Wframe-larger-than= warning. Make sure we don't generate the warn-stack-size attribute for that case. Differential Revision: https://reviews.llvm.org/D108686
2021-08-20[clang][Codegen] Introduce the disable_sanitizer_instrumentation attributeAlexander Potapenko1-0/+9
The purpose of __attribute__((disable_sanitizer_instrumentation)) is to prevent all kinds of sanitizer instrumentation applied to a certain function, Objective-C method, or global variable. The no_sanitize(...) attribute drops instrumentation checks, but may still insert code preventing false positive reports. In some cases though (e.g. when building Linux kernel with -fsanitize=kernel-memory or -fsanitize=thread) the users may want to avoid any kind of instrumentation. Differential Revision: https://reviews.llvm.org/D108029
2021-08-17[SVE] Remove usage of getMaxVScale for AArch64, in favour of IR AttributeDylan Fleming1-5/+7
Removed AArch64 usage of the getMaxVScale interface, replacing it with the vscale_range(min, max) IR Attribute. Reviewed By: paulwalker-arm Differential Revision: https://reviews.llvm.org/D106277
2021-07-29[clang][patch][FPEnv] Make initialization of C++ globals strictfp awareMelanie Blower1-16/+10
@kpn pointed out that the global variable initialization functions didn't have the "strictfp" metadata set correctly, and @rjmccall said that there was buggy code in SetFPModel and StartFunction, this patch is to solve those problems. When Sema creates a FunctionDecl, it sets the FunctionDeclBits.UsesFPIntrin to "true" if the lexical FP settings (i.e. a combination of command line options and #pragma float_control settings) correspond to ConstrainedFP mode. That bit is used when CodeGen starts codegen for a llvm function, and it translates into the "strictfp" function attribute. See bugs.llvm.org/show_bug.cgi?id=44571 Reviewed By: Aaron Ballman Differential Revision: https://reviews.llvm.org/D102343
2021-07-20[clang][patch][NFC] Refactor calculation of FunctionDecl to avoid duplicate codeMelanie Blower1-40/+31
2021-07-08[CodeGen] Avoid CreateGEP with nullptr type (NFC)Nikita Popov1-1/+2
In preparation for dropping support for it. I've replaced it with a proper type where the correct type was obvious and left an explicit getPointerElementType() where it wasn't.
2021-06-29PR50767: clear non-distinct debuginfo for function with nodebug definition ↵Bruno De Fraine1-2/+8
after undecorated declaration Fix suggested by Yuanfang Chen: Non-distinct debuginfo is attached to the function due to the undecorated declaration. Later, when seeing the function definition and `nodebug` attribute, the non-distinct debuginfo should be cleared. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D104777
2021-06-21[IR] convert warn-stack-size from module flag to fn attrNick Desaulniers1-0/+4
Otherwise, this causes issues when building with LTO for object files that use different values. Link: https://github.com/ClangBuiltLinux/linux/issues/1395 Reviewed By: dblaikie, MaskRay Differential Revision: https://reviews.llvm.org/D104342
2021-06-18[Clang][Codegen] Add GNU function attribute 'no_profile' and lower it to ↵Nick Desaulniers1-0/+3
noprofile noprofile IR attribute already exists to prevent profiling with PGO; emit that when a function uses the newly added no_profile function attribute. The Linux kernel would like to avoid compiler generated code in functions annotated with such attribute. We already respect this for libcalls to fentry() and mcount(). Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80223 Link: https://lore.kernel.org/lkml/CAKwvOdmPTi93n2L0_yQkrzLdmpxzrOR7zggSzonyaw2PGshApw@mail.gmail.com/ Reviewed By: MaskRay, void, phosek, aaron.ballman Differential Revision: https://reviews.llvm.org/D104475
2021-05-25[SanitizeCoverage] Add support for NoSanitizeCoverage function attributeMarco Elver1-1/+10
We really ought to support no_sanitize("coverage") in line with other sanitizers. This came up again in discussions on the Linux-kernel mailing lists, because we currently do workarounds using objtool to remove coverage instrumentation. Since that support is only on x86, to continue support coverage instrumentation on other architectures, we must support selectively disabling coverage instrumentation via function attributes. Unfortunately, for SanitizeCoverage, it has not been implemented as a sanitizer via fsanitize= and associated options in Sanitizers.def, but rolls its own option fsanitize-coverage. This meant that we never got "automatic" no_sanitize attribute support. Implement no_sanitize attribute support by special-casing the string "coverage" in the NoSanitizeAttr implementation. To keep the feature as unintrusive to existing IR generation as possible, define a new negative function attribute NoSanitizeCoverage to propagate the information through to the instrumentation pass. Fixes: https://bugs.llvm.org/show_bug.cgi?id=49035 Reviewed By: vitalybuka, morehouse Differential Revision: https://reviews.llvm.org/D102772
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-30[clang] Refactor mustprogress handling, add it to all loops in c++11+.Florian Hahn1-4/+1
Currently Clang does not add mustprogress to inifinite loops with a known constant condition, matching C11 behavior. The forward progress guarantee in C++11 and later should allow us to add mustprogress to any loop (http://eel.is/c++draft/intro.progress#1). This allows us to simplify the code dealing with adding mustprogress a bit. Reviewed By: aaron.ballman, lebedev.ri Differential Revision: https://reviews.llvm.org/D96418
2021-04-17Normalize interaction with boolean attributesSerge Guelton1-1/+1
Such attributes can either be unset, or set to "true" or "false" (as string). throughout the codebase, this led to inelegant checks ranging from if (Fn->getFnAttribute("no-jump-tables").getValueAsString() == "true") to if (Fn->hasAttribute("no-jump-tables") && Fn->getFnAttribute("no-jump-tables").getValueAsString() == "true") Introduce a getValueAsBool that normalize the check, with the following behavior: no attributes or attribute set to "false" => return false attribute set to "true" => return true Differential Revision: https://reviews.llvm.org/D99299
2021-04-12[Clang][Coroutine][DebugInfo] In c++ coroutine, clang will emit different ↵yifeng.dongyifeng1-0/+5
debug info variables for parameters and move-parameters. The first one is the real parameters of the coroutine function, the other one just for copying parameters to the coroutine frame. Considering the following c++ code: ``` struct coro { ... }; coro foo(struct test & t) { ... co_await suspend_always(); ... co_await suspend_always(); ... co_await suspend_always(); } int main(int argc, char *argv[]) { auto c = foo(...); c.handle.resume(); ... } ``` Function foo is the standard coroutine function, and it has only one parameter named t (ignoring this at first), when we use the llvm code to compile this function, we can get the following ir: ``` !2921 = distinct !DISubprogram(name: "foo", linkageName: "_ZN6Object3fooE4test", scope: !2211, file: !45, li\ ne: 48, type: !2329, scopeLine: 48, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefi\ nition | DISPFlagOptimized, unit: !44, declaration: !2328, retainedNodes: !2922) !2924 = !DILocalVariable(name: "t", arg: 2, scope: !2921, file: !45, line: 48, type: !838) ... !2926 = !DILocalVariable(name: "t", scope: !2921, type: !838, flags: DIFlagArtificial) ``` We can find there are two `the same` DIVariable named t in the same dwarf scope for foo.resume. And when we try to use llvm-dwarfdump to dump the dwarf info of this elf, we get the following output: ``` 0x00006684: DW_TAG_subprogram DW_AT_low_pc (0x00000000004013a0) DW_AT_high_pc (0x00000000004013a8) DW_AT_frame_base (DW_OP_reg7 RSP) DW_AT_object_pointer (0x0000669c) DW_AT_GNU_all_call_sites (true) DW_AT_specification (0x00005b5c "_ZN6Object3fooE4test") 0x000066a5: DW_TAG_formal_parameter DW_AT_name ("t") DW_AT_decl_file ("/disk1/yifeng.dongyifeng/my_code/llvm/build/bin/coro-debug-1.cpp") DW_AT_decl_line (48) DW_AT_type (0x00004146 "test") 0x000066ba: DW_TAG_variable DW_AT_name ("t") DW_AT_type (0x00004146 "test") DW_AT_artificial (true) ``` The elf also has two 't' in the same scope. But unluckily, it might let the debugger confused. And failed to print parameters for O0 or above. This patch will make coroutine parameters and move parameters use the same DIVar and try to fix the problems that I mentioned before. Test Plan: check-clang Reviewed By: aprantl, jmorse Differential Revision: https://reviews.llvm.org/D97533
2021-04-08Revert "Reduce the number of attributes attached to each function"Dávid Bolvanský1-2/+1
This reverts commit 053dc95839b3b8a36db46f8c419e36e632e989cd. It causes perf regressions - see discussion in D97116.
2021-03-25[Coroutine][Clang] Force emit lifetime intrinsics for CoroutinesXun Li1-4/+10
tl;dr Correct implementation of Corouintes requires having lifetime intrinsics available. Coroutine functions are functions that can be suspended and resumed latter. To do so, data that need to stay alive after suspension must be put on the heap (i.e. the coroutine frame). The optimizer is responsible for analyzing each AllocaInst and figure out whether it should be put on the stack or the frame. In most cases, for data that we are unable to accurately analyze lifetime, we can just conservatively put them on the heap. Unfortunately, there exists a few cases where certain data MUST be put on the stack, not on the heap. Without lifetime intrinsics, we are unable to correctly analyze those data's lifetime. To dig into more details, there exists cases where at certain code points, the current coroutine frame may have already been destroyed. Hence no frame access would be allowed beyond that point. The following is a common code pattern called "Symmetric Transfer" in coroutine: ``` auto tmp = await_suspend(); __builtin_coro_resume(tmp.address()); return; ``` In the above code example, `await_suspend()` returns a new coroutine handle, which we will obtain the address and then resume that coroutine. This essentially "transfered" from the current coroutine to a different coroutine. During the call to `await_suspend()`, the current coroutine may be destroyed, which should be fine because we are not accessing any data afterwards. However when LLVM is emitting IR for the above code, it needs to emit an AllocaInst for `tmp`. It will then call the `address` function on tmp. `address` function is a member function of coroutine, and there is no way for the LLVM optimizer to know that it does not capture the `tmp` pointer. So when the optimizer looks at it, it has to conservatively assume that `tmp` may escape and hence put it on the heap. Furthermore, in some cases `address` call would be inlined, which will generate a bunch of store/load instructions that move the `tmp` pointer around. Those stores will also make the compiler to think that `tmp` might escape. To summarize, it's really difficult for the mid-end to figure out that the `tmp` data is short-lived. I made some attempt in D98638, but it appears to be way too complex and is basically doing the same thing as inserting lifetime intrinsics in coroutines. Also, for reference, we already force emitting lifetime intrinsics in O0 for AlwaysInliner: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Passes/PassBuilder.cpp#L1893 Differential Revision: https://reviews.llvm.org/D99227
2021-03-22[IR] Add vscale_range IR function attributeBradley Smith1-0/+7
This attribute represents the minimum and maximum values vscale can take. For now this attribute is not hooked up to anything during codegen, this will be added in the future when such codegen is considered stable. Additionally hook up the -msve-vector-bits=<x> clang option to emit this attribute. Differential Revision: https://reviews.llvm.org/D98030
2021-03-21[clang][Codegen] EmitBranchOnBoolExpr(): emit prof branch counts even at -O0Roman Lebedev1-19/+19
This restores the original behaviour before i unadvertedly broke it in e3a470162738871bba982416748ae5f5e3572947 and clang/test/Profile/ caught it.
2021-03-21[clang][CodeGen] Lower Likelihood attributes to @llvm.expect intrin instead ↵Roman Lebedev1-45/+44
of branch weights 08196e0b2e1f8aaa8a854585335c17ba479114df exposed LowerExpectIntrinsic's internal implementation detail in the form of LikelyBranchWeight/UnlikelyBranchWeight options to the outside. While this isn't incorrect from the results viewpoint, this is suboptimal from the layering viewpoint, and causes confusion - should transforms also use those weights, or should they use something else, D98898? So go back to status quo by making LikelyBranchWeight/UnlikelyBranchWeight internal again, and fixing all the code that used it directly, which currently is only clang codegen, thankfully, to emit proper @llvm.expect intrinsics instead.
2021-03-21Revert "[BranchProbability] move options for 'likely' and 'unlikely'"Roman Lebedev1-1/+1
Upon reviewing D98898 i've come to realization that these are implementation detail of LowerExpectIntrinsicPass, and they should not be exposed to outside of it. This reverts commit ee8b53815ddf6f6f94ade0068903cd5ae843fafa.
2021-03-20[BranchProbability] move options for 'likely' and 'unlikely'Sanjay Patel1-1/+1
This makes the settings available for use in other passes by housing them within the Support lib, but NFC otherwise. See D98898 for the proposed usage in SimplifyCFG (where this change was originally included). Differential Revision: https://reviews.llvm.org/D98945
2021-03-12[OpaquePtrs] Remove some uses of type-less CreateGEP() (NFC)Nikita Popov1-5/+5
This removes some (but not all) uses of type-less CreateGEP() and CreateInBoundsGEP() APIs, which are incompatible with opaque pointers. There are a still a number of tricky uses left, as well as many more variation APIs for CreateGEP.
2021-03-11[CGBuilder] Remove type-less CreateAlignedLoad() APIs (NFC)Nikita Popov1-1/+3
These are incompatible with opaque pointers. This is in preparation of dropping this API on the IRBuilder side as well. Instead explicitly pass the loaded type.
2021-03-04[clang][OpenMP] Use OpenMPIRBuilder for workshare loops.Michael Kruse1-2/+2
Initial support for using the OpenMPIRBuilder by clang to generate loops using the OpenMPIRBuilder. This initial support is intentionally limited to: * Only the worksharing-loop directive. * Recognizes only the nowait clause. * No loop nests with more than one loop. * Untested with templates, exceptions. * Semantic checking left to the existing infrastructure. This patch introduces a new AST node, OMPCanonicalLoop, which becomes parent of any loop that has to adheres to the restrictions as specified by the OpenMP standard. These restrictions allow OMPCanonicalLoop to provide the following additional information that depends on base language semantics: * The distance function: How many loop iterations there will be before entering the loop nest. * The loop variable function: Conversion from a logical iteration number to the loop variable. These allow the OpenMPIRBuilder to act solely using logical iteration numbers without needing to be concerned with iterator semantics between calling the distance function and determining what the value of the loop variable ought to be. Any OpenMP logical should be done by the OpenMPIRBuilder such that it can be reused MLIR OpenMP dialect and thus by flang. The distance and loop variable function are implemented using lambdas (or more exactly: CapturedStmt because lambda implementation is more interviewed with the parser). It is up to the OpenMPIRBuilder how they are called which depends on what is done with the loop. By default, these are emitted as outlined functions but we might think about emitting them inline as the OpenMPRuntime does. For compatibility with the current OpenMP implementation, even though not necessary for the OpenMPIRBuilder, OMPCanonicalLoop can still be nested within OMPLoopDirectives' CapturedStmt. Although OMPCanonicalLoop's are not currently generated when the OpenMPIRBuilder is not enabled, these can just be skipped when not using the OpenMPIRBuilder in case we don't want to make the AST dependent on the EnableOMPBuilder setting. Loop nests with more than one loop require support by the OpenMPIRBuilder (D93268). A simple implementation of non-rectangular loop nests would add another lambda function that returns whether a loop iteration of the rectangular overapproximation is also within its non-rectangular subset. Reviewed By: jdenny Differential Revision: https://reviews.llvm.org/D94973
2021-03-04[MS] Fix crash involving gnu stmt exprs and inallocaReid Kleckner1-6/+6
Use a WeakTrackingVH to cope with the stmt emission logic that cleans up unreachable blocks. This invalidates the reference to the deferred replacement placeholder. Cope with it. Fixes PR25102 (from 2015!)
2021-03-04Introduce noundef attribute at call sites for stricter poison analysisGui Andrade1-14/+1
This change adds a new IR noundef attribute, which denotes when a function call argument or return val may never contain uninitialized bits. In MemorySanitizer, this attribute enables optimizations which decrease instrumented code size by up to 17% (measured with an instrumented build of clang) . I'll introduce the change allowing msan to take advantage of this information in a separate patch. Differential Revision: https://reviews.llvm.org/D81678
2021-02-24Reduce the number of attributes attached to each functionDávid Bolvanský1-1/+2
Patch takes advantage of the implicit default behavior to reduce the number of attributes, which in turns reduces compilation time. Reviewed By: serge-sans-paille Differential Revision: https://reviews.llvm.org/D97116
2021-02-22[clang][patch] Inclusive language, modify filename SanitizerBlacklist.h to ↵Melanie Blower1-2/+2
NoSanitizeList.h This patch responds to a comment from @vitalybuka in D96203: suggestion to do the change incrementally, and start by modifying this file name. I modified the file name and made the other changes that follow from that rename. Reviewers: vitalybuka, echristo, MaskRay, jansvoboda11, aaron.ballman Differential Revision: https://reviews.llvm.org/D96974
2021-02-20Reduce the number of attributes attached to each functionDávid Bolvanský1-2/+2
This takes advantage of the implicit default behavior to reduce the number of attributes.
2021-01-26Support for instrumenting only selected files or functionsPetr Hosek1-0/+4
This change implements support for applying profile instrumentation only to selected files or functions. The implementation uses the sanitizer special case list format to select which files and functions to instrument, and relies on the new noprofile IR attribute to exclude functions from instrumentation. Differential Revision: https://reviews.llvm.org/D94820
2021-01-26Revert "Support for instrumenting only selected files or functions"Petr Hosek1-4/+0
This reverts commit 4edf35f11a9e20bd5df3cb47283715f0ff38b751 because the test fails on Windows bots.
2021-01-26Support for instrumenting only selected files or functionsPetr Hosek1-0/+4
This change implements support for applying profile instrumentation only to selected files or functions. The implementation uses the sanitizer special case list format to select which files and functions to instrument, and relies on the new noprofile IR attribute to exclude functions from instrumentation. Differential Revision: https://reviews.llvm.org/D94820
2021-01-11CGDebugInfo: Delete unused parametersFangrui Song1-2/+1
2021-01-05[Coverage] Add support for Branch Coverage in LLVM Source-Based Code CoverageAlan Phipps1-12/+96
This is an enhancement to LLVM Source-Based Code Coverage in clang to track how many times individual branch-generating conditions are taken (evaluate to TRUE) and not taken (evaluate to FALSE). Individual conditions may comprise larger boolean expressions using boolean logical operators. This functionality is very similar to what is supported by GCOV except that it is very closely anchored to the ASTs. Differential Revision: https://reviews.llvm.org/D84467
2020-12-28Fix PR35902: incorrect alignment used for ubsan check.James Y Knight1-5/+3
UBSan was using the complete-object align rather than nv alignment when checking the "this" pointer of a method. Furthermore, CGF.CXXABIThisAlignment was also being set incorrectly, due to an incorrectly negated test. The latter doesn't appear to have had any impact, due to it not really being used anywhere. Differential Revision: https://reviews.llvm.org/D93072
2020-11-06[FPEnv] Use strictfp metadata in casting nodesKevin P. Neal1-1/+18
The strictfp metadata was added to the casting AST nodes in D85960, but we aren't using that metadata yet. This patch adds that support. In order to avoid lots of ad-hoc passing around of the strictfp bits I updated the IRBuilder when moving from a function that has the Expr* to a function that lacks it. I believe we should switch to this pattern to keep the strictfp support from being overly invasive. For the purpose of testing that we're picking up the right metadata, I also made my tests use a pragma to make the AST's strictfp metadata not match the global strictfp metadata. This exposes issues that we need to deal with in subsequent patches, and I believe this is the right method for most all of our clang strictfp tests. Differential Revision: https://reviews.llvm.org/D88913
2020-11-04[clang] Add mustprogress and llvm.loop.mustprogress attribute deductionAtmn Patel1-0/+8
Since C++11, the C++ standard has a forward progress guarantee [intro.progress], so all such functions must have the `mustprogress` requirement. In addition, from C11 and onwards, loops without a non-zero constant conditional or no conditional are also required to make progress (C11 6.8.5p6). This patch implements these attribute deductions so they can be used by the optimization passes. Differential Revision: https://reviews.llvm.org/D86841
2020-10-31[CodeGen] Implement [[likely]] and [[unlikely]] for while and for loop.Mark de Wever1-0/+9
The attribute has no effect on a do statement since the path of execution will always include its substatement. It adds a diagnostic when the attribute is used on an infinite while loop since the codegen omits the branch here. Since the likelihood attributes have no effect on a do statement no diagnostic will be issued for do [[unlikely]] {...} while(0); Differential Revision: https://reviews.llvm.org/D89899
2020-10-30Support complex target features combinationsLiu, Chen31-38/+17
This patch is mainly doing two things: 1. Adding support for parentheses, making the combination of target features more diverse; 2. Making the priority of ’,‘ is higher than that of '|' by default. So I need to make some change with PTX Builtin function. Differential Revision: https://reviews.llvm.org/D89184