summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Factor out common tautological comparison code from scalar and vector ↵Richard Smith2018-01-071-97/+110
| | | | | | | | compare checking. In passing, improve vector compare diagnostic to match scalar compare diagnostic. llvm-svn: 321972
* [NFC] Modernize enum 'UnqualifiedId::IdKind' into a scoped enum ↵Faisal Vali2017-12-301-6/+7
| | | | | | UnqualifiedIdKind. llvm-svn: 321574
* [NFC] Modernize enum Declarator::TheContext to a type-safe scoped enum.Faisal Vali2017-12-291-1/+1
| | | | | | Note, we don't do any bitwise manipulations when using them. llvm-svn: 321546
* Silence a bunch of implicit fallthrough warningsAdrian Prantl2017-12-191-3/+3
| | | | llvm-svn: 321115
* [c++20] P0515R3: Parsing support and basic AST construction for operator <=>.Richard Smith2017-12-141-0/+8
| | | | | | | | | | | | | | | Adding the new enumerator forced a bunch more changes into this patch than I would have liked. The -Wtautological-compare warning was extended to properly check the new comparison operator, clang-format needed updating because it uses precedence levels as weights for determining where to break lines (and several operators increased their precedence levels with this change), thread-safety analysis needed changes to build its own IL properly for the new operator. All "real" semantic checking for this operator has been deferred to a future patch. For now, we use the relational comparison rules and arbitrarily give the builtin form of the operator a return type of 'void'. llvm-svn: 320707
* [CodeGen][X86] Fix handling of __fp16 vectors.Akira Hatanaka2017-12-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes a bug in IRGen where it generates completely broken code for __fp16 vectors on X86. For example when the following code is compiled: half4 hv0, hv1, hv2; // these are vectors of __fp16. void foo221() { hv0 = hv1 + hv2; } clang generates the following IR, in which two i16 vectors are added: @hv1 = common global <4 x i16> zeroinitializer, align 8 @hv2 = common global <4 x i16> zeroinitializer, align 8 @hv0 = common global <4 x i16> zeroinitializer, align 8 define void @foo221() { %0 = load <4 x i16>, <4 x i16>* @hv1, align 8 %1 = load <4 x i16>, <4 x i16>* @hv2, align 8 %add = add <4 x i16> %0, %1 store <4 x i16> %add, <4 x i16>* @hv0, align 8 ret void } To fix the bug, this commit uses the code committed in r314056, which modified clang to promote and truncate __fp16 vectors to and from float vectors in the AST. It also fixes another IRGen bug where a short value is assigned to an __fp16 variable without any integer-to-floating-point conversion, as shown in the following example: __fp16 a; short b; void foo1() { a = b; } @b = common global i16 0, align 2 @a = common global i16 0, align 2 define void @foo1() #0 { %0 = load i16, i16* @b, align 2 store i16 %0, i16* @a, align 2 ret void } rdar://problem/20625184 Differential Revision: https://reviews.llvm.org/D40112 llvm-svn: 320215
* Remove creation of out-of-bounds value of enumeration type (resulting in UB).Richard Smith2017-12-081-5/+5
| | | | | | | Also remove unnecessary initialization of out-parameters with this value, so that MSan is able to catch errors appropriately. llvm-svn: 320212
* [OPENMP] Initial codegen for `target teams distribute` directive.Alexey Bataev2017-12-081-1/+1
| | | | | | Host + default devices codegen for `target teams distribute` directive. llvm-svn: 320149
* [OPENMP] Do not capture private variables in the target regions.Alexey Bataev2017-12-071-2/+4
| | | | | | | | Private variables are completely redefined in the outlined regions, so we don't need to capture them. Patch adds this behavior to the target-based regions. llvm-svn: 320078
* Generalize "static data member instantiated" notification to cover variable ↵Richard Smith2017-12-051-39/+29
| | | | | | | | | templates too. While here, split the "point of instantiation changed" notification out from it; these two really are orthogonal changes. llvm-svn: 319727
* Now that C++17 is official (https://www.iso.org/standard/68564.html), start ↵Aaron Ballman2017-12-041-2/+2
| | | | | | changing the C++1z terminology over to C++17. NFC intended, these are all mechanical changes. llvm-svn: 319688
* The offsetof macro is intended to work with subobjects rather than simple ↵Aaron Ballman2017-11-211-9/+1
| | | | | | identifiers designating a member, making the -Wextended-offsetof diagnostic obsolete as this construct is not an extension. Implements WG14 DR496. llvm-svn: 318796
* [OpenMP] diagnose assign to firstprivate const, patch by Joel E. DennyAlexey Bataev2017-11-101-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: [OpenMP] diagnose assign to firstprivate const Clang does not diagnose assignments to const variables declared firstprivate. Furthermore, codegen is broken such that, at run time, such assignments simply have no effect. For example, the following prints 0 not 1: int main() { const int i = 0; #pragma omp parallel firstprivate(i) { i=1; printf("%d\n", i); } return 0; } This commit makes these assignments a compile error, which is consistent with other OpenMP compilers I've tried (pgcc 17.4-0, gcc 6.3.0). Reviewers: ABataev Reviewed By: ABataev Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D39859 llvm-svn: 317891
* [ObjC] Fix function signature handling for blocks literals with attributesAlex Lorenz2017-11-081-2/+2
| | | | | | | | | | | | | | Block literals can have a type with attributes in its signature, e.g. ns_returns_retained. The code that inspected the type loc of the block when declaring its parameters didn't account for this fact, and only looked through paren type loc. This commit ensures that getAsAdjusted is used instead of IgnoreParens to find the block's FunctionProtoTypeLoc. This ensures that block parameters are declared correctly in the block and avoids the 'undeclared identifier' error. rdar://35416160 llvm-svn: 317736
* PR35039: Materialize temporary objects before wrapping them in anRichard Smith2017-10-281-0/+10
| | | | | | | | | OpaqueValueExpr in a GNU binary conditional expression. It's not meaningful for a non-materialized temporary object to be used as a common subexpression of multiple expressions. llvm-svn: 316836
* Don't suppress instantiation of definitions for variables subject to explicitRichard Smith2017-10-181-5/+11
| | | | | | | | | instantiation declarations if they are usable from constant expressions. We are permitted to instantiate in these cases, and required to do so in order to have an initializer available for use within constant evaluation. llvm-svn: 316136
* Enable support for the [[maybe_unused]] attribute from WG14 N2053 when ↵Aaron Ballman2017-10-181-1/+2
| | | | | | enabling double square bracket attributes in C code. llvm-svn: 316096
* Convert clang::LangAS to a strongly typed enumAlexander Richardson2017-10-151-20/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Convert clang::LangAS to a strongly typed enum Currently both clang AST address spaces and target specific address spaces are represented as unsigned which can lead to subtle errors if the wrong type is passed. It is especially confusing in the CodeGen files as it is not possible to see what kind of address space should be passed to a function without looking at the implementation. I originally made this change for our LLVM fork for the CHERI architecture where we make extensive use of address spaces to differentiate between capabilities and pointers. When merging the upstream changes I usually run into some test failures or runtime crashes because the wrong kind of address space is passed to a function. By converting the LangAS enum to a C++11 we can catch these errors at compile time. Additionally, it is now obvious from the function signature which kind of address space it expects. I found the following errors while writing this patch: - ItaniumRecordLayoutBuilder::LayoutField was passing a clang AST address space to TargetInfo::getPointer{Width,Align}() - TypePrinter::printAttributedAfter() prints the numeric value of the clang AST address space instead of the target address space. However, this code is not used so I kept the current behaviour - initializeForBlockHeader() in CGBlocks.cpp was passing LangAS::opencl_generic to TargetInfo::getPointer{Width,Align}() - CodeGenFunction::EmitBlockLiteral() was passing a AST address space to TargetInfo::getPointerWidth() - CGOpenMPRuntimeNVPTX::translateParameter() passed a target address space to Qualifiers::addAddressSpace() - CGOpenMPRuntimeNVPTX::getParameterAddress() was using llvm::Type::getPointerTo() with a AST address space - clang_getAddressSpace() returns either a LangAS or a target address space. As this is exposed to C I have kept the current behaviour and added a comment stating that it is probably not correct. Other than this the patch should not cause any functional changes. Reviewers: yaxunl, pcc, bader Reviewed By: yaxunl, bader Subscribers: jlebar, jholewinski, nhaehnle, Anastasia, cfe-commits Differential Revision: https://reviews.llvm.org/D38816 llvm-svn: 315871
* [OPENMP] Capture references to global variables.Alexey Bataev2017-10-061-1/+2
| | | | | | | | In C++11 variable to global variables are considered as constant expressions and these variables are not captured in the outlined regions. Patch allows capturing of such variables in the OpenMP regions. llvm-svn: 315074
* [OpenCL] Fix checking of vector type castingYaxun Liu2017-10-031-3/+3
| | | | | | | | | | | | | | | | | | Currently clang allows the following code int a; int b = (const int) a; However it does not the following code int4 a; int4 b = (const int4) a; This is because Clang compares the qualified types instead of unqualified types for vector type casting, which causes the inconsistency. This patch fixes that. Differential Revision: https://reviews.llvm.org/D38463 llvm-svn: 314802
* [Sema] Null check in BuildDeclarationNameExprYi Kong2017-09-251-0/+2
| | | | | | | | | | Qualtype may point to null if we cannot infer its type yet. Fixes PR33843 Differential Revision: https://reviews.llvm.org/D38158 llvm-svn: 314124
* Don't warn about runtime behavior problems in variable initializers that weRichard Smith2017-09-231-3/+17
| | | | | | | | know are going to be constant-evaluated. Any relevant diagnostics should be produced by constant expression evaluation. llvm-svn: 314067
* Promote storage-only __fp16 vector operands to float vectors.Akira Hatanaka2017-09-231-2/+119
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes a bug in the handling of storage-only __fp16 vectors where clang didn't promote __fp16 vector operands to float vectors. Conceptually, it performs the following transformation on the AST in CreateBuiltinBinOp and CreateBuiltinUnaryOp: (Before) typedef __fp16 half4 __attribute__ ((vector_size (8))); typedef float float4 __attribute__ ((vector_size (16))); half4 hv0, hv1, hv2, hv3; hv0 = hv1 + hv2 + hv3; (After) float4 t0 = (float4)hv1 + (float4)hv2; float4 t1 = t0 + (float4)hv3; hv0 = (half4)t1; Note that this commit fixes the bug for targets that set HalfArgsAndReturns to true (ARM and ARM64). Targets using intrinsics such as llvm.convert.to.fp16 to handle __fp16 are still broken. rdar://problem/20625184 Differential Revision: https://reviews.llvm.org/D32520 llvm-svn: 314056
* Implement C++ [basic.link]p8.Richard Smith2017-09-201-0/+2
| | | | | | | | | | | | | | If a function or variable has a type with no linkage (and is not extern "C"), any use of it requires a definition within the same translation unit; the idea is that it is not possible to define the entity elsewhere, so any such use is necessarily an error. There is an exception, though: some types formally have no linkage but nonetheless can be referenced from other translation units (for example, this happens to anonymous structures defined within inline functions). For entities with those types, we suppress the diagnostic except under -pedantic. llvm-svn: 313729
* Teach clang to tolerate the 'p = nullptr + n' idiom used by glibcAndrew Kaylor2017-09-191-0/+46
| | | | | | Differential Revision: https://reviews.llvm.org/D37042 llvm-svn: 313666
* [Sema] Disallow assigning record lvalues with nested const-qualified fields.Bjorn Pettersson2017-09-191-10/+74
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: According to C99 6.3.2.1p1, structs and unions with nested const-qualified fields (that is, const-qualified fields declared at some recursive level of the aggregate) are not modifiable lvalues. However, Clang permits assignments of these lvalues. With this patch, we both prohibit the assignment of records with const-qualified fields and emit a best-effort diagnostic. This fixes https://bugs.llvm.org/show_bug.cgi?id=31796 . Committing on behalf of bevinh (Bevin Hansson). Reviewers: rtrieu, rsmith, bjope Reviewed By: bjope Subscribers: Ka-Ka, rogfer01, bjope, fhahn, cfe-commits Differential Revision: https://reviews.llvm.org/D37254 llvm-svn: 313628
* Fix the second half of PR34266: Don't implicitly capture '*this' if the ↵Faisal Vali2017-09-171-0/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | members are found in a class unrelated to the enclosing class. https://bugs.llvm.org/show_bug.cgi?id=34266 For e.g. struct A { void f(int); static void f(char); }; struct B { auto foo() { return [&] (auto a) { A::f(a); // this should not cause a capture of '*this' }; } }; The patch does the following: 1) It moves the check to attempt an implicit capture of '*this' by reference into the more logical location of when the call is actually built within ActOnCallExpr (as opposed to when the unresolved-member-lookup node is created). - Reminder: A capture of '*this' by value has to always be an explicit capture. 2) It additionally checks whether the naming class of the UnresolvedMemberExpr ('A' in the example above) is related to the enclosing class ('B' above). P.S. If you have access to ISO-C++'s CWG reflector, see this thread for some potentially related discussion: http://lists.isocpp.org/core/2017/08/2851.php llvm-svn: 313487
* [Sema] Correct typos in LHS, RHS before building a binop expression.Volodymyr Sapsai2017-09-151-15/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically, typo correction should be done before dispatching between different kinds of binary operations like pseudo-object assignment, overloaded binary operation, etc. Without this change we hit an assertion Assertion failed: (!LHSExpr->hasPlaceholderType(BuiltinType::PseudoObject)), function CheckAssignmentOperands when in Objective-C we reference a property without `self` and there are 2 equally good typo correction candidates: ivar and a class name. In this case LHS expression in `BuildBinOp` is CXXDependentScopeMemberExpr `-TypoExpr and instead of handling Obj-C property assignment as pseudo-object assignment, we call `CreateBuiltinBinOp` which corrects typo to ObjCPropertyRefExpr '<pseudo-object type>' but cannot handle pseudo-objects and asserts about it (indirectly, through `CheckAssignmentOperands`). rdar://problem/33102722 Reviewers: rsmith, ahatanak, majnemer Reviewed By: ahatanak Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D37322 llvm-svn: 313323
* Catch more cases with -Wenum-compareRichard Trieu2017-09-091-2/+4
| | | | | | | Treat typedef enum as named enums instead of anonymous enums. Anonymous enums are ignored by the warning, so previously, typedef enums were ignored as well. llvm-svn: 312842
* Recommit "Add _Float16 as a C/C++ source language type"Sjoerd Meijer2017-09-081-2/+6
| | | | | | | | This is a recommit of r312781; in some build configurations variable names are omitted, so changed the new regression test accordingly. llvm-svn: 312794
* Revert "Add _Float16 as a C/C++ source language type"Sjoerd Meijer2017-09-081-6/+2
| | | | | | | The clang-with-lto-ubuntu bot didn't like the new regression test, revert while I investigate the issue. llvm-svn: 312784
* Add _Float16 as a C/C++ source language typeSjoerd Meijer2017-09-081-2/+6
| | | | | | | | | | | This adds _Float16 as a source language type, which is a 16-bit floating point type defined in C11 extension ISO/IEC TS 18661-3. In follow up patches documentation and more tests will be added. Differential Revision: https://reviews.llvm.org/D33719 llvm-svn: 312781
* [OpenCL] Handle taking an address of block captures.Anastasia Stulova2017-09-071-12/+11
| | | | | | | | | | | | | | | | Block captures can have different physical locations in memory segments depending on the use case (as a function call or as a kernel enqueue) and in different vendor implementations. Therefore it's unclear how to add address space to capture addresses uniformly. Currently it has been decided to disallow taking addresses of captured variables until further clarifications in the spec. Differential Revision: https://reviews.llvm.org/D36410 llvm-svn: 312728
* Fix typos, remove unused private members of CommonOptionsParser, NFCJohannes Altmanninger2017-08-231-1/+1
| | | | llvm-svn: 311544
* [OPENMP] Fix for PR34014: OpenMP 4.5: Target construct in static methodAlexey Bataev2017-08-221-0/+1
| | | | | | | | | | of class fails to map class static variable. If the global variable is captured and it has several redeclarations, sometimes it may lead to a compiler crash. Patch fixes this by working only with canonical declarations. llvm-svn: 311479
* Fix typos in comments; NFCGeorge Burgess IV2017-08-161-1/+1
| | | | llvm-svn: 311051
* Reapply Sema: allow imaginary constants via GNU extension if UDL overloads ↵Tim Northover2017-08-091-8/+17
| | | | | | | | | | | | | | | | | | not present. C++14 added user-defined literal support for complex numbers so that you can write something like "complex<double> val = 2i". However, there is an existing GNU extension supporting this syntax and interpreting the result as a _Complex type. This changes parsing so that such literals are interpreted in terms of C++14's operators if an overload is present but otherwise falls back to the original GNU extension. (We now have more robust diagnostics for implicit conversions so the libc++ test that caused the original revert still passes). llvm-svn: 310478
* Sema: disable implicit conversion from _Complex to real types in C++.Tim Northover2017-08-081-0/+6
| | | | | | | | | | | Converting a _Complex type to a real one simply discards the imaginary part. This can easily lead to loss of information so for safety (and GCC compatibility) this patch disallows that when the conversion would be implicit. The one exception is bool, which actually compares both real and imaginary parts and so is safe. llvm-svn: 310427
* [OPENMP][DEBUG] Set proper address space info if required by target.Alexey Bataev2017-08-081-0/+2
| | | | | | | | | | | Arguments, passed to the outlined function, must have correct address space info for proper Debug info support. Patch sets global address space for arguments that are mapped and passed by reference. Also, cuda-gdb does not handle reference types correctly, so reference arguments are represented as pointers. llvm-svn: 310387
* Revert "[OPENMP][DEBUG] Set proper address space info if required by target."Alexey Bataev2017-08-081-2/+0
| | | | | | This reverts commit r310377. llvm-svn: 310379
* [OPENMP][DEBUG] Set proper address space info if required by target.Alexey Bataev2017-08-081-0/+2
| | | | | | | | | | | Arguments, passed to the outlined function, must have correct address space info for proper Debug info support. Patch sets global address space for arguments that are mapped and passed by reference. Also, cuda-gdb does not handle reference types correctly, so reference arguments are represented as pointers. llvm-svn: 310377
* Revert "[OPENMP][DEBUG] Set proper address space info if required by target."Alexey Bataev2017-08-081-2/+0
| | | | | | This reverts commit r310360. llvm-svn: 310364
* [OPENMP][DEBUG] Set proper address space info if required by target.Alexey Bataev2017-08-081-0/+2
| | | | | | | | | | | Arguments, passed to the outlined function, must have correct address space info for proper Debug info support. Patch sets global address space for arguments that are mapped and passed by reference. Also, cuda-gdb does not handle reference types correctly, so reference arguments are represented as pointers. llvm-svn: 310360
* Revert "[OPENMP][DEBUG] Set proper address space info if required by target."Alexey Bataev2017-08-041-2/+0
| | | | | | This reverts commit r310104. llvm-svn: 310135
* [OPENMP][DEBUG] Set proper address space info if required by target.Alexey Bataev2017-08-041-0/+2
| | | | | | | | | | | Arguments, passed to the outlined function, must have correct address space info for proper Debug info support. Patch sets global address space for arguments that are mapped and passed by reference. Also, cuda-gdb does not handle reference types correctly, so reference arguments are represented as pointers. llvm-svn: 310104
* [Sema] Add a comment on an identified bug on default arguments.Tim Shen2017-08-031-0/+16
| | | | | | | | | | | | | | | Summary: The mis-compile is triggered by internal code, but I haven't reduced it to a small piece of code. Add a FIXME here, since a decent fix doesn't seem to be trivial. The decent fix can be changing Decl::Init to PointerUnion<Stmt *, EvaluatedStmt *, ParamVarDecl *>, and make setUninstantiatedDefaultArg take a ParamVarDecl *, which contains the Expr * as the default argument. This way, getTemplateInstantiationArgs can take that ParamVarDecl and do the right thing. Reviewers: rsmith Subscribers: sanjoy, cfe-commits Differential Revision: https://reviews.llvm.org/D36253 llvm-svn: 309908
* [Sema] Fix lax conversion between non ext vectorsBruno Cardoso Lopes2017-08-011-1/+1
| | | | | | | | | | r282968 introduced a regression due to the lack of proper testing. Re-add lax conversion support between non ext vectors for compound assignments and add a test for that. rdar://problem/28639467 llvm-svn: 309722
* [Sema] NFC: Move all availability checking code to SemaDeclAttr.cppErik Pilkington2017-07-181-78/+1
| | | | | | Previously, this was awkwardly split up between SemaExpr.cpp. llvm-svn: 308356
* [Sema] Mark a virtual CXXMethodDecl as used if a call to it can beAkira Hatanaka2017-07-131-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | devirtualized. The code to detect devirtualized calls is already in IRGen, so move the code to lib/AST and make it a shared utility between Sema and IRGen. This commit fixes a linkage error I was seeing when compiling the following code: $ cat test1.cpp struct Base { virtual void operator()() {} }; template<class T> struct Derived final : Base { void operator()() override {} }; Derived<int> *d; int main() { if (d) (*d)(); return 0; } rdar://problem/33195657 Differential Revision: https://reviews.llvm.org/D34301 llvm-svn: 307883
* [ObjC] Avoid the -Wunguarded-availability warnings for protocolAlex Lorenz2017-07-071-3/+8
| | | | | | | | | | | | | | | requirements in protocol/class/category declarations The unguarded availability warnings in the protocol requirements of a protocol /class/category declaration can be avoided. This matches the behaviour of Swift's diagnostics. The warnings for deprecated/unavailable protocols are preserved. rdar://33156429 Differential Revision: https://reviews.llvm.org/D35061 llvm-svn: 307368
OpenPOWER on IntegriCloud