Skip to content

Commit a41cf8a

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project into res-create-1-add-methods
2 parents dfc07bd + db3054a commit a41cf8a

File tree

93 files changed

+2473
-1436
lines changed

Some content is hidden

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

93 files changed

+2473
-1436
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,45 +3752,45 @@ functions intended for different purposes have distinct CFI identities.
37523752

37533753
// Header file - define convenience macros
37543754
#define __cfi_salt(s) __attribute__((cfi_salt(s)))
3755-
3755+
37563756
// Typedef for regular function pointers
37573757
typedef int (*fptr_t)(void);
3758-
3759-
// Typedef for salted function pointers
3758+
3759+
// Typedef for salted function pointers
37603760
typedef int (*fptr_salted_t)(void) __cfi_salt("pepper");
3761-
3761+
37623762
struct widget_ops {
37633763
fptr_t init; // Regular CFI
37643764
fptr_salted_t exec; // Salted CFI
37653765
fptr_t cleanup; // Regular CFI
37663766
};
3767-
3767+
37683768
// Function implementations
37693769
static int widget_init(void) { return 0; }
37703770
static int widget_exec(void) __cfi_salt("pepper") { return 1; }
37713771
static int widget_cleanup(void) { return 0; }
3772-
3772+
37733773
static struct widget_ops ops = {
37743774
.init = widget_init, // OK - compatible types
37753775
.exec = widget_exec, // OK - both use "pepper" salt
37763776
.cleanup = widget_cleanup // OK - compatible types
37773777
};
3778-
3778+
37793779
// Using C++11 attribute syntax
37803780
void secure_callback(void) [[clang::cfi_salt("secure")]];
3781-
3781+
37823782
// This would cause a compilation error:
37833783
// fptr_t bad_ptr = widget_exec; // Error: incompatible types
37843784

37853785
**Notes:**
37863786

37873787
* The salt string can contain non-NULL ASCII characters, including spaces and
37883788
quotes
3789-
* This attribute only applies to function types; using it on non-function
3789+
* This attribute only applies to function types; using it on non-function
37903790
types will generate a warning
3791-
* All declarations and definitions of the same function must use identical
3791+
* All declarations and definitions of the same function must use identical
37923792
salt values
3793-
* The attribute affects type compatibility during compilation and CFI hash
3793+
* The attribute affects type compatibility during compilation and CFI hash
37943794
generation during code generation
37953795
}];
37963796
}

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5363,7 +5363,7 @@ class Sema final : public SemaBase {
53635363
SourceLocation UsingLoc,
53645364
SourceLocation EnumLoc, SourceRange TyLoc,
53655365
const IdentifierInfo &II, ParsedType Ty,
5366-
CXXScopeSpec *SS = nullptr);
5366+
const CXXScopeSpec &SS);
53675367
Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS,
53685368
MultiTemplateParamsArg TemplateParams,
53695369
SourceLocation UsingLoc, UnqualifiedId &Name,

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration(
672672
/*WantNontrivialTypeSourceInfo=*/true);
673673

674674
UED = Actions.ActOnUsingEnumDeclaration(
675-
getCurScope(), AS, UsingLoc, UELoc, IdentLoc, *IdentInfo, Type, &SS);
675+
getCurScope(), AS, UsingLoc, UELoc, IdentLoc, *IdentInfo, Type, SS);
676676
} else if (Tok.is(tok::annot_template_id)) {
677677
TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
678678

@@ -687,7 +687,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration(
687687

688688
UED = Actions.ActOnUsingEnumDeclaration(getCurScope(), AS, UsingLoc,
689689
UELoc, Loc, *TemplateId->Name,
690-
Type.get(), &SS);
690+
Type.get(), SS);
691691
} else {
692692
Diag(Tok.getLocation(), diag::err_using_enum_not_enum)
693693
<< TemplateId->Name->getName()

clang/lib/Sema/SemaCXXScopeSpec.cpp

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,54 @@ class NestedNameSpecifierValidatorCCC final
398398

399399
}
400400

401+
[[nodiscard]] static bool ExtendNestedNameSpecifier(Sema &S, CXXScopeSpec &SS,
402+
const NamedDecl *ND,
403+
SourceLocation NameLoc,
404+
SourceLocation CCLoc) {
405+
TypeLocBuilder TLB;
406+
QualType T;
407+
if (const auto *USD = dyn_cast<UsingShadowDecl>(ND)) {
408+
T = S.Context.getUsingType(ElaboratedTypeKeyword::None, SS.getScopeRep(),
409+
USD);
410+
TLB.push<UsingTypeLoc>(T).set(/*ElaboratedKeywordLoc=*/SourceLocation(),
411+
SS.getWithLocInContext(S.Context), NameLoc);
412+
} else if (const auto *TD = dyn_cast<TypeDecl>(ND)) {
413+
T = S.Context.getTypeDeclType(ElaboratedTypeKeyword::None, SS.getScopeRep(),
414+
TD);
415+
switch (T->getTypeClass()) {
416+
case Type::Record:
417+
case Type::InjectedClassName:
418+
case Type::Enum: {
419+
auto TTL = TLB.push<TagTypeLoc>(T);
420+
TTL.setElaboratedKeywordLoc(SourceLocation());
421+
TTL.setQualifierLoc(SS.getWithLocInContext(S.Context));
422+
TTL.setNameLoc(NameLoc);
423+
break;
424+
}
425+
case Type::Typedef:
426+
TLB.push<TypedefTypeLoc>(T).set(/*ElaboratedKeywordLoc=*/SourceLocation(),
427+
SS.getWithLocInContext(S.Context),
428+
NameLoc);
429+
break;
430+
case Type::UnresolvedUsing:
431+
TLB.push<UnresolvedUsingTypeLoc>(T).set(
432+
/*ElaboratedKeywordLoc=*/SourceLocation(),
433+
SS.getWithLocInContext(S.Context), NameLoc);
434+
break;
435+
default:
436+
assert(SS.isEmpty());
437+
T = S.Context.getTypeDeclType(TD);
438+
TLB.pushTypeSpec(T).setNameLoc(NameLoc);
439+
break;
440+
}
441+
} else {
442+
return false;
443+
}
444+
SS.clear();
445+
SS.Make(S.Context, TLB.getTypeLocInContext(S.Context, T), CCLoc);
446+
return true;
447+
}
448+
401449
bool Sema::BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo,
402450
bool EnteringContext, CXXScopeSpec &SS,
403451
NamedDecl *ScopeLookupResult,
@@ -653,40 +701,9 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo,
653701
if (isa<EnumDecl>(TD))
654702
Diag(IdInfo.IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec);
655703

656-
QualType T;
657-
TypeLocBuilder TLB;
658-
if (const auto *USD = dyn_cast<UsingShadowDecl>(SD)) {
659-
T = Context.getUsingType(ElaboratedTypeKeyword::None, SS.getScopeRep(),
660-
USD);
661-
TLB.push<UsingTypeLoc>(T).set(/*ElaboratedKeywordLoc=*/SourceLocation(),
662-
SS.getWithLocInContext(Context),
663-
IdInfo.IdentifierLoc);
664-
} else if (const auto *Tag = dyn_cast<TagDecl>(TD)) {
665-
T = Context.getTagType(ElaboratedTypeKeyword::None, SS.getScopeRep(), Tag,
666-
/*OwnsTag=*/false);
667-
auto TTL = TLB.push<TagTypeLoc>(T);
668-
TTL.setElaboratedKeywordLoc(SourceLocation());
669-
TTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
670-
TTL.setNameLoc(IdInfo.IdentifierLoc);
671-
} else if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
672-
T = Context.getTypedefType(ElaboratedTypeKeyword::None, SS.getScopeRep(),
673-
TN);
674-
TLB.push<TypedefTypeLoc>(T).set(/*ElaboratedKeywordLoc=*/SourceLocation(),
675-
SS.getWithLocInContext(SemaRef.Context),
676-
IdInfo.IdentifierLoc);
677-
} else if (auto *UD = dyn_cast<UnresolvedUsingTypenameDecl>(TD)) {
678-
T = Context.getUnresolvedUsingType(ElaboratedTypeKeyword::None,
679-
SS.getScopeRep(), UD);
680-
TLB.push<UnresolvedUsingTypeLoc>(T).set(
681-
/*ElaboratedKeywordLoc=*/SourceLocation(),
682-
SS.getWithLocInContext(SemaRef.Context), IdInfo.IdentifierLoc);
683-
} else {
684-
assert(SS.isEmpty());
685-
T = Context.getTypeDeclType(TD);
686-
TLB.pushTypeSpec(T).setNameLoc(IdInfo.IdentifierLoc);
687-
}
688-
SS.clear();
689-
SS.Make(Context, TLB.getTypeLocInContext(Context, T), IdInfo.CCLoc);
704+
[[maybe_unused]] bool IsType = ::ExtendNestedNameSpecifier(
705+
*this, SS, SD, IdInfo.IdentifierLoc, IdInfo.CCLoc);
706+
assert(IsType && "unhandled declaration kind");
690707
return false;
691708
}
692709

@@ -762,21 +779,16 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo,
762779
}
763780

764781
if (!Found.empty()) {
765-
if (TypeDecl *TD = Found.getAsSingle<TypeDecl>()) {
766-
QualType T;
767-
if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
768-
T = Context.getTypedefType(ElaboratedTypeKeyword::None,
769-
SS.getScopeRep(), TN);
770-
} else {
771-
// FIXME: Enumerate the possibilities here.
772-
assert(!isa<TagDecl>(TD));
773-
assert(SS.isEmpty());
774-
T = Context.getTypeDeclType(TD);
775-
}
776-
782+
const auto *ND = Found.getAsSingle<NamedDecl>();
783+
if (::ExtendNestedNameSpecifier(*this, SS, ND, IdInfo.IdentifierLoc,
784+
IdInfo.CCLoc)) {
785+
const Type *T = SS.getScopeRep().getAsType();
777786
Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
778-
<< T << getLangOpts().CPlusPlus;
779-
} else if (Found.getAsSingle<TemplateDecl>()) {
787+
<< QualType(T, 0) << getLangOpts().CPlusPlus;
788+
// Recover with this type if it would be a valid nested name specifier.
789+
return !T->getAsCanonical<TagType>();
790+
}
791+
if (isa<TemplateDecl>(ND)) {
780792
ParsedType SuggestedType;
781793
DiagnoseUnknownTypeName(IdInfo.Identifier, IdInfo.IdentifierLoc, S, &SS,
782794
SuggestedType);

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12628,16 +12628,17 @@ Decl *Sema::ActOnUsingEnumDeclaration(Scope *S, AccessSpecifier AS,
1262812628
SourceLocation UsingLoc,
1262912629
SourceLocation EnumLoc, SourceRange TyLoc,
1263012630
const IdentifierInfo &II, ParsedType Ty,
12631-
CXXScopeSpec *SS) {
12632-
assert(SS && !SS->isInvalid() && "ScopeSpec is invalid");
12631+
const CXXScopeSpec &SS) {
1263312632
TypeSourceInfo *TSI = nullptr;
1263412633
SourceLocation IdentLoc = TyLoc.getBegin();
1263512634
QualType EnumTy = GetTypeFromParser(Ty, &TSI);
1263612635
if (EnumTy.isNull()) {
12637-
Diag(IdentLoc, isDependentScopeSpecifier(*SS)
12636+
Diag(IdentLoc, isDependentScopeSpecifier(SS)
1263812637
? diag::err_using_enum_is_dependent
1263912638
: diag::err_unknown_typename)
12640-
<< II.getName() << SourceRange(SS->getBeginLoc(), TyLoc.getEnd());
12639+
<< II.getName()
12640+
<< SourceRange(SS.isValid() ? SS.getBeginLoc() : IdentLoc,
12641+
TyLoc.getEnd());
1264112642
return nullptr;
1264212643
}
1264312644

clang/test/SemaCXX/GH156458.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
2+
3+
// Force a fatal error
4+
#include <unknownheader> // expected-error {{file not found}}
5+
6+
namespace N {}
7+
8+
enum class E {};
9+
using enum N::E::V;
10+
11+
using T = int;
12+
using enum N::T::v;

compiler-rt/lib/asan/asan_malloc_win.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,22 @@ void *SharedReAlloc(ReAllocFunction reallocFunc, SizeFunction heapSizeFunc,
322322
}
323323
}
324324

325+
if (dwFlags & HEAP_REALLOC_IN_PLACE_ONLY) {
326+
size_t old_usable_size = asan_malloc_usable_size(lpMem, pc, bp);
327+
if (dwBytes == old_usable_size) {
328+
// Nothing to change, return the current pointer.
329+
return lpMem;
330+
} else if (dwBytes >= old_usable_size) {
331+
// Growing with HEAP_REALLOC_IN_PLACE_ONLY is not supported.
332+
return nullptr;
333+
} else {
334+
// Shrinking with HEAP_REALLOC_IN_PLACE_ONLY is not yet supported.
335+
// For now return the current pointer and
336+
// leave the allocation size as it is.
337+
return lpMem;
338+
}
339+
}
340+
325341
if (ownershipState == ASAN && !only_asan_supported_flags) {
326342
// Conversion to unsupported flags allocation,
327343
// transfer this allocation back to the original allocator.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// RUN: %clang_cl_asan %Od %s %Fe%t %MD
2+
// RUN: %env_asan_opts=windows_hook_rtl_allocators=true not %run %t 2>&1 | FileCheck %s
3+
4+
#include <stdio.h>
5+
#include <windows.h>
6+
7+
using AllocateFunctionPtr = PVOID(__stdcall *)(PVOID, ULONG, SIZE_T);
8+
using ReAllocateFunctionPtr = PVOID(__stdcall *)(PVOID, ULONG, PVOID, SIZE_T);
9+
using FreeFunctionPtr = PVOID(__stdcall *)(PVOID, ULONG, PVOID);
10+
11+
int main() {
12+
HMODULE NtDllHandle = GetModuleHandle("ntdll.dll");
13+
if (!NtDllHandle) {
14+
fputs("Couldn't load ntdll??\n", stderr);
15+
return -1;
16+
}
17+
18+
auto RtlAllocateHeap_ptr =
19+
(AllocateFunctionPtr)GetProcAddress(NtDllHandle, "RtlAllocateHeap");
20+
if (RtlAllocateHeap_ptr == 0) {
21+
fputs("Couldn't RtlAllocateHeap\n", stderr);
22+
return -1;
23+
}
24+
25+
auto RtlReAllocateHeap_ptr =
26+
(ReAllocateFunctionPtr)GetProcAddress(NtDllHandle, "RtlReAllocateHeap");
27+
if (RtlReAllocateHeap_ptr == 0) {
28+
fputs("Couldn't find RtlReAllocateHeap\n", stderr);
29+
return -1;
30+
}
31+
32+
auto RtlFreeHeap_ptr =
33+
(FreeFunctionPtr)GetProcAddress(NtDllHandle, "RtlFreeHeap");
34+
if (RtlFreeHeap_ptr == 0) {
35+
fputs("Couldn't RtlFreeHeap\n", stderr);
36+
return -1;
37+
}
38+
39+
char *ptr1;
40+
char *ptr2;
41+
ptr2 = ptr1 = (char *)RtlAllocateHeap_ptr(GetProcessHeap(), 0, 15);
42+
if (ptr1)
43+
fputs("Okay alloc\n", stderr);
44+
// CHECK: Okay alloc
45+
46+
// TODO: Growing is currently not supported
47+
ptr2 = (char *)RtlReAllocateHeap_ptr(GetProcessHeap(),
48+
HEAP_REALLOC_IN_PLACE_ONLY, ptr1, 23);
49+
if (ptr2 == NULL)
50+
fputs("Okay grow failed\n", stderr);
51+
// CHECK: Okay grow failed
52+
53+
// TODO: Shrinking is currently not supported
54+
ptr2 = (char *)RtlReAllocateHeap_ptr(GetProcessHeap(),
55+
HEAP_REALLOC_IN_PLACE_ONLY, ptr1, 7);
56+
if (ptr2 == ptr1)
57+
fputs("Okay shrinking return the original pointer\n", stderr);
58+
// CHECK: Okay shrinking return the original pointer
59+
60+
ptr1[7] = 'a';
61+
fputs("Okay 7\n", stderr);
62+
// CHECK: Okay 7
63+
64+
// TODO: Writing behind the shrinked part is currently not detected.
65+
// Therefore test writing behind the original allocation for now.
66+
ptr1[16] = 'a';
67+
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
68+
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
69+
70+
RtlFreeHeap_ptr(GetProcessHeap(), 0, ptr1);
71+
}

flang/include/flang/Evaluate/tools.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,12 @@ class Scope;
15311531
// point to its subprogram.
15321532
const Symbol *GetMainEntry(const Symbol *);
15331533

1534+
inline bool IsAlternateEntry(const Symbol *symbol) {
1535+
// If symbol is not alternate entry symbol, GetMainEntry() returns the same
1536+
// symbol.
1537+
return symbol && GetMainEntry(symbol) != symbol;
1538+
}
1539+
15341540
// These functions are used in Evaluate so they are defined here rather than in
15351541
// Semantics to avoid a link-time dependency on Semantics.
15361542
// All of these apply GetUltimate() or ResolveAssociations() to their arguments.

flang/lib/Semantics/check-declarations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2950,7 +2950,7 @@ static bool IsSubprogramDefinition(const Symbol &symbol) {
29502950

29512951
static bool IsExternalProcedureDefinition(const Symbol &symbol) {
29522952
return IsBlockData(symbol) ||
2953-
(IsSubprogramDefinition(symbol) &&
2953+
((IsSubprogramDefinition(symbol) || IsAlternateEntry(&symbol)) &&
29542954
(IsExternal(symbol) || symbol.GetBindName()));
29552955
}
29562956

0 commit comments

Comments
 (0)