aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/AST/SourceLocationTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-04-01[clang] Concepts: support pack expansions for type constraints (#132626)Matheus Izvekov1-3/+3
This reverts an earlier attempt (adb0d8ddceb143749c519d14b8b31b481071da77 and 50e5411e4247421fd606f0a206682fcdf0303ae3) to support these expansions, which was limited to type arguments and which subverted the purpose of SubstTemplateTypeParmType. This propagates the ArgumentPackSubstitutionIndex along with the AssociatedConstraint, so that the pack expansion works, without needing any new transforms or otherwise any changes to the template instantiation process. This keeps the tests from the reverted commits, and adds a few more showing the new solution also works for NTTPs. Fixes https://github.com/llvm/llvm-project/issues/131798
2024-09-14[clang] Strip unneeded calls to raw_string_ostream::str() (NFC)JOE19941-1/+1
Avoid extra layer of indirection. p.s. Also, remove calls to raw_string_ostream::flush(), which are no-ops.
2023-08-31Add a concept AST node.Jens Massberg1-4/+133
This patch adds a concept AST node (`ConceptLoc`) and uses it at the corresponding places. There are three objects that might have constraints via concepts: `TypeConstraint`, `ConceptSpecializationExpr` and `AutoTypeLoc`. The first two inherit from `ConceptReference` while the latter has the information about a possible constraint directly stored in `AutoTypeLocInfo`. It would be nice if the concept information would be stored the same way in all three cases. Moreover the current structure makes it difficult to deal with these concepts. For example in Clangd accessing the locations of constraints of a `AutoTypeLoc` can only be done with quite ugly hacks. So we think that it makes sense to create a new AST node for such concepts. In details we propose the following: - Rename `ConceptReference` to `ConceptLoc` (or something else what is approriate) and make it the new AST node. - `TypeConstraint` and `ConceptSpecializationExpr` do not longer inherit from `ConceptReference` but store a pointer to a `ConceptLoc`. - `AutoTypeLoc` stores a pointer to `ConceptLoc` instead of storing the concept info in `AutoTypeLocInfo`. This patch implements a first version of this idea which compiles and where the existing tests pass. To make this patch as small as possible we keep the existing member functions to access concept data. Later these can be replaced by directly calling the corresponding functions of the `ConceptLoc`s. Differential Revision: https://reviews.llvm.org/D155858
2023-01-18[clang][Sema] Fix uninitialized `SourceLocation` for types with multiple ↵Volodymyr Sapsai1-0/+41
attributes and macros. Some `TypeLoc`s are considered "sugar" and we go past them in `GetTypeSourceInfoForDeclarator`. The problem is that we peel off only the same kind of `TypeLoc` at the time which makes it impossible to handle mixed sequences like `AttributedTypeLoc - MacroQualifiedTypeLoc - AttributedTypeLoc - PointerTypeLoc` In this situation, as shown in the added test, we don't get to `PointerTypeLoc` and don't set its starLoc leaving it uninitialized. Address FIXME and peel off "sugar" `TypeLoc`s regardless of their order. rdar://102149264 Differential Revision: https://reviews.llvm.org/D141424
2023-01-12[test] Split out Annotations from `TestingSupport`Jordan Rupprecht1-1/+1
The Annotations helper class does not have a gtest or gmock dependency, but because it's bundled with the rest of TestingSupport, it gets one. By splitting it out, a target can use it without being forced to use LLVM's copy of gtest. Reviewed By: GMNGeoffrey, sammccall, gribozavr2 Differential Revision: https://reviews.llvm.org/D141175
2022-05-04Change the behavior of implicit int diagnosticsAaron Ballman1-2/+8
C89 allowed a type specifier to be elided with the resulting type being int, aka implicit int behavior. This feature was subsequently removed in C99 without a deprecation period, so implementations continued to support the feature. Now, as with implicit function declarations, is a good time to reevaluate the need for this support. This patch allows -Wimplicit-int to issue warnings in C89 mode (off by default), defaults the warning to an error in C99 through C17, and disables support for the feature entirely in C2x. It also removes a warning about missing declaration specifiers that really was just an implicit int warning in disguise and other minor related cleanups.
2022-01-19[AST] Fix the incorrect auto-keyword loc for constrained auto type loc.Haojian Wu1-0/+8
E.g. `Concept auto Func();` The nameLoc for the constained auto type loc pointed to the concept name loc, it should be the auto token loc. This patch fixes it, and remove a relevant hack in clang-tidy check. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D117009
2022-01-17Reland (2) "[AST] Add RParen loc for decltype AutoTypeloc.""Haojian Wu1-0/+7
The patch was reverted because it caused a crash during PCH build -- we missed to update the RParenLoc in TreeTransform<Derived>::TransformAutoType. This relands 55d96ac and 37ec65e with a test and fix.
2022-01-12Revert (2) "[AST] Add RParen loc for decltype AutoTypeloc."Florian Hahn1-7/+0
This reverts commit 41fbdfa4d5601cccbcdc0ded8ef35190d502f7f3. The commit breaks stage 2 builds with debug info, e.g. https://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/5088/console Clang crashes with the following assertion when building llvm-project/llvm/lib/Support/Timer.cpp /usr/local/bin/sccache /Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/host-compiler/bin/clang++ -DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Support -I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support -Iinclude -I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/include -fno-stack-protector -fno-common -Wno-profile-instr-unprofiled -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -fmodules -fmodules-cache-path=/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/clang-build/Build/module.cache -fcxx-modules -Xclang -fmodules-local-submodule-visibility -gmodules -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -flto=thin -O2 -g -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -std=c++14 -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -MF lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o.d -o lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -c /Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support/Timer.cpp Assertion failed: (((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow"), function getLocWithOffset, file /Users/buildslave/jenkins/workspace/clang-stage1-RA/llvm-project/clang/include/clang/Basic/SourceLocation.h, line 135.
2022-01-11Reland "[AST] Add RParen loc for decltype AutoTypeloc."Haojian Wu1-0/+7
Reland 55d96ac and 37ec65e with a clang-tidy fix.
2022-01-10Revert "[AST] Add RParen loc for decltype AutoTypeloc."Haojian Wu1-7/+0
This breaks a clang-tidy check, needs to investigate and fix. Revert them to bring the buildbot back. This reverts commit 55d96ac3dc56bdebea854952a724c2a50d96ce19 and 37ec65e1d705f56fe5551de1dfcbac1e071588a2
2022-01-10[AST] Add RParen loc for decltype AutoTypeloc.Haojian Wu1-0/+7
Differential Revision: https://reviews.llvm.org/D116919
2022-01-10[AST] Add more source information for DecltypeTypeLoc.Haojian Wu1-1/+28
Adds the paren source location, and removes the hack in clangd. Differential Revision: https://reviews.llvm.org/D116793
2020-12-11Remove references to the ast_type_traits namespaceAlexander Kornienko1-2/+1
Follow up to cd62511496938e33c061c90796dd23a5288ff843 / https://reviews.llvm.org/D74499 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D92994
2020-07-10Summary: [clang] Provide a way for WhileStmt to report the location of its ↵Vy Nguyen1-0/+53
LParen and RParen. Summary: This helps avoiding hacks downstream. Reviewers: shafik Subscribers: martong, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D83529
2020-06-02Renamed Lang_C to Lang_C99, Lang_CXX to Lang_CXX03, and 2a to 20Dmitri Gribenko1-3/+3
Summary: I think we would be better off with tests explicitly specifying the language mode. Right now Lang_C means C99, but reads as "any C version", or as "unspecified C version". I also changed '-std=c++98' to '-std=c++03' because they are aliases (so there is no difference in practice), because Clang implements C++03 rules in practice, and because 03 makes a nice sortable progression between 03, 11, 14, 17, 20. Reviewers: shafik, hlopko Reviewed By: hlopko Subscribers: jfb, martong, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D81000
2020-05-21Set traversal explicitly where needed in testsStephen Kelly1-9/+9
Reviewers: aaron.ballman, shafik Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72531
2020-03-13Refactor SourceLocationTest to `using namespace`Marcel Hlopko1-20/+17
Summary: Only for the readability reasons. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76120
2020-03-13[Sema] Fix location of star ('*') inside MemberPointerTypeLocMarcel Hlopko1-1/+20
Summary: Copy of https://reviews.llvm.org/D72073?id=235842, submitting with ilya-biryukov's permission. Reviewers: gribozavr, gribozavr2 Reviewed By: gribozavr2 Subscribers: mgorny, gribozavr2, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76061
2019-12-03Add FunctionDecl::getParameterSourceRange()Nicolas Manichon1-0/+106
This source range covers the list of parameters of the function declaration, including the ellipsis for a variadic function.
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2017-01-12Tracking exception specification source locationsMalcolm Parsons1-0/+67
Summary: We do not currently track the source locations for exception specifications such that their source range can be queried through the AST. This leads to trying to write more complex code to determine the source range for uses like FixItHints (see D18575 for an example). In addition to use within tools like clang-tidy, I think this information may become more important to track as exception specifications become more integrated into the type system. Patch by Don Hinton. Reviewers: rsmith Subscribers: malcolm.parsons, sbarzowski, alexfh, hintonda, cfe-commits Differential Revision: https://reviews.llvm.org/D20428 llvm-svn: 291771
2016-10-21[Sema] Store a SourceRange for multi-token builtin typesMalcolm Parsons1-0/+90
Summary: clang-tidy's modernize-use-auto check uses the SourceRange of a TypeLoc when replacing the type with auto. This was producing the wrong result for multi-token builtin types like long long: -long long *ll = new long long(); +auto long *ll = new long long(); Reviewers: alexfh, hokein, rsmith, Prazek, aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25363 llvm-svn: 284885
2016-01-12Properly track the end location of an exception specification.Aaron Ballman1-0/+38
Patch by Adrian Zgorzałek llvm-svn: 257521
2015-09-17Rename AST node matchers to match the AST node names directly. Part of this ↵Aaron Ballman1-13/+13
rename also splits recordDecl() (which used to match CXXRecordDecl) into recordDecl() (that matches RecordDecl) and cxxRecordDecl (that matches CXXRecordDecl). Also adds isStruct(), isUnion(), and isClass() narrowing matchers for RecordDecl objects. llvm-svn: 247885
2015-05-01Fix a few line endings. NFC.Yunzhong Gao1-36/+36
llvm-svn: 236301
2015-04-11Use 'override/final' instead of 'virtual' for overridden methodsAlexander Kornienko1-5/+5
Summary: The patch is generated using clang-tidy misc-use-override check. This command was used: tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \ -checks='-*,misc-use-override' -header-filter='llvm|clang' -j=32 -fix Reviewers: dblaikie Reviewed By: dblaikie Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D8926 llvm-svn: 234678
2015-03-24Track the source location of the dot or arrow operator in a MemberExpr.Aaron Ballman1-6/+38
Patch by Joe Ranieri! llvm-svn: 233085
2015-03-23Record correct source range for defaulted/deleted members.Eli Bendersky1-0/+12
Fixes https://llvm.org/bugs/show_bug.cgi?id=20744 struct A { A() = default; }; Previously the source range of the declaration of A ended at the ')'. It should include the '= default' part as well. The same for '= delete'. Note: this will break one of the clang-tidy fixers, which is going to be addessed in a follow-up patch. Differential Revision: http://reviews.llvm.org/D8465 llvm-svn: 233028
2014-07-31Obective-C. Patch to fix the incorrect ObjcMessageExpr argument source ranges, Fariborz Jahanian1-0/+12
when arguments are structures or classes. PR16392. patch by Karlis Senko llvm-svn: 214409
2014-07-17Fix FriendDecl source location and range for class templates and function ↵Nikola Smiljanic1-4/+136
declarations that don't start with 'friend' keyword. Add more unittests. llvm-svn: 213220
2014-06-06Add first set of tests for FriendDecl source range and location.Nikola Smiljanic1-0/+78
llvm-svn: 210306
2014-02-22Correctly set brace range for CXXConstructExprs formed by list initialization.Peter Collingbourne1-0/+10
Differential Revision: http://llvm-reviews.chandlerc.com/D2711 llvm-svn: 201926
2014-01-07Sort all the #include lines with LLVM's utils/sort_includes.py whichChandler Carruth1-1/+1
encodes the canonical rules for LLVM's style. I noticed this had drifted quite a bit when cleaning up LLVM, so wanted to clean up Clang as well. llvm-svn: 198686
2013-09-07Fix missing source location in CXXTemporaryObjectExpr nodes.Enea Zaffanella1-0/+9
For clarity, renamed (get/set)ParenRange as (get/set)ParenOrBraceRange in CXXConstructExpr nodes. Added testcase. llvm-svn: 190239
2013-07-19Fix source range of implicitly instantiated friend declaration.Enea Zaffanella1-0/+13
llvm-svn: 186702
2013-07-17Fixed source range of C++03 access declarations.Enea Zaffanella1-0/+20
llvm-svn: 186522
2013-07-08Fixed testcase failing under MS by adding "-fno-delayed-template-parsing",Enea Zaffanella1-6/+3
as suggested by Takumi. To this end, added a MatchVerifier::match() overload accepting a vector of invocation arguments. llvm-svn: 185827
2013-07-08AST/SourceLocationTest.cpp: Appease MS hosts to suppress ↵NAKAMURA Takumi1-0/+5
CXXUnresolvedConstructExpr.SourceRange, for now. FIXME: It could pass if MS-compatible mode were disabled with Args.push_back("-fno-delayed-template-parsing"). llvm-svn: 185795
2013-07-07Fixed source range for functional cast and unresolved construct expr nodes.Enea Zaffanella1-0/+21
Added testcases. llvm-svn: 185773
2013-07-06Fixed source location info for UnaryTransformTypeLoc nodes.Enea Zaffanella1-0/+21
llvm-svn: 185765
2013-06-17Fix source range of CXXNewExpr with parentheses around the type. PR15569.Eli Friedman1-0/+6
llvm-svn: 184139
2013-06-07Re-commit r183466 with a fix to make the TypeLoc casting machinery workEli Friedman1-1/+1
correctly in the presence of qualified types. (I had to change the unittest because it was trying to cast a QualifiedTypeLoc to TemplateSpecializationTypeLoc.) llvm-svn: 183563
2013-06-07Adds a test that verifies angle bracket locations.Manuel Klimek1-0/+19
Regression test to make sure TemplateSpecializationTypeLocs have the correct locations for angle brackets. llvm-svn: 183514
2013-04-05Add an error to check that all program scope variables are in the constant ↵Tanya Lattner1-4/+4
address space in OpenCL. llvm-svn: 178906
2013-02-05PR15095: Use more correct source locations for the InitListExpr we fake up forRichard Smith1-0/+33
vector initialization. Patch by John Stratton! llvm-svn: 174339
2013-01-31Move commonly useful code for AST testing into MatchVerfier.h.Manuel Klimek1-165/+2
llvm-svn: 174057
2012-12-04Sort the #include lines for unittests/...Chandler Carruth1-1/+1
I've tried to place sensible headers at the top as main-module headers. llvm-svn: 169243
2012-11-08Fix a source range regression in C++ new expressions with call initializers.David Blaikie1-0/+6
Introduced in r167507, discovered in review by Abramo Bagnara. llvm-svn: 167597
2012-11-08Fixed converted ConstantArrayTypeLoc range. Added a missing testcase for ↵Abramo Bagnara1-1/+18
ConstructorDecl source range. llvm-svn: 167583