Skip to content

[Clang] fix crash in codegen caused by deferred asm diagnostics under -fopenmp #147163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ Bug Fixes in This Version
- Fixed an infinite recursion when checking constexpr destructors. (#GH141789)
- Fixed a crash when a malformed using declaration appears in a ``constexpr`` function. (#GH144264)
- Fixed a bug when use unicode character name in macro concatenation. (#GH145240)
- Fixed a crash caused by deferred diagnostics under ``-fopenmp``,
which resulted in passing invalid asm statements to codegen. (#GH140375)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
34 changes: 14 additions & 20 deletions clang/lib/Sema/SemaStmtAsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,9 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
TargetInfo::ConstraintInfo Info(ConstraintStr, OutputName);
if (!Context.getTargetInfo().validateOutputConstraint(Info) &&
!(LangOpts.HIPStdPar && LangOpts.CUDAIsDevice)) {
targetDiag(Constraint->getBeginLoc(),
diag::err_asm_invalid_output_constraint)
<< Info.getConstraintStr();
return CreateGCCAsmStmt();
return StmtError(targetDiag(Constraint->getBeginLoc(),
diag::err_asm_invalid_output_constraint)
<< Info.getConstraintStr());
}

ExprResult ER = CheckPlaceholderExpr(Exprs[i]);
Expand Down Expand Up @@ -378,9 +377,9 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
FeatureMap,
GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(Constraint),
Size)) {
targetDiag(OutputExpr->getBeginLoc(), diag::err_asm_invalid_output_size)
<< Info.getConstraintStr();
return CreateGCCAsmStmt();
return StmtError(targetDiag(OutputExpr->getBeginLoc(),
diag::err_asm_invalid_output_size)
<< Info.getConstraintStr());
}
}

Expand All @@ -399,10 +398,9 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
TargetInfo::ConstraintInfo Info(ConstraintStr, InputName);
if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos,
Info)) {
targetDiag(Constraint->getBeginLoc(),
diag::err_asm_invalid_input_constraint)
<< Info.getConstraintStr();
return CreateGCCAsmStmt();
return StmtError(targetDiag(Constraint->getBeginLoc(),
diag::err_asm_invalid_input_constraint)
<< Info.getConstraintStr());
}

ExprResult ER = CheckPlaceholderExpr(Exprs[i]);
Expand Down Expand Up @@ -504,13 +502,9 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(ClobberExpr);

if (!Context.getTargetInfo().isValidClobber(Clobber)) {
targetDiag(ClobberExpr->getBeginLoc(),
diag::err_asm_unknown_register_name)
<< Clobber;
return new (Context) GCCAsmStmt(
Context, AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs, Names,
constraints.data(), Exprs.data(), asmString, NumClobbers,
clobbers.data(), NumLabels, RParenLoc);
return StmtError(targetDiag(ClobberExpr->getBeginLoc(),
diag::err_asm_unknown_register_name)
<< Clobber);
}

if (Clobber == "unwind") {
Expand All @@ -520,8 +514,8 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,

// Using unwind clobber and asm-goto together is not supported right now.
if (UnwindClobberLoc && NumLabels > 0) {
targetDiag(*UnwindClobberLoc, diag::err_asm_unwind_and_goto);
return CreateGCCAsmStmt();
return StmtError(
targetDiag(*UnwindClobberLoc, diag::err_asm_unwind_and_goto));
}

GCCAsmStmt *NS = CreateGCCAsmStmt();
Expand Down
28 changes: 28 additions & 0 deletions clang/test/OpenMP/openmp_asm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify=fopenmp -emit-llvm -o - %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -verify -emit-llvm -o - %s

// RUN: %clang_cc1 -triple x86_64-unknown-unknown -x c++ -fopenmp -verify=fopenmp -emit-llvm -o - %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -x c++ -verify -emit-llvm -o - %s

// fopenmp-no-diagnostics

void t1(int *a, int *b) {
asm volatile("" : "+&r"(a) : ""(b)); // expected-error {{invalid input constraint '' in asm}}
}

void t2() {
asm ("nop" : : : "foo"); // expected-error {{unknown register name 'foo' in asm}}
}

void t3() {
asm goto ("" ::: "unwind" : label); // expected-error {{unwind clobber cannot be used with asm goto}}
label:
;
}

typedef int vec256 __attribute__((ext_vector_type(8)));
vec256 t4() {
vec256 out;
asm("something %0" : "=y"(out)); // expected-error {{invalid output size for constraint '=y'}}
return out;
}
Loading