Skip to content

Commit 68789c0

Browse files
author
z1.cciauto
committed
merge main into amd-staging
2 parents ae3ea5c + 0e0b501 commit 68789c0

File tree

47 files changed

+11354
-1848
lines changed

Some content is hidden

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

47 files changed

+11354
-1848
lines changed

clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,113 @@ class MustacheTemplateFile : public Template {
7070
MustacheTemplateFile(StringRef TemplateStr) : Template(TemplateStr) {}
7171
};
7272

73+
static std::unique_ptr<MustacheTemplateFile> NamespaceTemplate = nullptr;
74+
75+
static std::unique_ptr<MustacheTemplateFile> RecordTemplate = nullptr;
76+
77+
static Error setupTemplateFiles(const clang::doc::ClangDocContext &CDCtx) {
78+
return Error::success();
79+
}
80+
7381
Error MustacheHTMLGenerator::generateDocs(
7482
StringRef RootDir, StringMap<std::unique_ptr<doc::Info>> Infos,
7583
const clang::doc::ClangDocContext &CDCtx) {
84+
if (auto Err = setupTemplateFiles(CDCtx))
85+
return Err;
86+
// Track which directories we already tried to create.
87+
StringSet<> CreatedDirs;
88+
// Collect all output by file name and create the necessary directories.
89+
StringMap<std::vector<doc::Info *>> FileToInfos;
90+
for (const auto &Group : Infos) {
91+
doc::Info *Info = Group.getValue().get();
92+
93+
SmallString<128> Path;
94+
sys::path::native(RootDir, Path);
95+
sys::path::append(Path, Info->getRelativeFilePath(""));
96+
if (!CreatedDirs.contains(Path)) {
97+
if (std::error_code EC = sys::fs::create_directories(Path))
98+
return createStringError(EC, "failed to create directory '%s'.",
99+
Path.c_str());
100+
CreatedDirs.insert(Path);
101+
}
102+
103+
sys::path::append(Path, Info->getFileBaseName() + ".html");
104+
FileToInfos[Path].push_back(Info);
105+
}
106+
107+
for (const auto &Group : FileToInfos) {
108+
std::error_code FileErr;
109+
raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None);
110+
if (FileErr)
111+
return createFileOpenError(Group.getKey(), FileErr);
112+
113+
for (const auto &Info : Group.getValue())
114+
if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx))
115+
return Err;
116+
}
76117
return Error::success();
77118
}
78119

120+
static json::Value extractValue(const NamespaceInfo &I,
121+
const ClangDocContext &CDCtx) {
122+
Object NamespaceValue = Object();
123+
return NamespaceValue;
124+
}
125+
126+
static json::Value extractValue(const RecordInfo &I,
127+
const ClangDocContext &CDCtx) {
128+
Object RecordValue = Object();
129+
return RecordValue;
130+
}
131+
132+
static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V,
133+
Info *I) {
134+
return createStringError(inconvertibleErrorCode(),
135+
"setupTemplateValue is unimplemented");
136+
}
137+
79138
Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
80139
const ClangDocContext &CDCtx) {
140+
switch (I->IT) {
141+
case InfoType::IT_namespace: {
142+
json::Value V =
143+
extractValue(*static_cast<clang::doc::NamespaceInfo *>(I), CDCtx);
144+
if (auto Err = setupTemplateValue(CDCtx, V, I))
145+
return Err;
146+
NamespaceTemplate->render(V, OS);
147+
break;
148+
}
149+
case InfoType::IT_record: {
150+
json::Value V =
151+
extractValue(*static_cast<clang::doc::RecordInfo *>(I), CDCtx);
152+
if (auto Err = setupTemplateValue(CDCtx, V, I))
153+
return Err;
154+
// Serialize the JSON value to the output stream in a readable format.
155+
RecordTemplate->render(V, OS);
156+
break;
157+
}
158+
case InfoType::IT_enum:
159+
OS << "IT_enum\n";
160+
break;
161+
case InfoType::IT_function:
162+
OS << "IT_Function\n";
163+
break;
164+
case InfoType::IT_typedef:
165+
OS << "IT_typedef\n";
166+
break;
167+
case InfoType::IT_default:
168+
return createStringError(inconvertibleErrorCode(), "unexpected InfoType");
169+
}
81170
return Error::success();
82171
}
83172

84173
Error MustacheHTMLGenerator::createResources(ClangDocContext &CDCtx) {
174+
for (const auto &FilePath : CDCtx.UserStylesheets)
175+
if (Error Err = copyFile(FilePath, CDCtx.OutDirectory))
176+
return Err;
177+
for (const auto &FilePath : CDCtx.JsScripts)
178+
if (Error Err = copyFile(FilePath, CDCtx.OutDirectory))
179+
return Err;
85180
return Error::success();
86181
}
87182

clang-tools-extra/unittests/clang-doc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ clang_target_link_libraries(ClangDocTests
3434
clangTooling
3535
clangToolingCore
3636
)
37+
3738
target_link_libraries(ClangDocTests
3839
PRIVATE
3940
clangDoc

clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include "Generators.h"
1111
#include "Representation.h"
1212
#include "clang/Basic/Version.h"
13+
#include "llvm/Support/Path.h"
1314
#include "llvm/Testing/Support/Error.h"
15+
#include "llvm/Testing/Support/SupportHelpers.h"
1416
#include "gmock/gmock.h"
1517
#include "gtest/gtest.h"
1618

@@ -40,13 +42,43 @@ getClangDocContext(std::vector<std::string> UserStylesheets = {},
4042
return CDCtx;
4143
}
4244

45+
static void verifyFileContents(const Twine &Path, StringRef Contents) {
46+
auto Buffer = MemoryBuffer::getFile(Path);
47+
ASSERT_TRUE((bool)Buffer);
48+
StringRef Data = Buffer.get()->getBuffer();
49+
ASSERT_EQ(Data, Contents);
50+
}
51+
4352
TEST(HTMLMustacheGeneratorTest, createResources) {
4453
auto G = getHTMLMustacheGenerator();
4554
ASSERT_THAT(G, NotNull()) << "Could not find HTMLMustacheGenerator";
4655
ClangDocContext CDCtx = getClangDocContext();
56+
EXPECT_THAT_ERROR(G->createResources(CDCtx), Failed())
57+
<< "Empty UserStylesheets or JsScripts should fail!";
58+
59+
unittest::TempDir RootTestDirectory("createResourcesTest", /*Unique=*/true);
60+
CDCtx.OutDirectory = RootTestDirectory.path();
61+
62+
unittest::TempFile CSS("clang-doc-mustache", "css", "CSS");
63+
unittest::TempFile JS("mustache", "js", "JavaScript");
64+
65+
CDCtx.UserStylesheets[0] = CSS.path();
66+
CDCtx.JsScripts[0] = JS.path();
4767

4868
EXPECT_THAT_ERROR(G->createResources(CDCtx), Succeeded())
49-
<< "Failed to create resources.";
69+
<< "Failed to create resources with valid UserStylesheets and JsScripts";
70+
{
71+
SmallString<256> PathBuf;
72+
llvm::sys::path::append(PathBuf, RootTestDirectory.path(),
73+
"clang-doc-mustache.css");
74+
verifyFileContents(PathBuf, "CSS");
75+
}
76+
77+
{
78+
SmallString<256> PathBuf;
79+
llvm::sys::path::append(PathBuf, RootTestDirectory.path(), "mustache.js");
80+
verifyFileContents(PathBuf, "JavaScript");
81+
}
5082
}
5183

5284
TEST(HTMLMustacheGeneratorTest, generateDocs) {
@@ -79,8 +111,7 @@ TEST(HTMLMustacheGeneratorTest, generateDocsForInfo) {
79111
I.Children.Functions.back().Name = "OneFunction";
80112
I.Children.Enums.emplace_back();
81113

82-
EXPECT_THAT_ERROR(G->generateDocForInfo(&I, Actual, CDCtx), Succeeded())
83-
<< "Failed to generate docs.";
114+
EXPECT_THAT_ERROR(G->generateDocForInfo(&I, Actual, CDCtx), Failed());
84115

85116
std::string Expected = R"raw()raw";
86117
EXPECT_THAT(Actual.str(), Eq(Expected));

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,12 +600,27 @@ static bool isSafeArraySubscript(const ArraySubscriptExpr &Node,
600600
} else if (const auto *BE = dyn_cast<BinaryOperator>(IndexExpr)) {
601601
// For an integer expression `e` and an integer constant `n`, `e & n` and
602602
// `n & e` are bounded by `n`:
603-
if (BE->getOpcode() != BO_And)
603+
if (BE->getOpcode() != BO_And && BE->getOpcode() != BO_Rem)
604604
return false;
605605

606606
const Expr *LHS = BE->getLHS();
607607
const Expr *RHS = BE->getRHS();
608608

609+
if (BE->getOpcode() == BO_Rem) {
610+
// If n is a negative number, then n % const can be greater than const
611+
if (!LHS->getType()->isUnsignedIntegerType()) {
612+
return false;
613+
}
614+
615+
if (!RHS->isValueDependent() && RHS->EvaluateAsInt(EVResult, Ctx)) {
616+
llvm::APSInt result = EVResult.Val.getInt();
617+
if (result.isNonNegative() && result.getLimitedValue() <= limit)
618+
return true;
619+
}
620+
621+
return false;
622+
}
623+
609624
if ((!LHS->isValueDependent() &&
610625
LHS->EvaluateAsInt(EVResult, Ctx)) || // case: `n & e`
611626
(!RHS->isValueDependent() &&

clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,16 @@ class CIRGenFunctionInfo final
112112

113113
// NOLINTNEXTLINE(readability-identifier-naming)
114114
void Profile(llvm::FoldingSetNodeID &id) {
115-
id.AddBoolean(required.getOpaqueData());
116-
getReturnType().Profile(id);
115+
// It's unfortunate that we are looping over the arguments twice (here and
116+
// in the static Profile function we call from here), but if the Profile
117+
// functions get out of sync, we can end up with incorrect function
118+
// signatures, and we don't have the argument types in the format that the
119+
// static Profile function requires.
120+
llvm::SmallVector<CanQualType, 16> argTypes;
121+
for (const ArgInfo &argInfo : arguments())
122+
argTypes.push_back(argInfo.type);
123+
124+
Profile(id, required, getReturnType(), argTypes);
117125
}
118126

119127
llvm::ArrayRef<ArgInfo> arguments() const {

clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,21 @@ void constant_idx_safe0(unsigned idx) {
3535
buffer[0] = 0;
3636
}
3737

38-
int array[10]; // expected-warning {{'array' is an unsafe buffer that does not perform bounds checks}}
38+
int array[10]; // expected-warning 3{{'array' is an unsafe buffer that does not perform bounds checks}}
39+
40+
void circular_access_unsigned(unsigned idx) {
41+
array[idx % 10];
42+
array[idx % 11]; // expected-note {{used in buffer access here}}
43+
array[(idx + 3) % 10];
44+
array[(--idx) % 8];
45+
array[idx & 9 % 10];
46+
array[9 & idx % 11];
47+
array [12 % 10];
48+
}
49+
50+
void circular_access_signed(int idx) {
51+
array[idx % 10]; // expected-note {{used in buffer access here}}
52+
}
3953

4054
void masked_idx1(unsigned long long idx, Foo f) {
4155
// Bitwise and operation

lldb/docs/use/python.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,12 @@ decision to go right:
330330
process.Continue()
331331
else:
332332
print "Here is the problem; going right, should go left!"
333-
Just as a reminder, LLDB is going to take this script and wrap it up in a function, like this:
334333

335334

335+
Just as a reminder, LLDB is going to take this script and wrap it up in a function, like this:
336+
337+
::
338+
336339
def some_unique_and_obscure_function_name (frame, bp_loc):
337340
global path
338341
if path[0] == 'R':

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def __init__(
133133
self.output_condition = threading.Condition()
134134
self.output: dict[str, list[str]] = {}
135135
self.configuration_done_sent = False
136+
self.initialized = False
136137
self.frame_scopes = {}
137138
self.init_commands = init_commands
138139
self.disassembled_instructions = {}
@@ -235,6 +236,8 @@ def _handle_recv_packet(self, packet: Optional[ProtocolMessage]) -> bool:
235236
self.output_condition.release()
236237
# no need to add 'output' event packets to our packets list
237238
return keepGoing
239+
elif event == "initialized":
240+
self.initialized = True
238241
elif event == "process":
239242
# When a new process is attached or launched, remember the
240243
# details that are available in the body of the event
@@ -602,7 +605,7 @@ def request_attach(
602605
exitCommands: Optional[list[str]] = None,
603606
terminateCommands: Optional[list[str]] = None,
604607
coreFile: Optional[str] = None,
605-
stopOnAttach=True,
608+
stopOnEntry=False,
606609
sourceMap: Optional[Union[list[tuple[str, str]], dict[str, str]]] = None,
607610
gdbRemotePort: Optional[int] = None,
608611
gdbRemoteHostname: Optional[str] = None,
@@ -629,8 +632,8 @@ def request_attach(
629632
args_dict["attachCommands"] = attachCommands
630633
if coreFile:
631634
args_dict["coreFile"] = coreFile
632-
if stopOnAttach:
633-
args_dict["stopOnEntry"] = stopOnAttach
635+
if stopOnEntry:
636+
args_dict["stopOnEntry"] = stopOnEntry
634637
if postRunCommands:
635638
args_dict["postRunCommands"] = postRunCommands
636639
if sourceMap:
@@ -640,11 +643,7 @@ def request_attach(
640643
if gdbRemoteHostname is not None:
641644
args_dict["gdb-remote-hostname"] = gdbRemoteHostname
642645
command_dict = {"command": "attach", "type": "request", "arguments": args_dict}
643-
response = self.send_recv(command_dict)
644-
645-
if response["success"]:
646-
self.wait_for_event("process")
647-
return response
646+
return self.send_recv(command_dict)
648647

649648
def request_breakpointLocations(
650649
self, file_path, line, end_line=None, column=None, end_column=None
@@ -677,6 +676,7 @@ def request_configurationDone(self):
677676
response = self.send_recv(command_dict)
678677
if response:
679678
self.configuration_done_sent = True
679+
self.request_threads()
680680
return response
681681

682682
def _process_stopped(self):
@@ -824,7 +824,7 @@ def request_launch(
824824
args: Optional[list[str]] = None,
825825
cwd: Optional[str] = None,
826826
env: Optional[dict[str, str]] = None,
827-
stopOnEntry=True,
827+
stopOnEntry=False,
828828
disableASLR=True,
829829
disableSTDIO=False,
830830
shellExpandArguments=False,
@@ -894,11 +894,7 @@ def request_launch(
894894
if commandEscapePrefix is not None:
895895
args_dict["commandEscapePrefix"] = commandEscapePrefix
896896
command_dict = {"command": "launch", "type": "request", "arguments": args_dict}
897-
response = self.send_recv(command_dict)
898-
899-
if response["success"]:
900-
self.wait_for_event("process")
901-
return response
897+
return self.send_recv(command_dict)
902898

903899
def request_next(self, threadId, granularity="statement"):
904900
if self.exit_status is not None:

0 commit comments

Comments
 (0)