Skip to content

Commit 1cb34d9

Browse files
iclsrcdm-vodopyanov
iclsrc
authored andcommitted
Merge from 'main' to 'sycl-web' (intel#29)
CONFLICT (content): Merge conflict in clang/lib/CodeGen/CodeGenModule.cpp
2 parents cc0c8b6 + ecc8ac3 commit 1cb34d9

File tree

125 files changed

+5411
-3252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+5411
-3252
lines changed

clang/include/clang/Basic/Diagnostic.h

+1
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
806806
return FatalErrorOccurred || UnrecoverableErrorOccurred;
807807
}
808808

809+
unsigned getNumErrors() const { return NumErrors; }
809810
unsigned getNumWarnings() const { return NumWarnings; }
810811

811812
void setNumWarnings(unsigned NumWarnings) {

clang/include/clang/Frontend/CompilerInvocation.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class CompilerInvocation : public CompilerInvocationBase {
249249
DiagnosticsEngine &Diags);
250250

251251
/// Parse command line options that map to LangOptions.
252-
static void ParseLangArgs(LangOptions &Opts, llvm::opt::ArgList &Args,
252+
static bool ParseLangArgs(LangOptions &Opts, llvm::opt::ArgList &Args,
253253
InputKind IK, const llvm::Triple &T,
254254
std::vector<std::string> &Includes,
255255
DiagnosticsEngine &Diags);

clang/include/clang/Sema/Sema.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12505,7 +12505,7 @@ class Sema final {
1250512505
void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
1250612506
const ArraySubscriptExpr *ASE=nullptr,
1250712507
bool AllowOnePastEnd=true, bool IndexNegated=false);
12508-
void CheckArrayAccess(const Expr *E, int AllowOnePastEnd = 0);
12508+
void CheckArrayAccess(const Expr *E);
1250912509
// Used to grab the relevant information from a FormatAttr and a
1251012510
// FunctionDeclaration.
1251112511
struct FormatStringInfo {

clang/lib/CodeGen/CodeGenModule.cpp

+37-68
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,37 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
15251525
QualType ty = parm->getType();
15261526
std::string typeQuals;
15271527

1528+
// Get image and pipe access qualifier:
1529+
if (ty->isImageType() || ty->isPipeType()) {
1530+
const Decl *PDecl = parm;
1531+
if (auto *TD = dyn_cast<TypedefType>(ty))
1532+
PDecl = TD->getDecl();
1533+
const OpenCLAccessAttr *A = PDecl->getAttr<OpenCLAccessAttr>();
1534+
if (A && A->isWriteOnly())
1535+
accessQuals.push_back(llvm::MDString::get(VMContext, "write_only"));
1536+
else if (A && A->isReadWrite())
1537+
accessQuals.push_back(llvm::MDString::get(VMContext, "read_write"));
1538+
else
1539+
accessQuals.push_back(llvm::MDString::get(VMContext, "read_only"));
1540+
} else
1541+
accessQuals.push_back(llvm::MDString::get(VMContext, "none"));
1542+
1543+
// Get argument name.
1544+
argNames.push_back(llvm::MDString::get(VMContext, parm->getName()));
1545+
1546+
auto getTypeSpelling = [&](QualType Ty) {
1547+
auto typeName = Ty.getUnqualifiedType().getAsString(Policy);
1548+
1549+
if (Ty.isCanonical()) {
1550+
StringRef typeNameRef = typeName;
1551+
// Turn "unsigned type" to "utype"
1552+
if (typeNameRef.consume_front("unsigned "))
1553+
return std::string("u") + typeNameRef.str();
1554+
}
1555+
1556+
return typeName;
1557+
};
1558+
15281559
if (ty->isPointerType()) {
15291560
QualType pointeeTy = ty->getPointeeType();
15301561

@@ -1534,26 +1565,10 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
15341565
ArgInfoAddressSpace(pointeeTy.getAddressSpace()))));
15351566

15361567
// Get argument type name.
1537-
std::string typeName =
1538-
pointeeTy.getUnqualifiedType().getAsString(Policy) + "*";
1539-
1540-
// Turn "unsigned type" to "utype"
1541-
std::string::size_type pos = typeName.find("unsigned");
1542-
if (pointeeTy.isCanonical() && pos != std::string::npos)
1543-
typeName.erase(pos + 1, 8);
1544-
1545-
argTypeNames.push_back(llvm::MDString::get(VMContext, typeName));
1546-
1568+
std::string typeName = getTypeSpelling(pointeeTy) + "*";
15471569
std::string baseTypeName =
1548-
pointeeTy.getUnqualifiedType().getCanonicalType().getAsString(
1549-
Policy) +
1550-
"*";
1551-
1552-
// Turn "unsigned type" to "utype"
1553-
pos = baseTypeName.find("unsigned");
1554-
if (pos != std::string::npos)
1555-
baseTypeName.erase(pos + 1, 8);
1556-
1570+
getTypeSpelling(pointeeTy.getCanonicalType()) + "*";
1571+
argTypeNames.push_back(llvm::MDString::get(VMContext, typeName));
15571572
argBaseTypeNames.push_back(
15581573
llvm::MDString::get(VMContext, baseTypeName));
15591574

@@ -1575,30 +1590,9 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
15751590
llvm::ConstantAsMetadata::get(CGF->Builder.getInt32(AddrSpc)));
15761591

15771592
// Get argument type name.
1578-
std::string typeName;
1579-
if (isPipe)
1580-
typeName = ty.getCanonicalType()
1581-
->castAs<PipeType>()
1582-
->getElementType()
1583-
.getAsString(Policy);
1584-
else
1585-
typeName = ty.getUnqualifiedType().getAsString(Policy);
1586-
1587-
// Turn "unsigned type" to "utype"
1588-
std::string::size_type pos = typeName.find("unsigned");
1589-
if (ty.isCanonical() && pos != std::string::npos)
1590-
typeName.erase(pos + 1, 8);
1591-
1592-
std::string baseTypeName;
1593-
if (isPipe)
1594-
baseTypeName = ty.getCanonicalType()
1595-
->castAs<PipeType>()
1596-
->getElementType()
1597-
.getCanonicalType()
1598-
.getAsString(Policy);
1599-
else
1600-
baseTypeName =
1601-
ty.getUnqualifiedType().getCanonicalType().getAsString(Policy);
1593+
ty = isPipe ? ty->castAs<PipeType>()->getElementType() : ty;
1594+
std::string typeName = getTypeSpelling(ty);
1595+
std::string baseTypeName = getTypeSpelling(ty.getCanonicalType());
16021596

16031597
// Remove access qualifiers on images
16041598
// (as they are inseparable from type in clang implementation,
@@ -1610,39 +1604,14 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
16101604
}
16111605

16121606
argTypeNames.push_back(llvm::MDString::get(VMContext, typeName));
1613-
1614-
// Turn "unsigned type" to "utype"
1615-
pos = baseTypeName.find("unsigned");
1616-
if (pos != std::string::npos)
1617-
baseTypeName.erase(pos + 1, 8);
1618-
16191607
argBaseTypeNames.push_back(
16201608
llvm::MDString::get(VMContext, baseTypeName));
16211609

16221610
if (isPipe)
16231611
typeQuals = "pipe";
16241612
}
1625-
16261613
argTypeQuals.push_back(llvm::MDString::get(VMContext, typeQuals));
16271614

1628-
// Get image and pipe access qualifier:
1629-
if (ty->isImageType() || ty->isPipeType()) {
1630-
const Decl *PDecl = parm;
1631-
if (auto *TD = dyn_cast<TypedefType>(ty))
1632-
PDecl = TD->getDecl();
1633-
const OpenCLAccessAttr *A = PDecl->getAttr<OpenCLAccessAttr>();
1634-
if (A && A->isWriteOnly())
1635-
accessQuals.push_back(llvm::MDString::get(VMContext, "write_only"));
1636-
else if (A && A->isReadWrite())
1637-
accessQuals.push_back(llvm::MDString::get(VMContext, "read_write"));
1638-
else
1639-
accessQuals.push_back(llvm::MDString::get(VMContext, "read_only"));
1640-
} else
1641-
accessQuals.push_back(llvm::MDString::get(VMContext, "none"));
1642-
1643-
// Get argument name.
1644-
argNames.push_back(llvm::MDString::get(VMContext, parm->getName()));
1645-
16461615
auto *SYCLBufferLocationAttr =
16471616
parm->getAttr<SYCLIntelBufferLocationAttr>();
16481617
argSYCLBufferLocationAttr.push_back(

clang/lib/Frontend/CompilerInvocation.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -2651,10 +2651,12 @@ static void GenerateLangArgs(const LangOptions &Opts,
26512651
GenerateArg(Args, OPT_fdeclare_opencl_builtins, SA);
26522652
}
26532653

2654-
void CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
2654+
bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
26552655
InputKind IK, const llvm::Triple &T,
26562656
std::vector<std::string> &Includes,
26572657
DiagnosticsEngine &Diags) {
2658+
unsigned NumErrorsBefore = Diags.getNumErrors();
2659+
26582660
// FIXME: Cleanup per-file based stuff.
26592661
LangStandard::Kind LangStd = LangStandard::lang_unspecified;
26602662
if (const Arg *A = Args.getLastArg(OPT_std_EQ)) {
@@ -3106,6 +3108,8 @@ void CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
31063108
}
31073109
}
31083110
}
3111+
3112+
return Success && Diags.getNumErrors() == NumErrorsBefore;
31093113
}
31103114

31113115
static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
@@ -3446,8 +3450,8 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
34463450
} else {
34473451
// Other LangOpts are only initialized when the input is not AST or LLVM IR.
34483452
// FIXME: Should we really be calling this for an Language::Asm input?
3449-
ParseLangArgs(LangOpts, Args, DashX, T, Res.getPreprocessorOpts().Includes,
3450-
Diags);
3453+
Success &= ParseLangArgs(LangOpts, Args, DashX, T,
3454+
Res.getPreprocessorOpts().Includes, Diags);
34513455
if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
34523456
LangOpts.ObjCExceptions = 1;
34533457
if (T.isOSDarwin() && DashX.isPreprocessed()) {

clang/lib/Sema/SemaChecking.cpp

+55-56
Original file line numberDiff line numberDiff line change
@@ -14526,63 +14526,62 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
1452614526
PDiag(diag::note_array_declared_here) << ND);
1452714527
}
1452814528

14529-
void Sema::CheckArrayAccess(const Expr *expr, int AllowOnePastEnd) {
14530-
if (!expr)
14531-
return;
14532-
14533-
expr = expr->IgnoreParenCasts();
14534-
switch (expr->getStmtClass()) {
14535-
case Stmt::ArraySubscriptExprClass: {
14536-
const ArraySubscriptExpr *ASE = cast<ArraySubscriptExpr>(expr);
14537-
CheckArrayAccess(ASE->getBase(), ASE->getIdx(), ASE, AllowOnePastEnd > 0);
14538-
CheckArrayAccess(ASE->getBase(), AllowOnePastEnd);
14539-
return;
14540-
}
14541-
case Stmt::MemberExprClass: {
14542-
expr = cast<MemberExpr>(expr)->getBase();
14543-
CheckArrayAccess(expr, /*AllowOnePastEnd=*/0);
14544-
return;
14545-
}
14546-
case Stmt::OMPArraySectionExprClass: {
14547-
const OMPArraySectionExpr *ASE = cast<OMPArraySectionExpr>(expr);
14548-
if (ASE->getLowerBound())
14549-
CheckArrayAccess(ASE->getBase(), ASE->getLowerBound(),
14550-
/*ASE=*/nullptr, AllowOnePastEnd > 0);
14551-
return;
14552-
}
14553-
case Stmt::UnaryOperatorClass: {
14554-
// Only unwrap the * and & unary operators
14555-
const UnaryOperator *UO = cast<UnaryOperator>(expr);
14556-
expr = UO->getSubExpr();
14557-
switch (UO->getOpcode()) {
14558-
case UO_AddrOf:
14559-
AllowOnePastEnd++;
14560-
break;
14561-
case UO_Deref:
14562-
AllowOnePastEnd--;
14563-
break;
14564-
default:
14565-
return;
14529+
void Sema::CheckArrayAccess(const Expr *expr) {
14530+
int AllowOnePastEnd = 0;
14531+
while (expr) {
14532+
expr = expr->IgnoreParenImpCasts();
14533+
switch (expr->getStmtClass()) {
14534+
case Stmt::ArraySubscriptExprClass: {
14535+
const ArraySubscriptExpr *ASE = cast<ArraySubscriptExpr>(expr);
14536+
CheckArrayAccess(ASE->getBase(), ASE->getIdx(), ASE,
14537+
AllowOnePastEnd > 0);
14538+
expr = ASE->getBase();
14539+
break;
14540+
}
14541+
case Stmt::MemberExprClass: {
14542+
expr = cast<MemberExpr>(expr)->getBase();
14543+
break;
14544+
}
14545+
case Stmt::OMPArraySectionExprClass: {
14546+
const OMPArraySectionExpr *ASE = cast<OMPArraySectionExpr>(expr);
14547+
if (ASE->getLowerBound())
14548+
CheckArrayAccess(ASE->getBase(), ASE->getLowerBound(),
14549+
/*ASE=*/nullptr, AllowOnePastEnd > 0);
14550+
return;
14551+
}
14552+
case Stmt::UnaryOperatorClass: {
14553+
// Only unwrap the * and & unary operators
14554+
const UnaryOperator *UO = cast<UnaryOperator>(expr);
14555+
expr = UO->getSubExpr();
14556+
switch (UO->getOpcode()) {
14557+
case UO_AddrOf:
14558+
AllowOnePastEnd++;
14559+
break;
14560+
case UO_Deref:
14561+
AllowOnePastEnd--;
14562+
break;
14563+
default:
14564+
return;
14565+
}
14566+
break;
14567+
}
14568+
case Stmt::ConditionalOperatorClass: {
14569+
const ConditionalOperator *cond = cast<ConditionalOperator>(expr);
14570+
if (const Expr *lhs = cond->getLHS())
14571+
CheckArrayAccess(lhs);
14572+
if (const Expr *rhs = cond->getRHS())
14573+
CheckArrayAccess(rhs);
14574+
return;
14575+
}
14576+
case Stmt::CXXOperatorCallExprClass: {
14577+
const auto *OCE = cast<CXXOperatorCallExpr>(expr);
14578+
for (const auto *Arg : OCE->arguments())
14579+
CheckArrayAccess(Arg);
14580+
return;
14581+
}
14582+
default:
14583+
return;
1456614584
}
14567-
CheckArrayAccess(expr, AllowOnePastEnd);
14568-
return;
14569-
}
14570-
case Stmt::ConditionalOperatorClass: {
14571-
const ConditionalOperator *cond = cast<ConditionalOperator>(expr);
14572-
if (const Expr *lhs = cond->getLHS())
14573-
CheckArrayAccess(lhs, AllowOnePastEnd);
14574-
if (const Expr *rhs = cond->getRHS())
14575-
CheckArrayAccess(rhs, AllowOnePastEnd);
14576-
return;
14577-
}
14578-
case Stmt::CXXOperatorCallExprClass: {
14579-
const auto *OCE = cast<CXXOperatorCallExpr>(expr);
14580-
for (const auto *Arg : OCE->arguments())
14581-
CheckArrayAccess(Arg);
14582-
return;
14583-
}
14584-
default:
14585-
return;
1458614585
}
1458714586
}
1458814587

clang/lib/Sema/SemaCodeComplete.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -5186,6 +5186,15 @@ void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
51865186
if (!Base || !CodeCompleter)
51875187
return;
51885188

5189+
// Peel off the ParenListExpr by chosing the last one, as they don't have a
5190+
// predefined type.
5191+
if (auto *PLE = llvm::dyn_cast<ParenListExpr>(Base))
5192+
Base = PLE->getExpr(PLE->getNumExprs() - 1);
5193+
if (OtherOpBase) {
5194+
if (auto *PLE = llvm::dyn_cast<ParenListExpr>(OtherOpBase))
5195+
OtherOpBase = PLE->getExpr(PLE->getNumExprs() - 1);
5196+
}
5197+
51895198
ExprResult ConvertedBase = PerformMemberExprBaseConversion(Base, IsArrow);
51905199
if (ConvertedBase.isInvalid())
51915200
return;
@@ -5615,12 +5624,17 @@ ProduceSignatureHelp(Sema &SemaRef, Scope *S,
56155624
QualType Sema::ProduceCallSignatureHelp(Scope *S, Expr *Fn,
56165625
ArrayRef<Expr *> Args,
56175626
SourceLocation OpenParLoc) {
5618-
if (!CodeCompleter)
5627+
if (!CodeCompleter || !Fn)
56195628
return QualType();
56205629

5630+
// If we have a ParenListExpr for LHS, peel it off by chosing the last expr.
5631+
// As ParenListExprs don't have a predefined type.
5632+
if (auto *PLE = llvm::dyn_cast<ParenListExpr>(Fn))
5633+
Fn = PLE->getExpr(PLE->getNumExprs() - 1);
5634+
56215635
// FIXME: Provide support for variadic template functions.
56225636
// Ignore type-dependent call expressions entirely.
5623-
if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args))
5637+
if (Fn->isTypeDependent() || anyNullArguments(Args))
56245638
return QualType();
56255639
// In presence of dependent args we surface all possible signatures using the
56265640
// non-dependent args in the prefix. Afterwards we do a post filtering to make

clang/test/CodeCompletion/function-overloads.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace NS {
2121
void test_adl() {
2222
NS::X x;
2323
g(x, x);
24+
(void)(f)(1, 2, 3);
25+
(void)(test, test, test, f)(1, 2, 3);
2426
}
2527

2628
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:9 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
@@ -31,6 +33,10 @@ void test_adl() {
3133
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:21 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
3234
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:23:7 %s -o - | \
3335
// RUN: FileCheck -check-prefix=CHECK-CC5 %s
36+
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:24:13 %s -o - | \
37+
// RUN: FileCheck -check-prefix=CHECK-CC1 %s
38+
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:25:31 %s -o - | \
39+
// RUN: FileCheck -check-prefix=CHECK-CC1 %s
3440
// CHECK-CC1: OVERLOAD: [#int#]f(<#float x#>, float y)
3541
// CHECK-CC1: OVERLOAD: [#int#]f(<#int i#>)
3642
// CHECK-CC1-NOT, CHECK-CC2-NOT: OVERLOAD: A(

clang/test/CodeCompletion/member-access.c

+7
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ void test3(struct Point2 *p) {
2929

3030
// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:24:5 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
3131
// CHECK-CC3: x (requires fix-it: {24:4-24:5} to "->")
32+
33+
void test4(struct Point *p) {
34+
(int)(p)->x;
35+
(int)(0,1,2,3,4,p)->x;
36+
}
37+
// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:34:13 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
38+
// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:35:23 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s

0 commit comments

Comments
 (0)